#include "commons/commons_sync.h" #include "commons/commons_fmt.h" #include "commons/commons_region_alloc.h" #include struct _mutex { pthread_mutex_t handle; }; auto API Mutex_Create(region_alloc& alloc) -> mutex { _mutex& self = RegionAlloc_Alloc<_mutex>(alloc); int res = pthread_mutex_init(&self.handle, nullptr); ASSERT(res == 0); return &self; } void API Mutex_Destroy(mutex self) { pthread_mutex_destroy(&self->handle); } void API Mutex_Lock(mutex self) { pthread_mutex_lock(&self->handle); } void API Mutex_Unlock(mutex self) { pthread_mutex_unlock(&self->handle); } // struct _condvar { pthread_cond_t handle; }; auto API CondVar_Create(region_alloc& alloc) -> condvar { _condvar& self = RegionAlloc_Alloc<_condvar>(alloc); int res = pthread_cond_init(&self.handle, nullptr); ASSERT(res == 0); return &self; } void API CondVar_Destroy(condvar self) { pthread_cond_destroy(&self->handle); } void API CondVar_Wait(condvar self, mutex mutex) { pthread_cond_wait(&self->handle, &mutex->handle); } void API CondVar_Signal(condvar self) { pthread_cond_signal(&self->handle); }