WrappedSemaphore.cpp 575 B

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