/Src/Dependencies/Boost/boost/thread/pthread/pthread_mutex_scoped_lock.hpp

http://hadesmem.googlecode.com/ · C++ Header · 64 lines · 50 code · 9 blank · 5 comment · 1 complexity · 31957fabbb46f253bdada1b97dca1a21 MD5 · raw file

  1. #ifndef BOOST_PTHREAD_MUTEX_SCOPED_LOCK_HPP
  2. #define BOOST_PTHREAD_MUTEX_SCOPED_LOCK_HPP
  3. // (C) Copyright 2007-8 Anthony Williams
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #include <pthread.h>
  9. #include <boost/assert.hpp>
  10. #include <boost/config/abi_prefix.hpp>
  11. namespace boost
  12. {
  13. namespace pthread
  14. {
  15. class pthread_mutex_scoped_lock
  16. {
  17. pthread_mutex_t* m;
  18. bool locked;
  19. public:
  20. explicit pthread_mutex_scoped_lock(pthread_mutex_t* m_):
  21. m(m_),locked(true)
  22. {
  23. BOOST_VERIFY(!pthread_mutex_lock(m));
  24. }
  25. void unlock()
  26. {
  27. BOOST_VERIFY(!pthread_mutex_unlock(m));
  28. locked=false;
  29. }
  30. ~pthread_mutex_scoped_lock()
  31. {
  32. if(locked)
  33. {
  34. unlock();
  35. }
  36. }
  37. };
  38. class pthread_mutex_scoped_unlock
  39. {
  40. pthread_mutex_t* m;
  41. public:
  42. explicit pthread_mutex_scoped_unlock(pthread_mutex_t* m_):
  43. m(m_)
  44. {
  45. BOOST_VERIFY(!pthread_mutex_unlock(m));
  46. }
  47. ~pthread_mutex_scoped_unlock()
  48. {
  49. BOOST_VERIFY(!pthread_mutex_lock(m));
  50. }
  51. };
  52. }
  53. }
  54. #include <boost/config/abi_suffix.hpp>
  55. #endif