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.

151 lines
5.0 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/synch/singlethreaded_tss_index.hpp
  3. *
  4. * Purpose: An interface-compatible replacement for the tss_index
  5. * classes defined elsewhere in the libraries, for use in
  6. * single-threaded contexts.
  7. *
  8. * Created: 3rd February 2008
  9. * Updated: 10th August 2009
  10. *
  11. * Home: http://stlsoft.org/
  12. *
  13. * Copyright (c) 2008-2009, Matthew Wilson and Synesis Software
  14. * All rights reserved.
  15. *
  16. * Redistribution and use in source and binary forms, with or without
  17. * modification, are permitted provided that the following conditions are met:
  18. *
  19. * - Redistributions of source code must retain the above copyright notice, this
  20. * list of conditions and the following disclaimer.
  21. * - Redistributions in binary form must reproduce the above copyright notice,
  22. * this list of conditions and the following disclaimer in the documentation
  23. * and/or other materials provided with the distribution.
  24. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  25. * any contributors may be used to endorse or promote products derived from
  26. * this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  29. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  34. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  35. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  37. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * ////////////////////////////////////////////////////////////////////// */
  41. /** \file stlsoft/synch/singlethreaded_tss_index.hpp
  42. *
  43. * \brief [C++ only] An interface-compatible replacement for the tss_index
  44. * classes defined elsewhere in the libraries, for use in single-threaded
  45. * contexts.
  46. * (\ref group__library__synch "Synchronisation" Library).
  47. */
  48. #ifndef STLSOFT_INCL_STLSOFT_SYNCH_HPP_SINGLE_THREADED_TSS_INDEX
  49. #define STLSOFT_INCL_STLSOFT_SYNCH_HPP_SINGLE_THREADED_TSS_INDEX
  50. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  51. # define STLSOFT_VER_STLSOFT_SYNCH_HPP_SINGLE_THREADED_TSS_INDEX_MAJOR 1
  52. # define STLSOFT_VER_STLSOFT_SYNCH_HPP_SINGLE_THREADED_TSS_INDEX_MINOR 0
  53. # define STLSOFT_VER_STLSOFT_SYNCH_HPP_SINGLE_THREADED_TSS_INDEX_REVISION 2
  54. # define STLSOFT_VER_STLSOFT_SYNCH_HPP_SINGLE_THREADED_TSS_INDEX_EDIT 3
  55. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  56. /* /////////////////////////////////////////////////////////////////////////
  57. * Includes
  58. */
  59. #ifndef STLSOFT_INCL_STLSOFT_H_UNIXSTL
  60. # include <stlsoft/stlsoft.h>
  61. #endif /* !STLSOFT_INCL_STLSOFT_H_UNIXSTL */
  62. /* /////////////////////////////////////////////////////////////////////////
  63. * Namespace
  64. */
  65. #ifndef _STLSOFT_NO_NAMESPACE
  66. namespace stlsoft
  67. {
  68. #endif /* _STLSOFT_NO_NAMESPACE */
  69. /* /////////////////////////////////////////////////////////////////////////
  70. * Classes
  71. */
  72. /** \brief Interface-compatible single-threaded replacement for
  73. * unixstl::tss_index, winstl::tss_index and platformstl::tss_index.
  74. *
  75. * \ingroup group__library__synch
  76. */
  77. class singlethreaded_tss_index
  78. {
  79. /// \name Types
  80. /// @{
  81. public:
  82. /// \brief This class
  83. typedef singlethreaded_tss_index class_type;
  84. /// \brief The type of the TSS key
  85. typedef void key_type;
  86. /// \brief The type of the slot values
  87. typedef void* value_type;
  88. /// @}
  89. /// \name Construction
  90. /// @{
  91. public:
  92. /// \brief Allocates a TSS key
  93. ss_explicit_k singlethreaded_tss_index()
  94. : m_value(NULL)
  95. {}
  96. /// \brief Releases the TSS key
  97. ~singlethreaded_tss_index() stlsoft_throw_0()
  98. {}
  99. /// @}
  100. /// \name Operations
  101. /// @{
  102. public:
  103. /// \brief Sets the value in the slot for the current thread
  104. void set_value(value_type value)
  105. {
  106. m_value = value;
  107. }
  108. /// \brief Gets the value in the slot for the current thread
  109. value_type get_value() const
  110. {
  111. return m_value;
  112. }
  113. /// @}
  114. /// \name Members
  115. /// @{
  116. private:
  117. value_type m_value;
  118. /// @}
  119. /// \name Not to be implemented
  120. /// @{
  121. private:
  122. singlethreaded_tss_index(class_type const&);
  123. class_type& operator =(class_type const&);
  124. /// @}
  125. };
  126. /* ////////////////////////////////////////////////////////////////////// */
  127. #ifndef _STLSOFT_NO_NAMESPACE
  128. } // namespace stlsoft
  129. #endif /* _STLSOFT_NO_NAMESPACE */
  130. /* ////////////////////////////////////////////////////////////////////// */
  131. #endif /* !STLSOFT_INCL_STLSOFT_SYNCH_HPP_SINGLE_THREADED_TSS_INDEX */
  132. /* ///////////////////////////// end of file //////////////////////////// */