1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/pool/detail/mutex.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,145 @@
1.4 +// Copyright (C) 2000 Stephen Cleary
1.5 +//
1.6 +// Distributed under the Boost Software License, Version 1.0. (See
1.7 +// accompanying file LICENSE_1_0.txt or copy at
1.8 +// http://www.boost.org/LICENSE_1_0.txt)
1.9 +//
1.10 +// See http://www.boost.org for updates, documentation, and revision history.
1.11 +
1.12 +#ifndef BOOST_POOL_MUTEX_HPP
1.13 +#define BOOST_POOL_MUTEX_HPP
1.14 +
1.15 +#include <boost/config.hpp> // for workarounds
1.16 +
1.17 +// Extremely Light-Weight wrapper classes for OS thread synchronization
1.18 +
1.19 +// Configuration: for now, we just choose between pthread or Win32 mutexes or none
1.20 +
1.21 +#define BOOST_MUTEX_HELPER_NONE 0
1.22 +#define BOOST_MUTEX_HELPER_WIN32 1
1.23 +#define BOOST_MUTEX_HELPER_PTHREAD 2
1.24 +
1.25 +#if !defined(BOOST_HAS_THREADS) && !defined(BOOST_NO_MT)
1.26 +# define BOOST_NO_MT
1.27 +#endif
1.28 +
1.29 +#ifdef BOOST_NO_MT
1.30 + // No multithreading -> make locks into no-ops
1.31 + #define BOOST_MUTEX_HELPER BOOST_MUTEX_HELPER_NONE
1.32 +#else
1.33 + #ifdef BOOST_WINDOWS
1.34 + #define BOOST_MUTEX_HELPER BOOST_MUTEX_HELPER_WIN32
1.35 + #else
1.36 + #include <unistd.h>
1.37 + #ifdef _POSIX_THREADS
1.38 + #define BOOST_MUTEX_HELPER BOOST_MUTEX_HELPER_PTHREAD
1.39 + #endif
1.40 + #endif
1.41 +#endif
1.42 +
1.43 +#ifndef BOOST_MUTEX_HELPER
1.44 + #error Unable to determine platform mutex type; define BOOST_NO_MT to assume single-threaded
1.45 +#endif
1.46 +
1.47 +#ifndef BOOST_NO_MT
1.48 +# ifdef BOOST_WINDOWS
1.49 +# include <windows.h>
1.50 +# endif
1.51 +# ifdef _POSIX_THREADS
1.52 +# include <pthread.h>
1.53 +# endif
1.54 +#endif
1.55 +
1.56 +namespace boost {
1.57 +
1.58 +namespace details {
1.59 +namespace pool {
1.60 +
1.61 +#ifndef BOOST_NO_MT
1.62 +
1.63 +#ifdef BOOST_WINDOWS
1.64 +
1.65 +class win32_mutex
1.66 +{
1.67 + private:
1.68 + CRITICAL_SECTION mtx;
1.69 +
1.70 + win32_mutex(const win32_mutex &);
1.71 + void operator=(const win32_mutex &);
1.72 +
1.73 + public:
1.74 + win32_mutex()
1.75 + { InitializeCriticalSection(&mtx); }
1.76 +
1.77 + ~win32_mutex()
1.78 + { DeleteCriticalSection(&mtx); }
1.79 +
1.80 + void lock()
1.81 + { EnterCriticalSection(&mtx); }
1.82 +
1.83 + void unlock()
1.84 + { LeaveCriticalSection(&mtx); }
1.85 +};
1.86 +
1.87 +#endif // defined(BOOST_WINDOWS)
1.88 +
1.89 +#ifdef _POSIX_THREADS
1.90 +
1.91 +class pthread_mutex
1.92 +{
1.93 + private:
1.94 + pthread_mutex_t mtx;
1.95 +
1.96 + pthread_mutex(const pthread_mutex &);
1.97 + void operator=(const pthread_mutex &);
1.98 +
1.99 + public:
1.100 + pthread_mutex()
1.101 + { pthread_mutex_init(&mtx, 0); }
1.102 +
1.103 + ~pthread_mutex()
1.104 + { pthread_mutex_destroy(&mtx); }
1.105 +
1.106 + void lock()
1.107 + { pthread_mutex_lock(&mtx); }
1.108 +
1.109 + void unlock()
1.110 + { pthread_mutex_unlock(&mtx); }
1.111 +};
1.112 +
1.113 +#endif // defined(_POSIX_THREADS)
1.114 +
1.115 +#endif // !defined(BOOST_NO_MT)
1.116 +
1.117 +class null_mutex
1.118 +{
1.119 + private:
1.120 + null_mutex(const null_mutex &);
1.121 + void operator=(const null_mutex &);
1.122 +
1.123 + public:
1.124 + null_mutex() { }
1.125 +
1.126 + static void lock() { }
1.127 + static void unlock() { }
1.128 +};
1.129 +
1.130 +#if BOOST_MUTEX_HELPER == BOOST_MUTEX_HELPER_NONE
1.131 + typedef null_mutex default_mutex;
1.132 +#elif BOOST_MUTEX_HELPER == BOOST_MUTEX_HELPER_WIN32
1.133 + typedef win32_mutex default_mutex;
1.134 +#elif BOOST_MUTEX_HELPER == BOOST_MUTEX_HELPER_PTHREAD
1.135 + typedef pthread_mutex default_mutex;
1.136 +#endif
1.137 +
1.138 +} // namespace pool
1.139 +} // namespace details
1.140 +
1.141 +} // namespace boost
1.142 +
1.143 +#undef BOOST_MUTEX_HELPER_WIN32
1.144 +#undef BOOST_MUTEX_HELPER_PTHREAD
1.145 +#undef BOOST_MUTEX_HELPER_NONE
1.146 +#undef BOOST_MUTEX_HELPER
1.147 +
1.148 +#endif