diff options
| author | David Jeannot <djeannot24@gmail.com> | 2011-09-06 10:10:43 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@swtch.com> | 2011-09-06 10:10:43 -0400 |
| commit | a287dbab235c9041a32300a9e0bb60ef41864963 (patch) | |
| tree | 0049709f4a223e0de5fde987ea0d170fcb543b1d /src/cmd/devdraw/cocoa-thread.c | |
| parent | f0a4e8bd6cfb318e374e57f34b5676c6890fb1a2 (diff) | |
| download | plan9port-a287dbab235c9041a32300a9e0bb60ef41864963.tar.gz plan9port-a287dbab235c9041a32300a9e0bb60ef41864963.zip | |
devdraw: draft cocoa support
R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/4974060
Diffstat (limited to 'src/cmd/devdraw/cocoa-thread.c')
| -rw-r--r-- | src/cmd/devdraw/cocoa-thread.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/cmd/devdraw/cocoa-thread.c b/src/cmd/devdraw/cocoa-thread.c new file mode 100644 index 00000000..4b2443ce --- /dev/null +++ b/src/cmd/devdraw/cocoa-thread.c @@ -0,0 +1,54 @@ +#include <u.h> +#include <libc.h> +#include "cocoa-thread.h" + +static pthread_mutex_t initlock = PTHREAD_MUTEX_INITIALIZER; + +void +qlock(QLock *q) +{ + if(q->init == 0){ + pthread_mutex_lock(&initlock); + if(q->init == 0){ + pthread_mutex_init(&q->m, nil); + q->init = 1; + } + pthread_mutex_unlock(&initlock); + } + pthread_mutex_lock(&q->m); +} + +void +qunlock(QLock *q) +{ + pthread_mutex_unlock(&q->m); +} + +static void +rinit(Rendez *r) +{ + pthread_mutex_lock(&initlock); + if(r->init == 0){ + pthread_cond_init(&r->c, nil); + r->init = 1; + } + pthread_mutex_unlock(&initlock); +} + +void +rsleep(Rendez *r) +{ + if(r->init == 0) + rinit(r); + pthread_cond_wait(&r->c, &r->l->m); +} + +int +rwakeup(Rendez *r) +{ + if(r->init == 0) + rinit(r); + pthread_cond_signal(&r->c); + + return 0; +} |
