First public contribution.
1 // Copyright (C) 2000 Stephen Cleary
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org for updates, documentation, and revision history.
9 #ifndef BOOST_POOL_MUTEX_HPP
10 #define BOOST_POOL_MUTEX_HPP
12 #include <boost/config.hpp> // for workarounds
14 // Extremely Light-Weight wrapper classes for OS thread synchronization
16 // Configuration: for now, we just choose between pthread or Win32 mutexes or none
18 #define BOOST_MUTEX_HELPER_NONE 0
19 #define BOOST_MUTEX_HELPER_WIN32 1
20 #define BOOST_MUTEX_HELPER_PTHREAD 2
22 #if !defined(BOOST_HAS_THREADS) && !defined(BOOST_NO_MT)
27 // No multithreading -> make locks into no-ops
28 #define BOOST_MUTEX_HELPER BOOST_MUTEX_HELPER_NONE
31 #define BOOST_MUTEX_HELPER BOOST_MUTEX_HELPER_WIN32
35 #define BOOST_MUTEX_HELPER BOOST_MUTEX_HELPER_PTHREAD
40 #ifndef BOOST_MUTEX_HELPER
41 #error Unable to determine platform mutex type; define BOOST_NO_MT to assume single-threaded
48 # ifdef _POSIX_THREADS
67 win32_mutex(const win32_mutex &);
68 void operator=(const win32_mutex &);
72 { InitializeCriticalSection(&mtx); }
75 { DeleteCriticalSection(&mtx); }
78 { EnterCriticalSection(&mtx); }
81 { LeaveCriticalSection(&mtx); }
84 #endif // defined(BOOST_WINDOWS)
93 pthread_mutex(const pthread_mutex &);
94 void operator=(const pthread_mutex &);
98 { pthread_mutex_init(&mtx, 0); }
101 { pthread_mutex_destroy(&mtx); }
104 { pthread_mutex_lock(&mtx); }
107 { pthread_mutex_unlock(&mtx); }
110 #endif // defined(_POSIX_THREADS)
112 #endif // !defined(BOOST_NO_MT)
117 null_mutex(const null_mutex &);
118 void operator=(const null_mutex &);
123 static void lock() { }
124 static void unlock() { }
127 #if BOOST_MUTEX_HELPER == BOOST_MUTEX_HELPER_NONE
128 typedef null_mutex default_mutex;
129 #elif BOOST_MUTEX_HELPER == BOOST_MUTEX_HELPER_WIN32
130 typedef win32_mutex default_mutex;
131 #elif BOOST_MUTEX_HELPER == BOOST_MUTEX_HELPER_PTHREAD
132 typedef pthread_mutex default_mutex;
136 } // namespace details
140 #undef BOOST_MUTEX_HELPER_WIN32
141 #undef BOOST_MUTEX_HELPER_PTHREAD
142 #undef BOOST_MUTEX_HELPER_NONE
143 #undef BOOST_MUTEX_HELPER