posix_mutex_lock.cpp 788 B

123456789101112131415161718192021222324252627282930313233
  1. //
  2. // $Id$
  3. //
  4. #include<__vic/posix/mutex.h>
  5. #include<__vic/throw_errno.h>
  6. #include<exception>
  7. namespace __vic { namespace posix {
  8. //----------------------------------------------------------------------------
  9. void mutex_lock::lock()
  10. {
  11. int res = ::pthread_mutex_lock(&mtx);
  12. if(res) throw_errno("pthread_mutex_lock", res);
  13. }
  14. //----------------------------------------------------------------------------
  15. mutex_lock::~mutex_lock() __VIC_THROWS
  16. {
  17. int res = ::pthread_mutex_unlock(&mtx);
  18. if(res &&
  19. #if __cpp_lib_uncaught_exceptions
  20. std::uncaught_exceptions() == 0
  21. #else
  22. !std::uncaught_exception()
  23. #endif
  24. )
  25. throw_errno("pthread_mutex_unlock", res);
  26. }
  27. //----------------------------------------------------------------------------
  28. }} // namespace