Created
August 29, 2014 23:23
-
-
Save anonymous/5f97d8db71776b188820 to your computer and use it in GitHub Desktop.
This file contains 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 characters
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