WrappedSemaphore.cpp 584 B

12345678910111213141516171819202122232425
  1. #include "WrappedSemaphore.h"
  2. using namespace bell;
  3. WrappedSemaphore::WrappedSemaphore(int count) {
  4. this->semaphoreHandle = CreateSemaphore(NULL, 0, count, NULL);
  5. }
  6. WrappedSemaphore::~WrappedSemaphore() {
  7. CloseHandle(this->semaphoreHandle);
  8. }
  9. int WrappedSemaphore::wait() {
  10. WaitForSingleObject(this->semaphoreHandle, INFINITE);
  11. return 0;
  12. }
  13. int WrappedSemaphore::twait(long milliseconds) {
  14. return WaitForSingleObject(this->semaphoreHandle, milliseconds) !=
  15. WAIT_OBJECT_0;
  16. }
  17. void WrappedSemaphore::give() {
  18. ReleaseSemaphore(this->semaphoreHandle, 1, NULL);
  19. }