Solaris 2.x Gate Class

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

class Gate { private: mutex_t structure_lock; cond_t wakeup; int closed; public: Gate(void) { mutex_init(&structure_lock, USYNC_PROCESS, (void*)0); cond_init(&wakeup, USYNC_PROCESS, (void*)0); closed = 1; } ~Gate(void) { mutex_destroy(&structure_lock); cond_destroy(&wakeup); } void Open(void) { mutex_lock(&structure_lock); closed = 0; cond_broadcast(&wakeup); mutex_unlock(&structure_lock); } void Close(void) { mutex_lock(&structure_lock); closed = 1; mutex_unlock(&structure_lock); } // temporarily open the gate, allowing any waiting threads to // proceed void Release(void) { cond_broadcast(&wakeup); } void Wait(void) { mutex_lock(&structure_lock); if (closed) cond_wait(&wakeup, &structure_lock); mutex_unlock(&structure_lock); } };