Created
August 29, 2014 23:23
-
-
Save anonymous/5f97d8db71776b188820 to your computer and use it in GitHub Desktop.
Revisions
-
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ typedef struct chan_t { pthread_mutex_t m_mu; pthread_cond_t m_cond; int closed; void (* dispose)(struct chan_t * self); ... } chan_t; typedef struct unbuffered_t { chan_t base; ... } unbuffered_t; typedef struct buffered_t { chan_t base; ... } buffered_t; chan_t* chan_init(int capacity) { if (capacity) { buffered_t * ch = malloc(sizeof *ch); ch->dispose = dispose_buffered; ... return &ch->base; } else { Unbuffered_t * ch = malloc(sizeof *ch); ch->dispose = dispose_unbuffered; ... return &ch->base; } } void dispose_unbuffered(chan_t * self) { unbuffered_t * ch = (chan_t*)self; ... } void dispose_buffered(chan_t * self) { buffered_t * ch = (chan_t*)self; ... }