Solaris 2.x Semaphore Class

The following is the implementation of the Semaphore class on Solaris 2.x.

class Semaphore { private: sema_t semaphore; public: Semaphore(void) { sema_init(&semaphore, 0, USYNC_PROCESS, (void*)0); } Semaphore(int available) { sema_init(&semaphore, available, USYNC_PROCESS, (void*)0); } ~Semaphore(void) { sema_destroy(&semaphore); } void Post(void) { sema_post(&semaphore); } void Post(int how_many) { while (how_many-- > 0) sema_post(&semaphore); } void Wait(void) { sema_wait(&semaphore); } };