poly_shared_lockable_adapter.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. //[poly_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. //[poly_upgrade_lockable_adapter
  49. template <typename Mutex, typename Base=poly_shared_lockable>
  50. class poly_upgrade_lockable_adapter: public poly_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. bool try_unlock_shared_and_lock_for(chrono::nanoseconds const & rel_time)
  91. {
  92. return this->mtx().try_unlock_shared_and_lock_for(rel_time);
  93. }
  94. void unlock_and_lock_shared()
  95. {
  96. this->mtx().unlock_and_lock_shared();
  97. }
  98. bool try_unlock_shared_and_lock_upgrade()
  99. {
  100. return this->mtx().try_unlock_shared_and_lock_upgrade();
  101. }
  102. bool try_unlock_shared_and_lock_upgrade_until(chrono::system_clock::time_point const & abs_time)
  103. {
  104. return this->mtx().try_unlock_shared_and_lock_upgrade_until(abs_time);
  105. }
  106. bool try_unlock_shared_and_lock_upgrade_until(chrono::steady_clock::time_point const & abs_time)
  107. {
  108. return this->mtx().try_unlock_shared_and_lock_upgrade_until(abs_time);
  109. }
  110. bool try_unlock_shared_and_lock_upgrade_for(chrono::nanoseconds const & rel_time)
  111. {
  112. return this->mtx().try_unlock_shared_and_lock_upgrade_for(rel_time);
  113. }
  114. void unlock_and_lock_upgrade()
  115. {
  116. this->mtx().unlock_and_lock_upgrade();
  117. }
  118. void unlock_upgrade_and_lock()
  119. {
  120. this->mtx().unlock_upgrade_and_lock();
  121. }
  122. bool try_unlock_upgrade_and_lock()
  123. {
  124. return this->mtx().try_unlock_upgrade_and_lock();
  125. }
  126. bool try_unlock_upgrade_and_lock_until(chrono::system_clock::time_point const & abs_time)
  127. {
  128. return this->mtx().try_unlock_upgrade_and_lock_until(abs_time);
  129. }
  130. bool try_unlock_upgrade_and_lock_until(chrono::steady_clock::time_point const & abs_time)
  131. {
  132. return this->mtx().try_unlock_upgrade_and_lock_until(abs_time);
  133. }
  134. bool try_unlock_upgrade_and_lock_for(chrono::nanoseconds const & rel_time)
  135. {
  136. return this->mtx().try_unlock_upgrade_and_lock_for(rel_time);
  137. }
  138. void unlock_upgrade_and_lock_shared()
  139. {
  140. this->mtx().unlock_upgrade_and_lock_shared();
  141. }
  142. };
  143. //]
  144. }
  145. #endif