// EPOS Semaphore Implementation // // Author: alexandre // Documentation: $EPOS/doc/synchronizer Date: 19 May 2004 #include #include //#include __BEGIN_SYS __BEGIN_IMP Semaphore::Semaphore(int value) { db(TRC) << "Semaphore(value= " << value << ")\n"; Semaphore::counter = value; } Semaphore::~Semaphore() { db(TRC) << "~Semaphore()\n"; } void Semaphore::p() { db(TRC) << "Semaphore::p()\n"; Semaphore::self = Concurrent_Thread::running(); while (Semaphore::counter == 0) Semaphore::self->suspend(); Semaphore::counter--; } void Semaphore::v() { db(TRC) << "Semaphore::v()\n"; Semaphore::counter++; Semaphore::self = Concurrent_Thread::running(); Semaphore::self->resume(); } __END_IMP __END_SYS