shared_lock_guard.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Distributed under the Boost Software License, Version 1.0. (See
  2. // accompanying file LICENSE_1_0.txt or copy at
  3. // http://www.boost.org/LICENSE_1_0.txt)
  4. // (C) Copyright 2012 Vicente J. Botet Escriba
  5. #ifndef BOOST_THREAD_SHARED_LOCK_GUARD_HPP
  6. #define BOOST_THREAD_SHARED_LOCK_GUARD_HPP
  7. #include <boost/thread/detail/config.hpp>
  8. //#include <boost/thread/locks.hpp>
  9. #include <boost/thread/lock_options.hpp>
  10. #include <boost/thread/detail/delete.hpp>
  11. namespace boost
  12. {
  13. template<typename SharedMutex>
  14. class shared_lock_guard
  15. {
  16. private:
  17. SharedMutex& m;
  18. public:
  19. typedef SharedMutex mutex_type;
  20. BOOST_THREAD_NO_COPYABLE(shared_lock_guard)
  21. explicit shared_lock_guard(SharedMutex& m_):
  22. m(m_)
  23. {
  24. m.lock_shared();
  25. }
  26. shared_lock_guard(SharedMutex& m_,adopt_lock_t):
  27. m(m_)
  28. {}
  29. ~shared_lock_guard()
  30. {
  31. m.unlock_shared();
  32. }
  33. };
  34. #ifdef BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES
  35. template<typename T>
  36. struct is_mutex_type<shared_lock_guard<T> >
  37. {
  38. BOOST_STATIC_CONSTANT(bool, value = true);
  39. };
  40. #endif
  41. }
  42. #endif // header