null_mutex.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-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_NULL_MUTEX_HPP
  11. #define BOOST_INTERPROCESS_NULL_MUTEX_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #
  16. #if defined(BOOST_HAS_PRAGMA_ONCE)
  17. # pragma once
  18. #endif
  19. #include <boost/interprocess/detail/config_begin.hpp>
  20. #include <boost/interprocess/detail/workaround.hpp>
  21. //!\file
  22. //!Describes null_mutex classes
  23. namespace boost {
  24. namespace interprocess {
  25. //!Implements a mutex that simulates a mutex without doing any operation and
  26. //!simulates a successful operation.
  27. class null_mutex
  28. {
  29. #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  30. null_mutex(const null_mutex&);
  31. null_mutex &operator= (const null_mutex&);
  32. #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
  33. public:
  34. //!Constructor.
  35. //!Empty.
  36. null_mutex() BOOST_NOEXCEPT {}
  37. //!Destructor.
  38. //!Empty.
  39. ~null_mutex(){}
  40. //!Simulates a mutex lock() operation. Empty function.
  41. void lock(){}
  42. //!Simulates a mutex try_lock() operation.
  43. //!Equivalent to "return true;"
  44. bool try_lock()
  45. { return true; }
  46. //!Simulates a mutex timed_lock() operation.
  47. //!Equivalent to "return true;"
  48. template<class TimePoint>
  49. bool timed_lock(const TimePoint &)
  50. { return true; }
  51. //!Same as `timed_lock`, but this function is modeled after the
  52. //!standard library interface.
  53. template<class TimePoint>
  54. bool try_lock_until(const TimePoint &)
  55. { return true; }
  56. //!Same as `timed_lock`, but this function is modeled after the
  57. //!standard library interface.
  58. template<class Duration>
  59. bool try_lock_for(const Duration &)
  60. { return true; }
  61. //!Simulates a mutex unlock() operation.
  62. //!Empty function.
  63. void unlock(){}
  64. //!Simulates a mutex lock_sharable() operation.
  65. //!Empty function.
  66. void lock_sharable(){}
  67. //!Same as `lock_sharable` but with a std-compatible interface
  68. //!
  69. void lock_shared()
  70. { this->lock_sharable(); }
  71. //!Simulates a mutex try_lock_sharable() operation.
  72. //!Equivalent to "return true;"
  73. bool try_lock_sharable()
  74. { return true; }
  75. //!Same as `try_lock_sharable` but with a std-compatible interface
  76. //!
  77. bool try_lock_shared()
  78. { return this->try_lock_sharable(); }
  79. //!Simulates a mutex timed_lock_sharable() operation.
  80. //!Equivalent to "return true;"
  81. template<class TimePoint>
  82. bool timed_lock_sharable(const TimePoint &)
  83. { return true; }
  84. //!Simulates a mutex unlock_sharable() operation.
  85. //!Empty function.
  86. void unlock_sharable(){}
  87. //!Same as `unlock_sharable` but with a std-compatible interface
  88. //!
  89. void unlock_shared()
  90. { this->unlock_sharable(); }
  91. //!Simulates a mutex lock_upgradable() operation.
  92. //!Empty function.
  93. void lock_upgradable(){}
  94. //!Simulates a mutex try_lock_upgradable() operation.
  95. //!Equivalent to "return true;"
  96. bool try_lock_upgradable()
  97. { return true; }
  98. //!Simulates a mutex timed_lock_upgradable() operation.
  99. //!Equivalent to "return true;"
  100. template<class TimePoint>
  101. bool timed_lock_upgradable(const TimePoint &)
  102. { return true; }
  103. //!Simulates a mutex unlock_upgradable() operation.
  104. //!Empty function.
  105. void unlock_upgradable(){}
  106. //!Simulates unlock_and_lock_upgradable().
  107. //!Empty function.
  108. void unlock_and_lock_upgradable(){}
  109. //!Simulates unlock_and_lock_sharable().
  110. //!Empty function.
  111. void unlock_and_lock_sharable(){}
  112. //!Simulates unlock_upgradable_and_lock_sharable().
  113. //!Empty function.
  114. void unlock_upgradable_and_lock_sharable(){}
  115. //Promotions
  116. //!Simulates unlock_upgradable_and_lock().
  117. //!Empty function.
  118. void unlock_upgradable_and_lock(){}
  119. //!Simulates try_unlock_upgradable_and_lock().
  120. //!Equivalent to "return true;"
  121. bool try_unlock_upgradable_and_lock()
  122. { return true; }
  123. //!Simulates timed_unlock_upgradable_and_lock().
  124. //!Equivalent to "return true;"
  125. template<class TimePoint>
  126. bool timed_unlock_upgradable_and_lock(const TimePoint &)
  127. { return true; }
  128. //!Simulates try_unlock_sharable_and_lock().
  129. //!Equivalent to "return true;"
  130. bool try_unlock_sharable_and_lock()
  131. { return true; }
  132. //!Simulates try_unlock_sharable_and_lock_upgradable().
  133. //!Equivalent to "return true;"
  134. bool try_unlock_sharable_and_lock_upgradable()
  135. { return true; }
  136. };
  137. } //namespace interprocess {
  138. } //namespace boost {
  139. #include <boost/interprocess/detail/config_end.hpp>
  140. #endif //BOOST_INTERPROCESS_NULL_MUTEX_HPP