Created
February 7, 2011 08:21
-
-
Save grk/814136 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __semaphore_t_h__ | |
#define __semaphore_t_h__ | |
#ifdef __APPLE__ | |
#include <mach/mach_init.h> | |
#include <mach/task.h> | |
#include <mach/semaphore.h> | |
class semaph_t | |
{ | |
public: | |
semaph_t(int initial = 0) | |
{ | |
semaphore_create(mach_task_self(), &_sem, SYNC_POLICY_FIFO, initial); | |
} | |
~semaph_t() | |
{ | |
semaphore_destroy(mach_task_self(), _sem); | |
} | |
void post() | |
{ | |
semaphore_signal(_sem); | |
} | |
void wait() | |
{ | |
semaphore_wait(_sem); | |
} | |
private: | |
semaphore_t _sem; | |
}; | |
#else /* __APPLE__ */ | |
#include <semaphore.h> | |
class semaph_t | |
{ | |
public: | |
semaph_t(int initial = 0) | |
{ | |
sem_init(&_sem, 0, initial); | |
} | |
~semaph_t() | |
{ | |
sem_destroy(&_sem); | |
} | |
void post() | |
{ | |
sem_post(&_sem); | |
} | |
void wait() | |
{ | |
sem_wait(&_sem); | |
} | |
private: | |
sem_t _sem; | |
}; | |
#endif /* __APPLE__ */ | |
#endif /* __semaphore_t_h__ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment