1 | // Copyright (C) 2001-2003 |
---|
2 | // William E. Kempf |
---|
3 | // |
---|
4 | // Permission to use, copy, modify, distribute and sell this software |
---|
5 | // and its documentation for any purpose is hereby granted without fee, |
---|
6 | // provided that the above copyright notice appear in all copies and |
---|
7 | // that both that copyright notice and this permission notice appear |
---|
8 | // in supporting documentation. William E. Kempf makes no representations |
---|
9 | // about the suitability of this software for any purpose. |
---|
10 | // It is provided "as is" without express or implied warranty. |
---|
11 | |
---|
12 | #ifndef BOOST_MUTEX_WEK070601_HPP |
---|
13 | #define BOOST_MUTEX_WEK070601_HPP |
---|
14 | |
---|
15 | #include <boost/thread/detail/config.hpp> |
---|
16 | |
---|
17 | #include <boost/utility.hpp> |
---|
18 | #include <boost/thread/detail/lock.hpp> |
---|
19 | |
---|
20 | #if defined(BOOST_HAS_PTHREADS) |
---|
21 | # include <pthread.h> |
---|
22 | #endif |
---|
23 | |
---|
24 | #if defined(BOOST_HAS_MPTASKS) |
---|
25 | # include "scoped_critical_region.hpp" |
---|
26 | #endif |
---|
27 | |
---|
28 | namespace boost { |
---|
29 | |
---|
30 | struct xtime; |
---|
31 | |
---|
32 | class BOOST_THREAD_DECL mutex |
---|
33 | : private noncopyable |
---|
34 | { |
---|
35 | public: |
---|
36 | friend class detail::thread::lock_ops<mutex>; |
---|
37 | |
---|
38 | typedef detail::thread::scoped_lock<mutex> scoped_lock; |
---|
39 | |
---|
40 | mutex(); |
---|
41 | ~mutex(); |
---|
42 | |
---|
43 | private: |
---|
44 | #if defined(BOOST_HAS_WINTHREADS) |
---|
45 | typedef void* cv_state; |
---|
46 | #elif defined(BOOST_HAS_PTHREADS) |
---|
47 | struct cv_state |
---|
48 | { |
---|
49 | pthread_mutex_t* pmutex; |
---|
50 | }; |
---|
51 | #elif defined(BOOST_HAS_MPTASKS) |
---|
52 | struct cv_state |
---|
53 | { |
---|
54 | }; |
---|
55 | #endif |
---|
56 | void do_lock(); |
---|
57 | void do_unlock(); |
---|
58 | void do_lock(cv_state& state); |
---|
59 | void do_unlock(cv_state& state); |
---|
60 | |
---|
61 | #if defined(BOOST_HAS_WINTHREADS) |
---|
62 | void* m_mutex; |
---|
63 | bool m_critical_section; |
---|
64 | #elif defined(BOOST_HAS_PTHREADS) |
---|
65 | pthread_mutex_t m_mutex; |
---|
66 | #elif defined(BOOST_HAS_MPTASKS) |
---|
67 | threads::mac::detail::scoped_critical_region m_mutex; |
---|
68 | threads::mac::detail::scoped_critical_region m_mutex_mutex; |
---|
69 | #endif |
---|
70 | }; |
---|
71 | |
---|
72 | class BOOST_THREAD_DECL try_mutex |
---|
73 | : private noncopyable |
---|
74 | { |
---|
75 | public: |
---|
76 | friend class detail::thread::lock_ops<try_mutex>; |
---|
77 | |
---|
78 | typedef detail::thread::scoped_lock<try_mutex> scoped_lock; |
---|
79 | typedef detail::thread::scoped_try_lock<try_mutex> scoped_try_lock; |
---|
80 | |
---|
81 | try_mutex(); |
---|
82 | ~try_mutex(); |
---|
83 | |
---|
84 | private: |
---|
85 | #if defined(BOOST_HAS_WINTHREADS) |
---|
86 | typedef void* cv_state; |
---|
87 | #elif defined(BOOST_HAS_PTHREADS) |
---|
88 | struct cv_state |
---|
89 | { |
---|
90 | pthread_mutex_t* pmutex; |
---|
91 | }; |
---|
92 | #elif defined(BOOST_HAS_MPTASKS) |
---|
93 | struct cv_state |
---|
94 | { |
---|
95 | }; |
---|
96 | #endif |
---|
97 | void do_lock(); |
---|
98 | bool do_trylock(); |
---|
99 | void do_unlock(); |
---|
100 | void do_lock(cv_state& state); |
---|
101 | void do_unlock(cv_state& state); |
---|
102 | |
---|
103 | #if defined(BOOST_HAS_WINTHREADS) |
---|
104 | void* m_mutex; |
---|
105 | bool m_critical_section; |
---|
106 | #elif defined(BOOST_HAS_PTHREADS) |
---|
107 | pthread_mutex_t m_mutex; |
---|
108 | #elif defined(BOOST_HAS_MPTASKS) |
---|
109 | threads::mac::detail::scoped_critical_region m_mutex; |
---|
110 | threads::mac::detail::scoped_critical_region m_mutex_mutex; |
---|
111 | #endif |
---|
112 | }; |
---|
113 | |
---|
114 | class BOOST_THREAD_DECL timed_mutex |
---|
115 | : private noncopyable |
---|
116 | { |
---|
117 | public: |
---|
118 | friend class detail::thread::lock_ops<timed_mutex>; |
---|
119 | |
---|
120 | typedef detail::thread::scoped_lock<timed_mutex> scoped_lock; |
---|
121 | typedef detail::thread::scoped_try_lock<timed_mutex> scoped_try_lock; |
---|
122 | typedef detail::thread::scoped_timed_lock<timed_mutex> scoped_timed_lock; |
---|
123 | |
---|
124 | timed_mutex(); |
---|
125 | ~timed_mutex(); |
---|
126 | |
---|
127 | private: |
---|
128 | #if defined(BOOST_HAS_WINTHREADS) |
---|
129 | typedef void* cv_state; |
---|
130 | #elif defined(BOOST_HAS_PTHREADS) |
---|
131 | struct cv_state |
---|
132 | { |
---|
133 | pthread_mutex_t* pmutex; |
---|
134 | }; |
---|
135 | #elif defined(BOOST_HAS_MPTASKS) |
---|
136 | struct cv_state |
---|
137 | { |
---|
138 | }; |
---|
139 | #endif |
---|
140 | void do_lock(); |
---|
141 | bool do_trylock(); |
---|
142 | bool do_timedlock(const xtime& xt); |
---|
143 | void do_unlock(); |
---|
144 | void do_lock(cv_state& state); |
---|
145 | void do_unlock(cv_state& state); |
---|
146 | |
---|
147 | #if defined(BOOST_HAS_WINTHREADS) |
---|
148 | void* m_mutex; |
---|
149 | #elif defined(BOOST_HAS_PTHREADS) |
---|
150 | pthread_mutex_t m_mutex; |
---|
151 | pthread_cond_t m_condition; |
---|
152 | bool m_locked; |
---|
153 | #elif defined(BOOST_HAS_MPTASKS) |
---|
154 | threads::mac::detail::scoped_critical_region m_mutex; |
---|
155 | threads::mac::detail::scoped_critical_region m_mutex_mutex; |
---|
156 | #endif |
---|
157 | }; |
---|
158 | |
---|
159 | } // namespace boost |
---|
160 | |
---|
161 | // Change Log: |
---|
162 | // 8 Feb 01 WEKEMPF Initial version. |
---|
163 | // 22 May 01 WEKEMPF Modified to use xtime for time outs. Factored out |
---|
164 | // to three classes, mutex, try_mutex and timed_mutex. |
---|
165 | // 3 Jan 03 WEKEMPF Modified for DLL implementation. |
---|
166 | |
---|
167 | #endif // BOOST_MUTEX_WEK070601_HPP |
---|