#ifndef SEMAPHORE_H_ #define SEMAPHORE_H_ #include // has sem_ routines // ---- Class for semaphore ------------------------------------------ // By defining a class for semaphores, we ensure that sem_init // and sem_destroy are called automagically (respectively, // when a semaphoreObj is declared and goes out of scope). class semaphoreObj { public: // Constructor and destructor. semaphoreObj(const unsigned int initVal) { sem_init(&theSemaphore, 0, initVal); } ~semaphoreObj(void) { sem_destroy(&theSemaphore); } // Functions to "wait" and "signal". void wait(void) { sem_wait(&theSemaphore); } void signal(void) { sem_post(&theSemaphore); } private: // Make copy constructor and assignment operator private // so they can't be used (since it's not clear this would // make sense). semaphoreObj(const semaphoreObj & d); semaphoreObj & operator= (const semaphoreObj & d); // Member variables. sem_t theSemaphore; }; #endif // SEMAPHORE_H_