Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include "semaphore.h"
  2.  
  3. Semaphore::Semaphore(uint32_t count) {
  4.     count = count;
  5. }
  6.  
  7. Semaphore::~Semaphore() {
  8. }
  9.  
  10. void Semaphore::wait() {
  11.     std::unique_lock<std::mutex> lock(mtx);
  12.  
  13.     while (!count)
  14.         cv.wait(lock);
  15.  
  16.     count--;
  17. }
  18.  
  19. void Semaphore::notify() {
  20.     std::unique_lock<std::mutex> lock(mtx);
  21.     count++;
  22.     cv.notify_one();
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement