Implement WinNT condition variables, add semaphors
This commit is contained in:
@@ -87,6 +87,42 @@ int bh_mutex_unlock(bh_mutex_t *mutex)
|
||||
return pthread_mutex_unlock(&mutex->handle);
|
||||
}
|
||||
|
||||
int bh_semaphore_init(bh_semaphore_t *semaphore, int count)
|
||||
{
|
||||
return sem_init(&semaphore->handle, 0, count);
|
||||
}
|
||||
|
||||
void bh_semaphore_destroy(bh_semaphore_t *semaphore)
|
||||
{
|
||||
sem_destroy(&semaphore->handle);
|
||||
}
|
||||
|
||||
int bh_semaphore_post(bh_semaphore_t *semaphore)
|
||||
{
|
||||
return sem_post(&semaphore->handle);
|
||||
}
|
||||
|
||||
int bh_semaphore_wait(bh_semaphore_t *semaphore)
|
||||
{
|
||||
return sem_wait(&semaphore->handle);
|
||||
}
|
||||
|
||||
int bh_semaphore_wait_for(bh_semaphore_t *semaphore,
|
||||
unsigned long timeout)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
||||
ts.tv_sec = timeout / 1000;
|
||||
ts.tv_nsec = (timeout - ts.tv_sec * 1000) * 1000000;
|
||||
|
||||
return sem_timedwait(&semaphore->handle, &ts);
|
||||
}
|
||||
|
||||
int bh_semaphore_try_wait(bh_semaphore_t *semaphore)
|
||||
{
|
||||
return sem_trywait(&semaphore->handle);
|
||||
}
|
||||
|
||||
int bh_cond_init(bh_cond_t *cond)
|
||||
{
|
||||
return pthread_cond_init(&cond->handle, NULL);
|
||||
|
||||
Reference in New Issue
Block a user