posix_mutex_lock.cpp 688 B

123456789101112131415161718192021222324252627
  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 && !std::uncaught_exception())
  19. throw_errno("pthread_mutex_unlock", res);
  20. }
  21. //----------------------------------------------------------------------------
  22. }} // namespace