diff --git a/threading.h b/threading.h index f951b93..89ffd56 100644 --- a/threading.h +++ b/threading.h @@ -36,6 +36,41 @@ typedef pthread_cond_t tgvoip_lock_t; #define wait_lock(lock, mutex) pthread_cond_wait(&lock, &mutex) #define notify_lock(lock) pthread_cond_broadcast(&lock) +#ifdef __APPLE__ +#include +namespace tgvoip{ +class Semaphore{ +public: + Semaphore(unsigned int maxCount, unsigned int initValue){ + sem = dispatch_semaphore_create(initValue); + } + + ~Semaphore(){ + } + + void Acquire(){ + dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); + } + + void Release(){ + dispatch_semaphore_signal(sem); + } + + void Acquire(int count){ + for(int i=0;i