posix_mutex.cpp 680 B

12345678910111213141516171819202122232425262728
  1. //
  2. // $Id$
  3. //
  4. #include<__vic/posix/mutex.h>
  5. #include<__vic/throw_errno.h>
  6. #include<cerrno>
  7. namespace __vic { namespace posix {
  8. //----------------------------------------------------------------------------
  9. void mutex::lock()
  10. {
  11. int res = ::pthread_mutex_lock(&mtx);
  12. if(res) throw_errno("pthread_mutex_lock", res);
  13. }
  14. //----------------------------------------------------------------------------
  15. bool mutex::try_lock()
  16. {
  17. int res = ::pthread_mutex_trylock(&mtx);
  18. if(res == EBUSY) return false;
  19. if(res) throw_errno("pthread_mutex_trylock", res);
  20. return true;
  21. }
  22. //----------------------------------------------------------------------------
  23. }} // namespace