1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2018-2018. 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)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
10 //////////////////////////////////////////////////////////////////////////////
12 // This code is partially based on the lightweight mutex implemented
15 // Copyright (c) 2002, 2003 Peter Dimov
16 // Copyright (c) Microsoft Corporation 2014
18 // Distributed under the Boost Software License, Version 1.0. (See
19 // accompanying file LICENSE_1_0.txt or copy at
20 // http://www.boost.org/LICENSE_1_0.txt)
22 //////////////////////////////////////////////////////////////////////////////
24 #ifndef BOOST_CONFIG_HPP
25 # include <boost/config.hpp>
28 #if defined(BOOST_HAS_PRAGMA_ONCE)
32 #ifndef BOOST_CONTAINER_DETAIL_THREAD_MUTEX_HPP
33 #define BOOST_CONTAINER_DETAIL_THREAD_MUTEX_HPP
35 #include <boost/container/detail/config_begin.hpp>
36 #include <boost/container/detail/workaround.hpp>
38 #if defined(BOOST_HAS_PTHREADS)
41 #include <boost/assert.hpp>
52 BOOST_VERIFY(pthread_mutex_init(&m_mut, 0) == 0);
57 BOOST_VERIFY(pthread_mutex_destroy(&m_mut) == 0);
62 BOOST_VERIFY(pthread_mutex_lock( &m_mut) == 0);
67 BOOST_VERIFY(pthread_mutex_unlock(&m_mut) == 0);
71 thread_mutex(thread_mutex const &);
72 thread_mutex & operator=(thread_mutex const &);
74 pthread_mutex_t m_mut;
78 } // namespace container {
79 } // namespace boost {
81 #else //!BOOST_HAS_PTHREADS (Windows implementation)
83 #ifdef BOOST_USE_WINDOWS_H
91 typedef ::CRITICAL_SECTION win_critical_section;
94 } // namespace container {
95 } // namespace boost {
97 #else //! BOOST_USE_WINDOWS_H
99 struct _RTL_CRITICAL_SECTION_DEBUG;
100 struct _RTL_CRITICAL_SECTION;
103 namespace container {
106 #ifdef BOOST_PLAT_WINDOWS_UWP
107 extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSectionEx(::_RTL_CRITICAL_SECTION *, unsigned long, unsigned long);
109 extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(::_RTL_CRITICAL_SECTION *);
111 extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(::_RTL_CRITICAL_SECTION *);
112 extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(::_RTL_CRITICAL_SECTION *);
113 extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(::_RTL_CRITICAL_SECTION *);
115 struct win_critical_section
117 struct _RTL_CRITICAL_SECTION_DEBUG * DebugInfo;
121 void * LockSemaphore;
123 unsigned __int64 SpinCount;
125 unsigned long SpinCount;
130 } // namespace container {
131 } // namespace boost {
133 #endif //BOOST_USE_WINDOWS_H
136 namespace container {
144 #ifdef BOOST_PLAT_WINDOWS_UWP
145 (InitializeCriticalSectionEx)(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&m_crit_sect), 4000, 0);
147 (InitializeCriticalSection)(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&m_crit_sect));
153 (EnterCriticalSection)(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&m_crit_sect));
158 (LeaveCriticalSection)(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&m_crit_sect));
163 (DeleteCriticalSection)(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&m_crit_sect));
167 thread_mutex(thread_mutex const &);
168 thread_mutex & operator=(thread_mutex const &);
170 win_critical_section m_crit_sect;
174 } // namespace container {
175 } // namespace boost {
177 #endif //BOOST_HAS_PTHREADS
179 #include <boost/container/detail/config_end.hpp>
181 #endif // #ifndef BOOST_CONTAINER_DETAIL_THREAD_MUTEX_HPP