• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[/
2  (C) Copyright 2007-8 Anthony Williams.
3  (C) Copyright 2013 Oliver Kowalke.
4  Distributed under the Boost Software License, Version 1.0.
5  (See accompanying file LICENSE_1_0.txt or copy at
6  http://www.boost.org/LICENSE_1_0.txt).
7]
8
9[section:mutex_types Mutex Types]
10
11[class_heading mutex]
12
13        #include <boost/fiber/mutex.hpp>
14
15        namespace boost {
16        namespace fibers {
17
18        class mutex {
19        public:
20            mutex();
21            ~mutex();
22
23            mutex( mutex const& other) = delete;
24            mutex & operator=( mutex const& other) = delete;
25
26            void lock();
27            bool try_lock();
28            void unlock();
29        };
30
31        }}
32
33__mutex__ provides an exclusive-ownership mutex. At most one fiber can own the
34lock on a given instance of __mutex__ at any time. Multiple concurrent calls to
35__lock__, __try_lock__ and __unlock__ shall be permitted.
36
37Any fiber blocked in __lock__ is suspended until the owning fiber releases the
38lock by calling __unlock__.
39
40[member_heading mutex..lock]
41
42        void lock();
43
44[variablelist
45[[Precondition:] [The calling fiber doesn't own the mutex.]]
46[[Effects:] [The current fiber blocks until ownership can be obtained.]]
47[[Throws:] [`lock_error`]]
48[[Error Conditions:] [
49[*resource_deadlock_would_occur]: if `boost::this_fiber::get_id()` already owns the mutex.]]
50]
51
52[member_heading mutex..try_lock]
53
54            bool try_lock();
55
56[variablelist
57[[Precondition:] [The calling fiber doesn't own the mutex.]]
58[[Effects:] [Attempt to obtain ownership for the current fiber without
59blocking.]]
60[[Returns:] [`true` if ownership was obtained for the current fiber, `false`
61otherwise.]]
62[[Throws:] [`lock_error`]]
63[[Error Conditions:] [
64[*resource_deadlock_would_occur]: if `boost::this_fiber::get_id()` already owns the mutex.]]
65]
66
67[member_heading mutex..unlock]
68
69        void unlock();
70
71[variablelist
72[[Precondition:] [The current fiber owns `*this`.]]
73[[Effects:] [Releases a lock on `*this` by the current fiber.]]
74[[Throws:] [`lock_error`]]
75[[Error Conditions:] [
76[*operation_not_permitted]: if `boost::this_fiber::get_id()` does not own the mutex.]]
77]
78
79
80[class_heading timed_mutex]
81
82        #include <boost/fiber/timed_mutex.hpp>
83
84        namespace boost {
85        namespace fibers {
86
87        class timed_mutex {
88        public:
89            timed_mutex();
90            ~timed_mutex();
91
92            timed_mutex( timed_mutex const& other) = delete;
93            timed_mutex & operator=( timed_mutex const& other) = delete;
94
95            void lock();
96            bool try_lock();
97            void unlock();
98
99            template< typename Clock, typename Duration >
100            bool try_lock_until( std::chrono::time_point< Clock, Duration > const& timeout_time);
101            template< typename Rep, typename Period >
102            bool try_lock_for( std::chrono::duration< Rep, Period > const& timeout_duration);
103        };
104
105        }}
106
107__timed_mutex__ provides an exclusive-ownership mutex. At most one fiber can own
108the lock on a given instance of __timed_mutex__ at any time. Multiple concurrent
109calls to __lock__, __try_lock__, __try_lock_until__, __try_lock_for__ and
110__unlock__ shall be permitted.
111
112[member_heading timed_mutex..lock]
113
114        void lock();
115
116[variablelist
117[[Precondition:] [The calling fiber doesn't own the mutex.]]
118[[Effects:] [The current fiber blocks until ownership can be obtained.]]
119[[Throws:] [`lock_error`]]
120[[Error Conditions:] [
121[*resource_deadlock_would_occur]: if `boost::this_fiber::get_id()` already owns the mutex.]]
122]
123
124[member_heading timed_mutex..try_lock]
125
126        bool try_lock();
127
128[variablelist
129[[Precondition:] [The calling fiber doesn't own the mutex.]]
130[[Effects:] [Attempt to obtain ownership for the current fiber without
131blocking.]]
132[[Returns:] [`true` if ownership was obtained for the current fiber, `false`
133otherwise.]]
134[[Throws:] [`lock_error`]]
135[[Error Conditions:] [
136[*resource_deadlock_would_occur]: if `boost::this_fiber::get_id()` already owns the mutex.]]
137]
138
139[member_heading timed_mutex..unlock]
140
141        void unlock();
142
143[variablelist
144[[Precondition:] [The current fiber owns `*this`.]]
145[[Effects:] [Releases a lock on `*this` by the current fiber.]]
146[[Throws:] [`lock_error`]]
147[[Error Conditions:] [
148[*operation_not_permitted]: if `boost::this_fiber::get_id()` does not own the mutex.]]
149]
150
151[template_member_heading timed_mutex..try_lock_until]
152
153        template< typename Clock, typename Duration >
154        bool try_lock_until( std::chrono::time_point< Clock, Duration > const& timeout_time);
155
156[variablelist
157[[Precondition:] [The calling fiber doesn't own the mutex.]]
158[[Effects:] [Attempt to obtain ownership for the current fiber. Blocks until
159ownership can be obtained, or the specified time is reached. If the specified
160time has already passed, behaves as [member_link timed_mutex..try_lock].]]
161[[Returns:] [`true` if ownership was obtained for the current fiber, `false`
162otherwise.]]
163[[Throws:] [`lock_error`, timeout-related exceptions.]]
164[[Error Conditions:] [
165[*resource_deadlock_would_occur]: if `boost::this_fiber::get_id()` already owns the mutex.]]
166]
167
168[template_member_heading timed_mutex..try_lock_for]
169
170        template< typename Rep, typename Period >
171        bool try_lock_for( std::chrono::duration< Rep, Period > const& timeout_duration);
172
173[variablelist
174[[Precondition:] [The calling fiber doesn't own the mutex.]]
175[[Effects:] [Attempt to obtain ownership for the current fiber. Blocks until
176ownership can be obtained, or the specified time is reached. If the specified
177time has already passed, behaves as [member_link timed_mutex..try_lock].]]
178[[Returns:] [`true` if ownership was obtained for the current fiber, `false`
179otherwise.]]
180[[Throws:] [`lock_error`, timeout-related exceptions.]]
181[[Error Conditions:] [
182[*resource_deadlock_would_occur]: if `boost::this_fiber::get_id()` already owns the mutex.]]
183]
184
185
186[class_heading recursive_mutex]
187
188        #include <boost/fiber/recursive_mutex.hpp>
189
190        namespace boost {
191        namespace fibers {
192
193        class recursive_mutex {
194        public:
195            recursive_mutex();
196            ~recursive_mutex();
197
198            recursive_mutex( recursive_mutex const& other) = delete;
199            recursive_mutex & operator=( recursive_mutex const& other) = delete;
200
201            void lock();
202            bool try_lock() noexcept;
203            void unlock();
204        };
205
206        }}
207
208__recursive_mutex__ provides an exclusive-ownership recursive mutex. At most one
209fiber can own the lock on a given instance of __recursive_mutex__ at any time.
210Multiple concurrent calls to __lock__, __try_lock__ and __unlock__ shall be
211permitted. A fiber that already has exclusive ownership of a given
212__recursive_mutex__ instance can call __lock__ or __try_lock__ to acquire an
213additional level of ownership of the mutex. __unlock__ must be called once for
214each level of ownership acquired by a single fiber before ownership can be
215acquired by another fiber.
216
217[member_heading recursive_mutex..lock]
218
219        void lock();
220
221[variablelist
222[[Effects:] [The current fiber blocks until ownership can be obtained.]]
223[[Throws:] [Nothing]]
224]
225
226[member_heading recursive_mutex..try_lock]
227
228        bool try_lock() noexcept;
229
230[variablelist
231[[Effects:] [Attempt to obtain ownership for the current fiber without
232blocking.]]
233[[Returns:] [`true` if ownership was obtained for the current fiber, `false`
234otherwise.]]
235[[Throws:] [Nothing.]]
236]
237
238[member_heading recursive_mutex..unlock]
239
240        void unlock();
241
242[variablelist
243[[Effects:] [Releases a lock on `*this` by the current fiber.]]
244[[Throws:] [`lock_error`]]
245[[Error Conditions:] [
246[*operation_not_permitted]: if `boost::this_fiber::get_id()` does not own the mutex.]]
247]
248
249
250[class_heading recursive_timed_mutex]
251
252        #include <boost/fiber/recursive_timed_mutex.hpp>
253
254        namespace boost {
255        namespace fibers {
256
257        class recursive_timed_mutex {
258        public:
259            recursive_timed_mutex();
260            ~recursive_timed_mutex();
261
262            recursive_timed_mutex( recursive_timed_mutex const& other) = delete;
263            recursive_timed_mutex & operator=( recursive_timed_mutex const& other) = delete;
264
265            void lock();
266            bool try_lock() noexcept;
267            void unlock();
268
269            template< typename Clock, typename Duration >
270            bool try_lock_until( std::chrono::time_point< Clock, Duration > const& timeout_time);
271            template< typename Rep, typename Period >
272            bool try_lock_for( std::chrono::duration< Rep, Period > const& timeout_duration);
273        };
274
275        }}
276
277__recursive_timed_mutex__ provides an exclusive-ownership recursive mutex. At
278most one fiber can own the lock on a given instance of
279__recursive_timed_mutex__ at any time. Multiple concurrent calls to __lock__,
280__try_lock__, __try_lock_for__, __try_lock_until__ and __unlock__ shall be
281permitted. A fiber that already has exclusive ownership of a given
282__recursive_timed_mutex__ instance can call __lock__, __try_lock__,
283__try_lock_for__ or __try_lock_until__ to acquire an additional level of
284ownership of the mutex. __unlock__ must be called once for each level of
285ownership acquired by a single fiber before ownership can be acquired by another
286fiber.
287
288[member_heading recursive_timed_mutex..lock]
289
290        void lock();
291
292[variablelist
293[[Effects:] [The current fiber blocks until ownership can be obtained.]]
294[[Throws:] [Nothing]]
295]
296
297[member_heading recursive_timed_mutex..try_lock]
298
299        bool try_lock() noexcept;
300
301[variablelist
302[[Effects:] [Attempt to obtain ownership for the current fiber without
303blocking.]]
304[[Returns:] [`true` if ownership was obtained for the current fiber, `false`
305otherwise.]]
306[[Throws:] [Nothing.]]
307]
308
309[member_heading recursive_timed_mutex..unlock]
310
311        void unlock();
312
313[variablelist
314[[Effects:] [Releases a lock on `*this` by the current fiber.]]
315[[Throws:] [`lock_error`]]
316[[Error Conditions:] [
317[*operation_not_permitted]: if `boost::this_fiber::get_id()` does not own the mutex.]]
318]
319
320[template_member_heading recursive_timed_mutex..try_lock_until]
321
322        template< typename Clock, typename Duration >
323        bool try_lock_until( std::chrono::time_point< Clock, Duration > const& timeout_time);
324
325[variablelist
326[[Effects:] [Attempt to obtain ownership for the current fiber. Blocks until
327ownership can be obtained, or the specified time is reached. If the specified
328time has already passed, behaves as [member_link recursive_timed_mutex..try_lock].]]
329[[Returns:] [`true` if ownership was obtained for the current fiber, `false`
330otherwise.]]
331[[Throws:] [Timeout-related exceptions.]]
332]
333
334[template_member_heading recursive_timed_mutex..try_lock_for]
335
336        template< typename Rep, typename Period >
337        bool try_lock_for( std::chrono::duration< Rep, Period > const& timeout_duration);
338
339[variablelist
340[[Effects:] [Attempt to obtain ownership for the current fiber. Blocks until
341ownership can be obtained, or the specified time is reached. If the specified
342time has already passed, behaves as [member_link recursive_timed_mutex..try_lock].]]
343[[Returns:] [`true` if ownership was obtained for the current fiber, `false`
344otherwise.]]
345[[Throws:] [Timeout-related exceptions.]]
346]
347
348
349[endsect]
350