std_lock.hpp 913 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // std_lock.cpp
  3. // threadpp
  4. //
  5. // Created by Melo Yao on 1/15/15.
  6. // Copyright (c) 2015 Melo Yao. All rights reserved.
  7. //
  8. #ifndef __threadpp__std_lock__hpp__
  9. #define __threadpp__std_lock__hpp__
  10. #include "../threadpp_assert.h"
  11. namespace threadpp{
  12. inline std_lock::std_lock():_mutex(),_cond()
  13. {
  14. }
  15. inline std_lock::~std_lock()
  16. {
  17. }
  18. inline void std_lock::lock()
  19. {
  20. _mutex.lock();
  21. }
  22. inline void std_lock::unlock()
  23. {
  24. _mutex.unlock();
  25. }
  26. inline void std_lock::wait()
  27. {
  28. _cond.wait(_mutex);
  29. }
  30. inline void std_lock::wait(unsigned long millisecs)
  31. {
  32. _cond.wait_for(_mutex, std::chrono::milliseconds(millisecs));
  33. }
  34. inline void std_lock::notify()
  35. {
  36. _cond.notify_one();
  37. }
  38. inline void std_lock::notify_all()
  39. {
  40. _cond.notify_all();
  41. }
  42. }
  43. #endif