1 // Copyright (C) 2000 Stephen Cleary
2 // Copyright (C) 2018 Peter Dimov
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // See http://www.boost.org for updates, documentation, and revision history.
10 #ifndef BOOST_POOL_MUTEX_HPP
11 #define BOOST_POOL_MUTEX_HPP
13 #include <boost/config.hpp>
15 namespace boost{ namespace details{ namespace pool{
21 null_mutex(const null_mutex &);
22 void operator=(const null_mutex &);
29 static void unlock() {}
32 }}} // namespace boost::details::pool
34 #if !defined(BOOST_HAS_THREADS) || defined(BOOST_NO_MT) || defined(BOOST_POOL_NO_MT)
36 namespace boost{ namespace details{ namespace pool{
38 typedef null_mutex default_mutex;
40 }}} // namespace boost::details::pool
42 #elif !defined(BOOST_NO_CXX11_HDR_MUTEX)
46 namespace boost{ namespace details{ namespace pool{
48 typedef std::mutex default_mutex;
50 }}} // namespace boost::details::pool
52 #elif defined(BOOST_HAS_PTHREADS)
54 #include <boost/assert.hpp>
57 namespace boost{ namespace details{ namespace pool{
65 pt_mutex(pt_mutex const &);
66 pt_mutex & operator=(pt_mutex const &);
72 BOOST_VERIFY( pthread_mutex_init( &m_, 0 ) == 0 );
77 BOOST_VERIFY( pthread_mutex_destroy( &m_ ) == 0 );
82 BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
87 BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
91 typedef pt_mutex default_mutex;
93 }}} // namespace boost::details::pool
95 #elif defined(BOOST_HAS_WINTHREADS) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
97 #include <boost/winapi/critical_section.hpp>
99 namespace boost{ namespace details{ namespace pool{
105 boost::winapi::CRITICAL_SECTION_ cs_;
107 cs_mutex(cs_mutex const &);
108 cs_mutex & operator=(cs_mutex const &);
114 boost::winapi::InitializeCriticalSection( &cs_ );
119 boost::winapi::DeleteCriticalSection( &cs_ );
124 boost::winapi::EnterCriticalSection( &cs_ );
129 boost::winapi::LeaveCriticalSection( &cs_ );
133 typedef cs_mutex default_mutex;
135 }}} // namespace boost::details::pool
139 // Use #define BOOST_DISABLE_THREADS to avoid this error
140 # error Unrecognized threading platform
144 #endif // #ifndef BOOST_POOL_MUTEX_HPP