poly_shared_lockable_adapter.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Vicente J. Botet Escriba 2008-2009,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/thread for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_THREAD_POLY_SHARED_LOCKABLE_ADAPTER_HPP
  11. #define BOOST_THREAD_POLY_SHARED_LOCKABLE_ADAPTER_HPP
  12. #include <boost/thread/poly_lockable_adapter.hpp>
  13. #include <boost/thread/poly_shared_lockable.hpp>
  14. namespace boost
  15. {
  16. //[shared_lockable_adapter
  17. template <typename Mutex, typename Base=poly_shared_lockable>
  18. class poly_shared_lockable_adapter: public poly_timed_lockable_adapter<Mutex, Base>
  19. {
  20. public:
  21. typedef Mutex mutex_type;
  22. void lock_shared()
  23. {
  24. this->mtx().lock_shared();
  25. }
  26. bool try_lock_shared()
  27. {
  28. return this->mtx().try_lock_shared();
  29. }
  30. void unlock_shared()
  31. {
  32. this->mtx().unlock_shared();
  33. }
  34. bool try_lock_shared_until(chrono::system_clock::time_point const & abs_time)
  35. {
  36. return this->mtx().try_lock_shared_until(abs_time);
  37. }
  38. bool try_lock_shared_until(chrono::steady_clock::time_point const & abs_time)
  39. {
  40. return this->mtx().try_lock_shared_until(abs_time);
  41. }
  42. bool try_lock_shared_for(chrono::nanoseconds const & rel_time)
  43. {
  44. return this->mtx().try_lock_shared_for(rel_time);
  45. }
  46. };
  47. //]
  48. //[upgrade_lockable_adapter
  49. template <typename Mutex, typename Base=poly_shared_lockable>
  50. class upgrade_lockable_adapter: public shared_lockable_adapter<Mutex, Base>
  51. {
  52. public:
  53. typedef Mutex mutex_type;
  54. void lock_upgrade()
  55. {
  56. this->mtx().lock_upgrade();
  57. }
  58. bool try_lock_upgrade()
  59. {
  60. return this->mtx().try_lock_upgrade();
  61. }
  62. void unlock_upgrade()
  63. {
  64. this->mtx().unlock_upgrade();
  65. }
  66. bool try_lock_upgrade_until(chrono::system_clock::time_point const & abs_time)
  67. {
  68. return this->mtx().try_lock_upgrade_until(abs_time);
  69. }
  70. bool try_lock_upgrade_until(chrono::steady_clock::time_point const & abs_time)
  71. {
  72. return this->mtx().try_lock_upgrade_until(abs_time);
  73. }
  74. bool try_lock_upgrade_for(chrono::nanoseconds const & rel_time)
  75. {
  76. return this->mtx().try_lock_upgrade_for(rel_time);
  77. }
  78. bool try_unlock_shared_and_lock()
  79. {
  80. return this->mtx().try_unlock_shared_and_lock();
  81. }
  82. bool try_unlock_shared_and_lock_until(chrono::system_clock::time_point const & abs_time)
  83. {
  84. return this->mtx().try_unlock_shared_and_lock_until(abs_time);
  85. }
  86. bool try_unlock_shared_and_lock_until(chrono::steady_clock::time_point const & abs_time)
  87. {
  88. return this->mtx().try_unlock_shared_and_lock_until(abs_time);
  89. }
  90. template <typename Rep, typename Period>
  91. bool try_unlock_shared_and_lock_for(chrono::nanoseconds const & rel_time)
  92. {
  93. return this->mtx().try_unlock_shared_and_lock_for(rel_time);
  94. }
  95. void unlock_and_lock_shared()
  96. {
  97. this->mtx().unlock_and_lock_shared();
  98. }
  99. bool try_unlock_shared_and_lock_upgrade()
  100. {
  101. return this->mtx().try_unlock_shared_and_lock_upgrade();
  102. }
  103. bool try_unlock_shared_and_lock_upgrade_until(chrono::system_clock::time_point const & abs_time)
  104. {
  105. return this->mtx().try_unlock_shared_and_lock_upgrade_until(abs_time);
  106. }
  107. bool try_unlock_shared_and_lock_upgrade_until(chrono::steady_clock::time_point const & abs_time)
  108. {
  109. return this->mtx().try_unlock_shared_and_lock_upgrade_until(abs_time);
  110. }
  111. bool try_unlock_shared_and_lock_upgrade_for(chrono::nanoseconds const & rel_time)
  112. {
  113. return this->mtx().try_unlock_shared_and_lock_upgrade_for(rel_time);
  114. }
  115. void unlock_and_lock_upgrade()
  116. {
  117. this->mtx().unlock_and_lock_upgrade();
  118. }
  119. void unlock_upgrade_and_lock()
  120. {
  121. this->mtx().unlock_upgrade_and_lock();
  122. }
  123. bool try_unlock_upgrade_and_lock()
  124. {
  125. return this->mtx().try_unlock_upgrade_and_lock();
  126. }
  127. bool try_unlock_upgrade_and_lock_until(chrono::system_clock::time_point const & abs_time)
  128. {
  129. return this->mtx().try_unlock_upgrade_and_lock_until(abs_time);
  130. }
  131. bool try_unlock_upgrade_and_lock_until(chrono::steady_clock::time_point const & abs_time)
  132. {
  133. return this->mtx().try_unlock_upgrade_and_lock_until(abs_time);
  134. }
  135. bool try_unlock_upgrade_and_lock_for(chrono::nanoseconds const & rel_time)
  136. {
  137. return this->mtx().try_unlock_upgrade_and_lock_for(rel_time);
  138. }
  139. void unlock_upgrade_and_lock_shared()
  140. {
  141. this->mtx().unlock_upgrade_and_lock_shared();
  142. }
  143. };
  144. //]
  145. }
  146. #endif