You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
5.6 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/synch/null_mutex.hpp (originally MLMutex.h, ::SynesisStd)
  3. *
  4. * Purpose: Mutual exclusion model class.
  5. *
  6. * Created: 19th December 1997
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 1997-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file stlsoft/synch/null_mutex.hpp
  40. *
  41. * \brief [C++ only] Definition of stlsoft::null_mutex class
  42. * (\ref group__library__synch "Synchronisation" Library).
  43. */
  44. #ifndef STLSOFT_INCL_STLSOFT_SYNCH_HPP_NULL_MUTEX
  45. #define STLSOFT_INCL_STLSOFT_SYNCH_HPP_NULL_MUTEX
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define STLSOFT_VER_STLSOFT_SYNCH_HPP_NULL_MUTEX_MAJOR 4
  48. # define STLSOFT_VER_STLSOFT_SYNCH_HPP_NULL_MUTEX_MINOR 0
  49. # define STLSOFT_VER_STLSOFT_SYNCH_HPP_NULL_MUTEX_REVISION 1
  50. # define STLSOFT_VER_STLSOFT_SYNCH_HPP_NULL_MUTEX_EDIT 41
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Includes
  54. */
  55. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  56. # include <stlsoft/stlsoft.h>
  57. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  58. #ifndef STLSOFT_INCL_STLSOFT_SYNCH_HPP_CONCEPTS
  59. # include <stlsoft/synch/concepts.hpp>
  60. #endif /* !STLSOFT_INCL_STLSOFT_SYNCH_HPP_CONCEPTS */
  61. /* /////////////////////////////////////////////////////////////////////////
  62. * Namespace
  63. */
  64. #ifndef _STLSOFT_NO_NAMESPACE
  65. namespace stlsoft
  66. {
  67. #endif /* _STLSOFT_NO_NAMESPACE */
  68. /* /////////////////////////////////////////////////////////////////////////
  69. * Classes
  70. */
  71. // class null_mutex
  72. /** \brief This class provides a null implementation of the mutex model.
  73. *
  74. * \ingroup group__library__synch
  75. */
  76. class null_mutex
  77. : public critical_section< STLSOFT_CRITICAL_SECTION_IS_RECURSIVE
  78. , STLSOFT_CRITICAL_SECTION_ISNOT_TRYABLE
  79. >
  80. {
  81. /// \name Member Types
  82. /// @{
  83. public:
  84. typedef null_mutex class_type;
  85. /// @}
  86. /// \name Construction
  87. /// @{
  88. public:
  89. /// \brief Creates an instance of the mutex
  90. null_mutex() stlsoft_throw_0()
  91. {}
  92. /// @}
  93. /// \name Operations
  94. /// @{
  95. public:
  96. /// \brief Acquires a lock on the mutex, pending the thread until the lock is aquired
  97. void lock() stlsoft_throw_0()
  98. {}
  99. /// \brief Releases an aquired lock on the mutex
  100. void unlock() stlsoft_throw_0()
  101. {}
  102. /// @}
  103. /// \name Not to be implemented
  104. /// @{
  105. private:
  106. null_mutex(class_type const& rhs);
  107. null_mutex& operator =(class_type const& rhs);
  108. /// @}
  109. };
  110. /* /////////////////////////////////////////////////////////////////////////
  111. * Control shims
  112. */
  113. /** \brief This \ref group__concept__shims "control shim" aquires a lock on the given mutex
  114. *
  115. * \ingroup group__concept__shim__synchronisation_control
  116. *
  117. * \param mx The mutex on which to aquire the lock.
  118. */
  119. inline void lock_instance(stlsoft_ns_qual(null_mutex) &mx)
  120. {
  121. STLSOFT_SUPPRESS_UNUSED(mx); // This is used, instead of the preferred omission of parameter, since it upsets the documentation
  122. }
  123. /** \brief This \ref group__concept__shims "control shim" releases a lock on the given mutex
  124. *
  125. * \ingroup group__concept__shim__synchronisation_control
  126. *
  127. * \param mx The mutex on which to release the lock
  128. */
  129. inline void unlock_instance(stlsoft_ns_qual(null_mutex) &mx)
  130. {
  131. STLSOFT_SUPPRESS_UNUSED(mx); // This is used, instead of the preferred omission of parameter, since it upsets the documentation
  132. }
  133. ////////////////////////////////////////////////////////////////////////////
  134. // Unit-testing
  135. #ifdef STLSOFT_UNITTEST
  136. # include "./unittest/null_mutex_unittest_.h"
  137. #endif /* STLSOFT_UNITTEST */
  138. /* ////////////////////////////////////////////////////////////////////// */
  139. #ifndef _STLSOFT_NO_NAMESPACE
  140. } // namespace stlsoft
  141. #endif /* _STLSOFT_NO_NAMESPACE */
  142. /* ////////////////////////////////////////////////////////////////////// */
  143. #endif /* !STLSOFT_INCL_STLSOFT_SYNCH_HPP_NULL_MUTEX */
  144. /* ///////////////////////////// end of file //////////////////////////// */