File indexing completed on 2025-01-18 09:48:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_POOL_MUTEX_HPP
0011 #define BOOST_POOL_MUTEX_HPP
0012
0013 #include <boost/config.hpp>
0014
0015 namespace boost{ namespace details{ namespace pool{
0016
0017 class null_mutex
0018 {
0019 private:
0020
0021 null_mutex(const null_mutex &);
0022 void operator=(const null_mutex &);
0023
0024 public:
0025
0026 null_mutex() {}
0027
0028 static void lock() {}
0029 static void unlock() {}
0030 };
0031
0032 }}}
0033
0034 #if !defined(BOOST_HAS_THREADS) || defined(BOOST_NO_MT) || defined(BOOST_POOL_NO_MT)
0035
0036 namespace boost{ namespace details{ namespace pool{
0037
0038 typedef null_mutex default_mutex;
0039
0040 }}}
0041
0042 #elif !defined(BOOST_NO_CXX11_HDR_MUTEX)
0043
0044 #include <mutex>
0045
0046 namespace boost{ namespace details{ namespace pool{
0047
0048 typedef std::mutex default_mutex;
0049
0050 }}}
0051
0052 #elif defined(BOOST_HAS_PTHREADS)
0053
0054 #include <boost/assert.hpp>
0055 #include <pthread.h>
0056
0057 namespace boost{ namespace details{ namespace pool{
0058
0059 class pt_mutex
0060 {
0061 private:
0062
0063 pthread_mutex_t m_;
0064
0065 pt_mutex(pt_mutex const &);
0066 pt_mutex & operator=(pt_mutex const &);
0067
0068 public:
0069
0070 pt_mutex()
0071 {
0072 BOOST_VERIFY( pthread_mutex_init( &m_, 0 ) == 0 );
0073 }
0074
0075 ~pt_mutex()
0076 {
0077 BOOST_VERIFY( pthread_mutex_destroy( &m_ ) == 0 );
0078 }
0079
0080 void lock()
0081 {
0082 BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
0083 }
0084
0085 void unlock()
0086 {
0087 BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
0088 }
0089 };
0090
0091 typedef pt_mutex default_mutex;
0092
0093 }}}
0094
0095 #elif defined(BOOST_HAS_WINTHREADS) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
0096
0097 #include <boost/winapi/critical_section.hpp>
0098
0099 namespace boost{ namespace details{ namespace pool{
0100
0101 class cs_mutex
0102 {
0103 private:
0104
0105 boost::winapi::CRITICAL_SECTION_ cs_;
0106
0107 cs_mutex(cs_mutex const &);
0108 cs_mutex & operator=(cs_mutex const &);
0109
0110 public:
0111
0112 cs_mutex()
0113 {
0114 boost::winapi::InitializeCriticalSection( &cs_ );
0115 }
0116
0117 ~cs_mutex()
0118 {
0119 boost::winapi::DeleteCriticalSection( &cs_ );
0120 }
0121
0122 void lock()
0123 {
0124 boost::winapi::EnterCriticalSection( &cs_ );
0125 }
0126
0127 void unlock()
0128 {
0129 boost::winapi::LeaveCriticalSection( &cs_ );
0130 }
0131 };
0132
0133 typedef cs_mutex default_mutex;
0134
0135 }}}
0136
0137 #else
0138
0139
0140 # error Unrecognized threading platform
0141
0142 #endif
0143
0144 #endif