1 #include <SemaphoreSyncObject.h> 2 #include <cppunit/Exception.h> 3 4 _EXPORT SemaphoreSyncObject()5SemaphoreSyncObject::SemaphoreSyncObject() 6 : fSemId(create_sem(1, "CppUnitSync")) 7 { 8 if (fSemId < B_OK) 9 throw CppUnit::Exception("SemaphoreSyncObject::SemaphoreSyncObject() -- Error creating semaphore"); 10 } 11 12 _EXPORT ~SemaphoreSyncObject()13SemaphoreSyncObject::~SemaphoreSyncObject() { 14 delete_sem(fSemId); 15 } 16 17 _EXPORT 18 void lock()19SemaphoreSyncObject::lock() { 20 if (acquire_sem(fSemId) < B_OK) 21 throw CppUnit::Exception("SemaphoreSyncObject::lock() -- Error acquiring semaphore"); 22 } 23 24 _EXPORT 25 void unlock()26SemaphoreSyncObject::unlock() { 27 if (release_sem(fSemId) < B_OK) 28 throw CppUnit::Exception("SemaphoreSyncObject::unlock() -- Error releasing semaphore"); 29 } 30