shithub: libvpx

ref: 3ccbd4803bcc75be860dd67bb3a56b114251433b
dir: libvpx/plan9/semaphore.h

View raw version
#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