author | sl@SLION-WIN7.fritz.box |
Fri, 15 Jun 2012 03:10:57 +0200 | |
changeset 0 | bde4ae8d615e |
permissions | -rw-r--r-- |
sl@0 | 1 |
// Copyright (C) 2001-2003 |
sl@0 | 2 |
// William E. Kempf |
sl@0 | 3 |
// |
sl@0 | 4 |
// Distributed under the Boost Software License, Version 1.0. (See accompanying |
sl@0 | 5 |
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
sl@0 | 6 |
|
sl@0 | 7 |
#ifndef BOOST_MUTEX_WEK070601_HPP |
sl@0 | 8 |
#define BOOST_MUTEX_WEK070601_HPP |
sl@0 | 9 |
|
sl@0 | 10 |
#include <boost/thread/detail/config.hpp> |
sl@0 | 11 |
|
sl@0 | 12 |
#include <boost/utility.hpp> |
sl@0 | 13 |
#include <boost/thread/detail/lock.hpp> |
sl@0 | 14 |
|
sl@0 | 15 |
#if defined(BOOST_HAS_PTHREADS) |
sl@0 | 16 |
# include <pthread.h> |
sl@0 | 17 |
#endif |
sl@0 | 18 |
|
sl@0 | 19 |
#if defined(BOOST_HAS_MPTASKS) |
sl@0 | 20 |
# include "scoped_critical_region.hpp" |
sl@0 | 21 |
#endif |
sl@0 | 22 |
|
sl@0 | 23 |
namespace boost { |
sl@0 | 24 |
|
sl@0 | 25 |
struct xtime; |
sl@0 | 26 |
// disable warnings about non dll import |
sl@0 | 27 |
// see: http://www.boost.org/more/separate_compilation.html#dlls |
sl@0 | 28 |
#ifdef BOOST_MSVC |
sl@0 | 29 |
# pragma warning(push) |
sl@0 | 30 |
# pragma warning(disable: 4251 4231 4660 4275) |
sl@0 | 31 |
#endif |
sl@0 | 32 |
|
sl@0 | 33 |
class BOOST_THREAD_DECL mutex |
sl@0 | 34 |
: private noncopyable |
sl@0 | 35 |
{ |
sl@0 | 36 |
public: |
sl@0 | 37 |
friend class detail::thread::lock_ops<mutex>; |
sl@0 | 38 |
|
sl@0 | 39 |
typedef detail::thread::scoped_lock<mutex> scoped_lock; |
sl@0 | 40 |
|
sl@0 | 41 |
mutex(); |
sl@0 | 42 |
~mutex(); |
sl@0 | 43 |
|
sl@0 | 44 |
private: |
sl@0 | 45 |
#if defined(BOOST_HAS_WINTHREADS) |
sl@0 | 46 |
typedef void* cv_state; |
sl@0 | 47 |
#elif defined(BOOST_HAS_PTHREADS) |
sl@0 | 48 |
struct cv_state |
sl@0 | 49 |
{ |
sl@0 | 50 |
pthread_mutex_t* pmutex; |
sl@0 | 51 |
}; |
sl@0 | 52 |
#elif defined(BOOST_HAS_MPTASKS) |
sl@0 | 53 |
struct cv_state |
sl@0 | 54 |
{ |
sl@0 | 55 |
}; |
sl@0 | 56 |
#endif |
sl@0 | 57 |
void do_lock(); |
sl@0 | 58 |
void do_unlock(); |
sl@0 | 59 |
void do_lock(cv_state& state); |
sl@0 | 60 |
void do_unlock(cv_state& state); |
sl@0 | 61 |
|
sl@0 | 62 |
#if defined(BOOST_HAS_WINTHREADS) |
sl@0 | 63 |
void* m_mutex; |
sl@0 | 64 |
bool m_critical_section; |
sl@0 | 65 |
#elif defined(BOOST_HAS_PTHREADS) |
sl@0 | 66 |
pthread_mutex_t m_mutex; |
sl@0 | 67 |
#elif defined(BOOST_HAS_MPTASKS) |
sl@0 | 68 |
threads::mac::detail::scoped_critical_region m_mutex; |
sl@0 | 69 |
threads::mac::detail::scoped_critical_region m_mutex_mutex; |
sl@0 | 70 |
#endif |
sl@0 | 71 |
}; |
sl@0 | 72 |
|
sl@0 | 73 |
class BOOST_THREAD_DECL try_mutex |
sl@0 | 74 |
: private noncopyable |
sl@0 | 75 |
{ |
sl@0 | 76 |
public: |
sl@0 | 77 |
friend class detail::thread::lock_ops<try_mutex>; |
sl@0 | 78 |
|
sl@0 | 79 |
typedef detail::thread::scoped_lock<try_mutex> scoped_lock; |
sl@0 | 80 |
typedef detail::thread::scoped_try_lock<try_mutex> scoped_try_lock; |
sl@0 | 81 |
|
sl@0 | 82 |
try_mutex(); |
sl@0 | 83 |
~try_mutex(); |
sl@0 | 84 |
|
sl@0 | 85 |
private: |
sl@0 | 86 |
#if defined(BOOST_HAS_WINTHREADS) |
sl@0 | 87 |
typedef void* cv_state; |
sl@0 | 88 |
#elif defined(BOOST_HAS_PTHREADS) |
sl@0 | 89 |
struct cv_state |
sl@0 | 90 |
{ |
sl@0 | 91 |
pthread_mutex_t* pmutex; |
sl@0 | 92 |
}; |
sl@0 | 93 |
#elif defined(BOOST_HAS_MPTASKS) |
sl@0 | 94 |
struct cv_state |
sl@0 | 95 |
{ |
sl@0 | 96 |
}; |
sl@0 | 97 |
#endif |
sl@0 | 98 |
void do_lock(); |
sl@0 | 99 |
bool do_trylock(); |
sl@0 | 100 |
void do_unlock(); |
sl@0 | 101 |
void do_lock(cv_state& state); |
sl@0 | 102 |
void do_unlock(cv_state& state); |
sl@0 | 103 |
|
sl@0 | 104 |
#if defined(BOOST_HAS_WINTHREADS) |
sl@0 | 105 |
void* m_mutex; |
sl@0 | 106 |
bool m_critical_section; |
sl@0 | 107 |
#elif defined(BOOST_HAS_PTHREADS) |
sl@0 | 108 |
pthread_mutex_t m_mutex; |
sl@0 | 109 |
#elif defined(BOOST_HAS_MPTASKS) |
sl@0 | 110 |
threads::mac::detail::scoped_critical_region m_mutex; |
sl@0 | 111 |
threads::mac::detail::scoped_critical_region m_mutex_mutex; |
sl@0 | 112 |
#endif |
sl@0 | 113 |
}; |
sl@0 | 114 |
|
sl@0 | 115 |
class BOOST_THREAD_DECL timed_mutex |
sl@0 | 116 |
: private noncopyable |
sl@0 | 117 |
{ |
sl@0 | 118 |
public: |
sl@0 | 119 |
friend class detail::thread::lock_ops<timed_mutex>; |
sl@0 | 120 |
|
sl@0 | 121 |
typedef detail::thread::scoped_lock<timed_mutex> scoped_lock; |
sl@0 | 122 |
typedef detail::thread::scoped_try_lock<timed_mutex> scoped_try_lock; |
sl@0 | 123 |
typedef detail::thread::scoped_timed_lock<timed_mutex> scoped_timed_lock; |
sl@0 | 124 |
|
sl@0 | 125 |
timed_mutex(); |
sl@0 | 126 |
~timed_mutex(); |
sl@0 | 127 |
|
sl@0 | 128 |
private: |
sl@0 | 129 |
#if defined(BOOST_HAS_WINTHREADS) |
sl@0 | 130 |
typedef void* cv_state; |
sl@0 | 131 |
#elif defined(BOOST_HAS_PTHREADS) |
sl@0 | 132 |
struct cv_state |
sl@0 | 133 |
{ |
sl@0 | 134 |
pthread_mutex_t* pmutex; |
sl@0 | 135 |
}; |
sl@0 | 136 |
#elif defined(BOOST_HAS_MPTASKS) |
sl@0 | 137 |
struct cv_state |
sl@0 | 138 |
{ |
sl@0 | 139 |
}; |
sl@0 | 140 |
#endif |
sl@0 | 141 |
void do_lock(); |
sl@0 | 142 |
bool do_trylock(); |
sl@0 | 143 |
bool do_timedlock(const xtime& xt); |
sl@0 | 144 |
void do_unlock(); |
sl@0 | 145 |
void do_lock(cv_state& state); |
sl@0 | 146 |
void do_unlock(cv_state& state); |
sl@0 | 147 |
|
sl@0 | 148 |
#if defined(BOOST_HAS_WINTHREADS) |
sl@0 | 149 |
void* m_mutex; |
sl@0 | 150 |
#elif defined(BOOST_HAS_PTHREADS) |
sl@0 | 151 |
pthread_mutex_t m_mutex; |
sl@0 | 152 |
pthread_cond_t m_condition; |
sl@0 | 153 |
bool m_locked; |
sl@0 | 154 |
#elif defined(BOOST_HAS_MPTASKS) |
sl@0 | 155 |
threads::mac::detail::scoped_critical_region m_mutex; |
sl@0 | 156 |
threads::mac::detail::scoped_critical_region m_mutex_mutex; |
sl@0 | 157 |
#endif |
sl@0 | 158 |
}; |
sl@0 | 159 |
#ifdef BOOST_MSVC |
sl@0 | 160 |
# pragma warning(pop) |
sl@0 | 161 |
#endif |
sl@0 | 162 |
} // namespace boost |
sl@0 | 163 |
|
sl@0 | 164 |
// Change Log: |
sl@0 | 165 |
// 8 Feb 01 WEKEMPF Initial version. |
sl@0 | 166 |
// 22 May 01 WEKEMPF Modified to use xtime for time outs. Factored out |
sl@0 | 167 |
// to three classes, mutex, try_mutex and timed_mutex. |
sl@0 | 168 |
// 3 Jan 03 WEKEMPF Modified for DLL implementation. |
sl@0 | 169 |
|
sl@0 | 170 |
#endif // BOOST_MUTEX_WEK070601_HPP |