posix_cond_variable.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // $Id$
  3. //
  4. #include<__vic/posix/cond_variable.h>
  5. #include<__vic/throw_errno.h>
  6. #include<cerrno>
  7. namespace __vic { namespace posix {
  8. //----------------------------------------------------------------------------
  9. void cond_variable::wait(::pthread_mutex_t &m)
  10. {
  11. int err = ::pthread_cond_wait(&cond, &m);
  12. if(err) throw_errno("pthread_cond_wait", err);
  13. }
  14. //----------------------------------------------------------------------------
  15. bool cond_variable::wait_until(::pthread_mutex_t &m, const ::timespec &abstime)
  16. {
  17. int err = ::pthread_cond_timedwait(&cond, &m, &abstime);
  18. switch(err)
  19. {
  20. case 0:
  21. return true;
  22. case ETIMEDOUT:
  23. return false;
  24. default:
  25. throw_errno("pthread_cond_timedwait", err);
  26. }
  27. }
  28. //----------------------------------------------------------------------------
  29. void cond_variable::signal()
  30. {
  31. int err = ::pthread_cond_signal(&cond);
  32. if(err) throw_errno("pthread_cond_signal", err);
  33. }
  34. //----------------------------------------------------------------------------
  35. void cond_variable::broadcast()
  36. {
  37. int err = ::pthread_cond_broadcast(&cond);
  38. if(err) throw_errno("pthread_cond_broadcast", err);
  39. }
  40. //----------------------------------------------------------------------------
  41. }} // namespace