1
// Copyright (C) 2000 Stephen Cleary (shammah@voyager.net)
3
// This file can be redistributed and/or modified under the terms found
5
// This software and its documentation is provided "as is" without express or
6
// implied warranty, and with no claim as to its suitability for any purpose.
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
// Extremely Light-Weight wrapper classes for OS thread synchronization
15
// Configuration: for now, we just choose between pthread or Win32 mutexes or none
17
#define BOOST_MUTEX_HELPER_NONE 0
18
#define BOOST_MUTEX_HELPER_WIN32 1
19
#define BOOST_MUTEX_HELPER_PTHREAD 2
22
// No multithreading -> make locks into no-ops
23
#define BOOST_MUTEX_HELPER BOOST_MUTEX_HELPER_NONE
26
#define BOOST_MUTEX_HELPER BOOST_MUTEX_HELPER_WIN32
30
#define BOOST_MUTEX_HELPER BOOST_MUTEX_HELPER_PTHREAD
35
#ifndef BOOST_MUTEX_HELPER
36
#error Unable to determine platform mutex type; define BOOST_NO_MT to assume single-threaded
59
win32_mutex(const win32_mutex &);
60
void operator=(const win32_mutex &);
64
{ InitializeCriticalSection(&mtx); }
67
{ DeleteCriticalSection(&mtx); }
70
{ EnterCriticalSection(&mtx); }
73
{ LeaveCriticalSection(&mtx); }
76
#endif // defined(__WIN32__)
85
pthread_mutex(const pthread_mutex &);
86
void operator=(const pthread_mutex &);
90
{ pthread_mutex_init(&mtx, 0); }
93
{ pthread_mutex_destroy(&mtx); }
96
{ pthread_mutex_lock(&mtx); }
99
{ pthread_mutex_unlock(&mtx); }
102
#endif // defined(_POSIX_THREADS)
107
null_mutex(const null_mutex &);
108
void operator=(const null_mutex &);
113
static void lock() { }
114
static void unlock() { }
117
#if BOOST_MUTEX_HELPER == BOOST_MUTEX_HELPER_NONE
118
typedef null_mutex default_mutex;
119
#elif BOOST_MUTEX_HELPER == BOOST_MUTEX_HELPER_WIN32
120
typedef win32_mutex default_mutex;
121
#elif BOOST_MUTEX_HELPER == BOOST_MUTEX_HELPER_PTHREAD
122
typedef pthread_mutex default_mutex;
126
} // namespace details
130
#undef BOOST_MUTEX_HELPER_WIN32
131
#undef BOOST_MUTEX_HELPER_PTHREAD
132
#undef BOOST_MUTEX_HELPER_NONE
133
#undef BOOST_MUTEX_HELPER