8 pthread_mutex_t* lock = naAlloc(sizeof(pthread_mutex_t));
9 pthread_mutex_init(lock, 0);
13 void naLock(void* lock)
15 pthread_mutex_lock((pthread_mutex_t*)lock);
18 void naUnlock(void* lock)
20 pthread_mutex_unlock((pthread_mutex_t*)lock);
31 struct naSem* sem = naAlloc(sizeof(struct naSem));
32 pthread_mutex_init(&sem->lock , 0);
33 pthread_cond_init(&sem->cvar, 0);
38 void naSemDown(void* sh)
40 struct naSem* sem = (struct naSem*)sh;
41 pthread_mutex_lock(&sem->lock);
42 while(sem->count <= 0)
43 pthread_cond_wait(&sem->cvar, &sem->lock);
45 pthread_mutex_unlock(&sem->lock);
48 void naSemUpAll(void* sh, int count)
50 struct naSem* sem = (struct naSem*)sh;
51 pthread_mutex_lock(&sem->lock);
53 pthread_cond_broadcast(&sem->cvar);
54 pthread_mutex_unlock(&sem->lock);