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_RECURSIVE_MUTEX_WEK070601_HPP
|
sl@0
|
8 |
#define BOOST_RECURSIVE_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 |
class BOOST_THREAD_DECL recursive_mutex
|
sl@0
|
33 |
: private noncopyable
|
sl@0
|
34 |
{
|
sl@0
|
35 |
public:
|
sl@0
|
36 |
friend class detail::thread::lock_ops<recursive_mutex>;
|
sl@0
|
37 |
|
sl@0
|
38 |
typedef detail::thread::scoped_lock<recursive_mutex> scoped_lock;
|
sl@0
|
39 |
|
sl@0
|
40 |
recursive_mutex();
|
sl@0
|
41 |
~recursive_mutex();
|
sl@0
|
42 |
|
sl@0
|
43 |
private:
|
sl@0
|
44 |
#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
|
sl@0
|
45 |
typedef std::size_t cv_state;
|
sl@0
|
46 |
#elif defined(BOOST_HAS_PTHREADS)
|
sl@0
|
47 |
struct cv_state
|
sl@0
|
48 |
{
|
sl@0
|
49 |
long count;
|
sl@0
|
50 |
pthread_mutex_t* pmutex;
|
sl@0
|
51 |
};
|
sl@0
|
52 |
#endif
|
sl@0
|
53 |
void do_lock();
|
sl@0
|
54 |
void do_unlock();
|
sl@0
|
55 |
void do_lock(cv_state& state);
|
sl@0
|
56 |
void do_unlock(cv_state& state);
|
sl@0
|
57 |
|
sl@0
|
58 |
#if defined(BOOST_HAS_WINTHREADS)
|
sl@0
|
59 |
void* m_mutex;
|
sl@0
|
60 |
bool m_critical_section;
|
sl@0
|
61 |
unsigned long m_count;
|
sl@0
|
62 |
#elif defined(BOOST_HAS_PTHREADS)
|
sl@0
|
63 |
pthread_mutex_t m_mutex;
|
sl@0
|
64 |
unsigned m_count;
|
sl@0
|
65 |
# if !defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE)
|
sl@0
|
66 |
pthread_cond_t m_unlocked;
|
sl@0
|
67 |
pthread_t m_thread_id;
|
sl@0
|
68 |
bool m_valid_id;
|
sl@0
|
69 |
# endif
|
sl@0
|
70 |
#elif defined(BOOST_HAS_MPTASKS)
|
sl@0
|
71 |
threads::mac::detail::scoped_critical_region m_mutex;
|
sl@0
|
72 |
threads::mac::detail::scoped_critical_region m_mutex_mutex;
|
sl@0
|
73 |
std::size_t m_count;
|
sl@0
|
74 |
#endif
|
sl@0
|
75 |
};
|
sl@0
|
76 |
|
sl@0
|
77 |
class BOOST_THREAD_DECL recursive_try_mutex
|
sl@0
|
78 |
: private noncopyable
|
sl@0
|
79 |
{
|
sl@0
|
80 |
public:
|
sl@0
|
81 |
friend class detail::thread::lock_ops<recursive_try_mutex>;
|
sl@0
|
82 |
|
sl@0
|
83 |
typedef detail::thread::scoped_lock<recursive_try_mutex> scoped_lock;
|
sl@0
|
84 |
typedef detail::thread::scoped_try_lock<
|
sl@0
|
85 |
recursive_try_mutex> scoped_try_lock;
|
sl@0
|
86 |
|
sl@0
|
87 |
recursive_try_mutex();
|
sl@0
|
88 |
~recursive_try_mutex();
|
sl@0
|
89 |
|
sl@0
|
90 |
private:
|
sl@0
|
91 |
#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
|
sl@0
|
92 |
typedef std::size_t cv_state;
|
sl@0
|
93 |
#elif defined(BOOST_HAS_PTHREADS)
|
sl@0
|
94 |
struct cv_state
|
sl@0
|
95 |
{
|
sl@0
|
96 |
long count;
|
sl@0
|
97 |
pthread_mutex_t* pmutex;
|
sl@0
|
98 |
};
|
sl@0
|
99 |
#endif
|
sl@0
|
100 |
void do_lock();
|
sl@0
|
101 |
bool do_trylock();
|
sl@0
|
102 |
void do_unlock();
|
sl@0
|
103 |
void do_lock(cv_state& state);
|
sl@0
|
104 |
void do_unlock(cv_state& state);
|
sl@0
|
105 |
|
sl@0
|
106 |
#if defined(BOOST_HAS_WINTHREADS)
|
sl@0
|
107 |
void* m_mutex;
|
sl@0
|
108 |
bool m_critical_section;
|
sl@0
|
109 |
unsigned long m_count;
|
sl@0
|
110 |
#elif defined(BOOST_HAS_PTHREADS)
|
sl@0
|
111 |
pthread_mutex_t m_mutex;
|
sl@0
|
112 |
unsigned m_count;
|
sl@0
|
113 |
# if !defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE)
|
sl@0
|
114 |
pthread_cond_t m_unlocked;
|
sl@0
|
115 |
pthread_t m_thread_id;
|
sl@0
|
116 |
bool m_valid_id;
|
sl@0
|
117 |
# endif
|
sl@0
|
118 |
#elif defined(BOOST_HAS_MPTASKS)
|
sl@0
|
119 |
threads::mac::detail::scoped_critical_region m_mutex;
|
sl@0
|
120 |
threads::mac::detail::scoped_critical_region m_mutex_mutex;
|
sl@0
|
121 |
std::size_t m_count;
|
sl@0
|
122 |
#endif
|
sl@0
|
123 |
};
|
sl@0
|
124 |
|
sl@0
|
125 |
class BOOST_THREAD_DECL recursive_timed_mutex
|
sl@0
|
126 |
: private noncopyable
|
sl@0
|
127 |
{
|
sl@0
|
128 |
public:
|
sl@0
|
129 |
friend class detail::thread::lock_ops<recursive_timed_mutex>;
|
sl@0
|
130 |
|
sl@0
|
131 |
typedef detail::thread::scoped_lock<recursive_timed_mutex> scoped_lock;
|
sl@0
|
132 |
typedef detail::thread::scoped_try_lock<
|
sl@0
|
133 |
recursive_timed_mutex> scoped_try_lock;
|
sl@0
|
134 |
typedef detail::thread::scoped_timed_lock<
|
sl@0
|
135 |
recursive_timed_mutex> scoped_timed_lock;
|
sl@0
|
136 |
|
sl@0
|
137 |
recursive_timed_mutex();
|
sl@0
|
138 |
~recursive_timed_mutex();
|
sl@0
|
139 |
|
sl@0
|
140 |
private:
|
sl@0
|
141 |
#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
|
sl@0
|
142 |
typedef std::size_t cv_state;
|
sl@0
|
143 |
#elif defined(BOOST_HAS_PTHREADS)
|
sl@0
|
144 |
struct cv_state
|
sl@0
|
145 |
{
|
sl@0
|
146 |
long count;
|
sl@0
|
147 |
pthread_mutex_t* pmutex;
|
sl@0
|
148 |
};
|
sl@0
|
149 |
#endif
|
sl@0
|
150 |
void do_lock();
|
sl@0
|
151 |
bool do_trylock();
|
sl@0
|
152 |
bool do_timedlock(const xtime& xt);
|
sl@0
|
153 |
void do_unlock();
|
sl@0
|
154 |
void do_lock(cv_state& state);
|
sl@0
|
155 |
void do_unlock(cv_state& state);
|
sl@0
|
156 |
|
sl@0
|
157 |
#if defined(BOOST_HAS_WINTHREADS)
|
sl@0
|
158 |
void* m_mutex;
|
sl@0
|
159 |
unsigned long m_count;
|
sl@0
|
160 |
#elif defined(BOOST_HAS_PTHREADS)
|
sl@0
|
161 |
pthread_mutex_t m_mutex;
|
sl@0
|
162 |
pthread_cond_t m_unlocked;
|
sl@0
|
163 |
pthread_t m_thread_id;
|
sl@0
|
164 |
bool m_valid_id;
|
sl@0
|
165 |
unsigned m_count;
|
sl@0
|
166 |
#elif defined(BOOST_HAS_MPTASKS)
|
sl@0
|
167 |
threads::mac::detail::scoped_critical_region m_mutex;
|
sl@0
|
168 |
threads::mac::detail::scoped_critical_region m_mutex_mutex;
|
sl@0
|
169 |
std::size_t m_count;
|
sl@0
|
170 |
#endif
|
sl@0
|
171 |
};
|
sl@0
|
172 |
#ifdef BOOST_MSVC
|
sl@0
|
173 |
# pragma warning(pop)
|
sl@0
|
174 |
#endif
|
sl@0
|
175 |
} // namespace boost
|
sl@0
|
176 |
|
sl@0
|
177 |
#endif // BOOST_RECURSIVE_MUTEX_WEK070601_HPP
|
sl@0
|
178 |
|
sl@0
|
179 |
// Change Log:
|
sl@0
|
180 |
// 8 Feb 01 WEKEMPF Initial version.
|
sl@0
|
181 |
// 1 Jun 01 WEKEMPF Modified to use xtime for time outs. Factored out
|
sl@0
|
182 |
// to three classes, mutex, try_mutex and timed_mutex.
|
sl@0
|
183 |
// 11 Jun 01 WEKEMPF Modified to use PTHREAD_MUTEX_RECURSIVE if available.
|
sl@0
|
184 |
// 3 Jan 03 WEKEMPF Modified for DLL implementation.
|