Skip to content

Instantly share code, notes, and snippets.

Created August 29, 2014 23:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/5f97d8db71776b188820 to your computer and use it in GitHub Desktop.
Save anonymous/5f97d8db71776b188820 to your computer and use it in GitHub Desktop.
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;
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment