ref: df0d3a415216340a44953c6ed936bc2a4d7a1175
dir: /plan9/semaphore.h/
#ifndef __semaphore_h__ #define __semaphore_h__ typedef struct sem_t sem_t; struct sem_t { Channel *c; }; static int sem_post(sem_t *s) { void *p; if(s == nil || s->c == nil) return -1; nbrecv(s->c, &p); return 0; } static int sem_wait(sem_t *s) { void *p; if(s == nil || s->c == nil) return -1; sendp(s->c, nil); return 0; } static int sem_init(sem_t *s, int pshared, unsigned int value) { s->c = chancreate(sizeof(void*), value); return 0; } static int sem_destroy(sem_t *s) { chanclose(s->c); return 0; } #endif