locks.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2012-2012. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_INTERPROCESS_DETAIL_LOCKS_HPP
  11. #define BOOST_INTERPROCESS_DETAIL_LOCKS_HPP
  12. #include <boost/interprocess/detail/config_begin.hpp>
  13. #include <boost/interprocess/detail/workaround.hpp>
  14. namespace boost {
  15. namespace interprocess {
  16. namespace ipcdetail {
  17. template<class Lock>
  18. class internal_mutex_lock
  19. {
  20. typedef void (internal_mutex_lock::*unspecified_bool_type)();
  21. public:
  22. typedef typename Lock::mutex_type::internal_mutex_type mutex_type;
  23. internal_mutex_lock(Lock &l)
  24. : l_(l)
  25. {}
  26. mutex_type* mutex() const
  27. { return l_ ? &l_.mutex()->internal_mutex() : 0; }
  28. void lock() { l_.lock(); }
  29. void unlock() { l_.unlock(); }
  30. operator unspecified_bool_type() const
  31. { return l_ ? &internal_mutex_lock::lock : 0; }
  32. private:
  33. Lock &l_;
  34. };
  35. template <class Lock>
  36. class lock_inverter
  37. {
  38. Lock &l_;
  39. public:
  40. lock_inverter(Lock &l)
  41. : l_(l)
  42. {}
  43. void lock() { l_.unlock(); }
  44. void unlock() { l_.lock(); }
  45. };
  46. } //namespace ipcdetail
  47. } //namespace interprocess
  48. } //namespace boost
  49. #include <boost/interprocess/detail/config_end.hpp>
  50. #endif //BOOST_INTERPROCESS_DETAIL_LOCKS_HPP