1 | Index: shared_lock_guard.hpp
|
---|
2 | ===================================================================
|
---|
3 | --- shared_lock_guard.hpp (revision 0)
|
---|
4 | +++ shared_lock_guard.hpp (revision 0)
|
---|
5 | @@ -0,0 +1,59 @@
|
---|
6 | +// Distributed under the Boost Software License, Version 1.0. (See
|
---|
7 | +// accompanying file LICENSE_1_0.txt or copy at
|
---|
8 | +// http://www.boost.org/LICENSE_1_0.txt)
|
---|
9 | +// (C) Copyright 2012 Vicente J. Botet Escriba
|
---|
10 | +
|
---|
11 | +#ifndef BOOST_THREAD_SHARED_LOCK_GUARD_HPP
|
---|
12 | +#define BOOST_THREAD_SHARED_LOCK_GUARD_HPP
|
---|
13 | +#include <boost/thread/detail/config.hpp>
|
---|
14 | +#include <boost/thread/locks.hpp>
|
---|
15 | +
|
---|
16 | +namespace boost
|
---|
17 | +{
|
---|
18 | +
|
---|
19 | + template<typename SharedMutex>
|
---|
20 | + class shared_lock_guard
|
---|
21 | + {
|
---|
22 | + private:
|
---|
23 | + SharedMutex& m;
|
---|
24 | +
|
---|
25 | +#ifndef BOOST_NO_DELETED_FUNCTIONS
|
---|
26 | + public:
|
---|
27 | + shared_lock_guard(shared_lock_guard const&) = delete;
|
---|
28 | + shared_lock_guard& operator=(shared_lock_guard const&) = delete;
|
---|
29 | +#else // BOOST_NO_DELETED_FUNCTIONS
|
---|
30 | + private:
|
---|
31 | + shared_lock_guard(shared_lock_guard&);
|
---|
32 | + shared_lock_guard& operator=(shared_lock_guard&);
|
---|
33 | +#endif // BOOST_NO_DELETED_FUNCTIONS
|
---|
34 | + public:
|
---|
35 | + typedef SharedMutex mutex_type;
|
---|
36 | + explicit shared_lock_guard(SharedMutex& m_):
|
---|
37 | + m(m_)
|
---|
38 | + {
|
---|
39 | + m.lock_shared();
|
---|
40 | + }
|
---|
41 | + shared_lock_guard(SharedMutex& m_,adopt_lock_t):
|
---|
42 | + m(m_)
|
---|
43 | + {}
|
---|
44 | + ~shared_lock_guard()
|
---|
45 | + {
|
---|
46 | + m.unlock_shared();
|
---|
47 | + }
|
---|
48 | + };
|
---|
49 | +
|
---|
50 | +#ifdef BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES
|
---|
51 | +
|
---|
52 | + template<typename T>
|
---|
53 | + struct is_mutex_type<shared_lock_guard<T> >
|
---|
54 | + {
|
---|
55 | + BOOST_STATIC_CONSTANT(bool, value = true);
|
---|
56 | + };
|
---|
57 | +
|
---|
58 | +
|
---|
59 | +#endif
|
---|
60 | +
|
---|
61 | +
|
---|
62 | +}
|
---|
63 | +
|
---|
64 | +#endif // header
|
---|
65 |
|
---|
66 | Property changes on: shared_lock_guard.hpp
|
---|
67 | ___________________________________________________________________
|
---|
68 | Added: svn:mime-type
|
---|
69 | + text/plain
|
---|
70 | Added: svn:keywords
|
---|
71 | + Id
|
---|
72 | Added: svn:eol-style
|
---|
73 | + native
|
---|
74 |
|
---|
75 | Index: ../../libs/thread/doc/changes.qbk
|
---|
76 | ===================================================================
|
---|
77 | --- ../../libs/thread/doc/changes.qbk (revision 77660)
|
---|
78 | +++ ../../libs/thread/doc/changes.qbk (working copy)
|
---|
79 | @@ -14,9 +14,9 @@
|
---|
80 |
|
---|
81 | [/
|
---|
82 | * [@http://svn.boost.org/trac/boost/ticket/1850 #1850] Request for unlock_guard to compliment lock_guard.
|
---|
83 | -* [@http://svn.boost.org/trac/boost/ticket/2637 #2637] Request for shared_mutex duration timed_lock and timed_lock_shared.
|
---|
84 | ]
|
---|
85 |
|
---|
86 | +* [@http://svn.boost.org/trac/boost/ticket/2637 #2637] Request for shared_mutex duration timed_lock and timed_lock_shared.
|
---|
87 | * [@http://svn.boost.org/trac/boost/ticket/2741 #2741] Proposal to manage portable and non portable thread attributes.
|
---|
88 | * [@http://svn.boost.org/trac/boost/ticket/3567 #3567] Request for shared_lock_guard.
|
---|
89 | * [@http://svn.boost.org/trac/boost/ticket/6194 #6194] Adapt to Boost.Move.
|
---|
90 | Index: ../../libs/thread/doc/mutex_concepts.qbk
|
---|
91 | ===================================================================
|
---|
92 | --- ../../libs/thread/doc/mutex_concepts.qbk (revision 77660)
|
---|
93 | +++ ../../libs/thread/doc/mutex_concepts.qbk (working copy)
|
---|
94 | @@ -1524,6 +1524,8 @@
|
---|
95 | [endsect]
|
---|
96 | [endsect]
|
---|
97 |
|
---|
98 | +]
|
---|
99 | +
|
---|
100 | [section:other_locks Other Lock Types]
|
---|
101 |
|
---|
102 |
|
---|
103 | @@ -1591,6 +1593,7 @@
|
---|
104 |
|
---|
105 | [endsect]
|
---|
106 |
|
---|
107 | +[/
|
---|
108 | [section:reverse_lock Class template `reverse_lock`]
|
---|
109 |
|
---|
110 | #include <boost/thread/reverse_lock.hpp>
|
---|
111 | @@ -1639,10 +1642,11 @@
|
---|
112 |
|
---|
113 |
|
---|
114 | [endsect]
|
---|
115 | +]
|
---|
116 |
|
---|
117 | [endsect]
|
---|
118 | -]
|
---|
119 |
|
---|
120 | +
|
---|
121 | [section:lock_functions Lock functions]
|
---|
122 |
|
---|
123 | [section:lock_multiple Non-member function `lock(Lockable1,Lockable2,...)`]
|
---|
124 | Index: ../../libs/thread/test/Jamfile.v2
|
---|
125 | ===================================================================
|
---|
126 | --- ../../libs/thread/test/Jamfile.v2 (revision 77658)
|
---|
127 | +++ ../../libs/thread/test/Jamfile.v2 (working copy)
|
---|
128 | @@ -377,4 +377,14 @@
|
---|
129 | #;
|
---|
130 |
|
---|
131 |
|
---|
132 | + #explicit shared_lock_guard ;
|
---|
133 | + test-suite shared_lock_guard
|
---|
134 | + :
|
---|
135 | + [ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/shared_lock_guard/copy_assign_fail.cpp : : shared_lock_guard__cons__copy_assign_f ]
|
---|
136 | + [ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/shared_lock_guard/copy_ctor_fail.cpp : : shared_lock_guard__cons__copy_ctor_f ]
|
---|
137 | + [ thread-run2 ./sync/mutual_exclusion/locks/shared_lock_guard/adopt_lock_pass.cpp : shared_lock_guard__cons__adopt_lock_p ]
|
---|
138 | + [ thread-run2 ./sync/mutual_exclusion/locks/shared_lock_guard/default_pass.cpp : shared_lock_guard__cons__default_p ]
|
---|
139 | + [ thread-run2 ./sync/mutual_exclusion/locks/shared_lock_guard/types_pass.cpp : shared_lock_guard__types_p ]
|
---|
140 | + ;
|
---|
141 | +
|
---|
142 | }
|
---|
143 | Index: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/adopt_lock_pass.cpp
|
---|
144 | ===================================================================
|
---|
145 | --- ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/adopt_lock_pass.cpp (revision 0)
|
---|
146 | +++ ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/adopt_lock_pass.cpp (revision 0)
|
---|
147 | @@ -0,0 +1,57 @@
|
---|
148 | +//===----------------------------------------------------------------------===//
|
---|
149 | +//
|
---|
150 | +// The LLVM Compiler Infrastructure
|
---|
151 | +//
|
---|
152 | +// This file is dual licensed under the MIT and the University of Illinois Open
|
---|
153 | +// Source Licenses. See LICENSE.TXT for details.
|
---|
154 | +//
|
---|
155 | +//===----------------------------------------------------------------------===//
|
---|
156 | +
|
---|
157 | +// Copyright (C) 2012 Vicente J. Botet Escriba
|
---|
158 | +//
|
---|
159 | +// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
---|
160 | +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
---|
161 | +
|
---|
162 | +// <boost/thread/shared_lock_guard.hpp>
|
---|
163 | +
|
---|
164 | +// template <class Mutex> class shared_lock_guard;
|
---|
165 | +
|
---|
166 | +// shared_lock_guard(mutex_type& m, adopt_lock_t);
|
---|
167 | +
|
---|
168 | +#include <boost/thread/shared_lock_guard.hpp>
|
---|
169 | +#include <boost/thread/shared_mutex.hpp>
|
---|
170 | +#include <boost/thread/thread.hpp>
|
---|
171 | +#include <boost/detail/lightweight_test.hpp>
|
---|
172 | +
|
---|
173 | +typedef boost::chrono::high_resolution_clock Clock;
|
---|
174 | +typedef Clock::time_point time_point;
|
---|
175 | +typedef Clock::duration duration;
|
---|
176 | +typedef boost::chrono::milliseconds ms;
|
---|
177 | +typedef boost::chrono::nanoseconds ns;
|
---|
178 | +
|
---|
179 | +boost::shared_mutex m;
|
---|
180 | +
|
---|
181 | +void f()
|
---|
182 | +{
|
---|
183 | + time_point t0 = Clock::now();
|
---|
184 | + time_point t1;
|
---|
185 | + {
|
---|
186 | + m.lock();
|
---|
187 | + boost::shared_lock_guard<boost::shared_mutex> lg(m, boost::adopt_lock);
|
---|
188 | + t1 = Clock::now();
|
---|
189 | + }
|
---|
190 | + ns d = t1 - t0 - ms(250);
|
---|
191 | + BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
|
---|
192 | +}
|
---|
193 | +
|
---|
194 | +int main()
|
---|
195 | +{
|
---|
196 | + m.lock();
|
---|
197 | + boost::thread t(f);
|
---|
198 | + boost::this_thread::sleep_for(ms(250));
|
---|
199 | + m.unlock();
|
---|
200 | + t.join();
|
---|
201 | +
|
---|
202 | + return boost::report_errors();
|
---|
203 | +}
|
---|
204 | +
|
---|
205 |
|
---|
206 | Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/adopt_lock_pass.cpp
|
---|
207 | ___________________________________________________________________
|
---|
208 | Added: svn:executable
|
---|
209 | + *
|
---|
210 | Added: svn:mime-type
|
---|
211 | + text/plain
|
---|
212 | Added: svn:keywords
|
---|
213 | + Id
|
---|
214 | Added: svn:eol-style
|
---|
215 | + native
|
---|
216 |
|
---|
217 | Index: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_assign_fail.cpp
|
---|
218 | ===================================================================
|
---|
219 | --- ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_assign_fail.cpp (revision 0)
|
---|
220 | +++ ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_assign_fail.cpp (revision 0)
|
---|
221 | @@ -0,0 +1,35 @@
|
---|
222 | +//===----------------------------------------------------------------------===//
|
---|
223 | +//
|
---|
224 | +// The LLVM Compiler Infrastructure
|
---|
225 | +//
|
---|
226 | +// This file is dual licensed under the MIT and the University of Illinois Open
|
---|
227 | +// Source Licenses. See LICENSE.TXT for details.
|
---|
228 | +//
|
---|
229 | +//===----------------------------------------------------------------------===//
|
---|
230 | +
|
---|
231 | +// Copyright (C) 2011 Vicente J. Botet Escriba
|
---|
232 | +//
|
---|
233 | +// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
---|
234 | +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
---|
235 | +
|
---|
236 | +// <boost/thread/shared_lock_guard.hpp>
|
---|
237 | +
|
---|
238 | +// template <class Mutex> class shared_lock_guard;
|
---|
239 | +
|
---|
240 | +// shared_lock_guard& operator=(shared_lock_guard const&) = delete;
|
---|
241 | +
|
---|
242 | +#include <boost/thread/shared_lock_guard.hpp>
|
---|
243 | +#include <boost/thread/shared_mutex.hpp>
|
---|
244 | +#include <boost/detail/lightweight_test.hpp>
|
---|
245 | +
|
---|
246 | +boost::shared_mutex m0;
|
---|
247 | +boost::shared_mutex m1;
|
---|
248 | +
|
---|
249 | +int main()
|
---|
250 | +{
|
---|
251 | + boost::shared_lock_guard<boost::shared_mutex> lk0(m0);
|
---|
252 | + boost::shared_lock_guard<boost::shared_mutex> lk1(m1);
|
---|
253 | + lk1 = lk0;
|
---|
254 | +
|
---|
255 | +}
|
---|
256 | +
|
---|
257 |
|
---|
258 | Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_assign_fail.cpp
|
---|
259 | ___________________________________________________________________
|
---|
260 | Added: svn:executable
|
---|
261 | + *
|
---|
262 | Added: svn:mime-type
|
---|
263 | + text/plain
|
---|
264 | Added: svn:keywords
|
---|
265 | + Id
|
---|
266 | Added: svn:eol-style
|
---|
267 | + native
|
---|
268 |
|
---|
269 | Index: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/default_pass.cpp
|
---|
270 | ===================================================================
|
---|
271 | --- ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/default_pass.cpp (revision 0)
|
---|
272 | +++ ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/default_pass.cpp (revision 0)
|
---|
273 | @@ -0,0 +1,56 @@
|
---|
274 | +//===----------------------------------------------------------------------===//
|
---|
275 | +//
|
---|
276 | +// The LLVM Compiler Infrastructure
|
---|
277 | +//
|
---|
278 | +// This file is dual licensed under the MIT and the University of Illinois Open
|
---|
279 | +// Source Licenses. See LICENSE.TXT for details.
|
---|
280 | +//
|
---|
281 | +//===----------------------------------------------------------------------===//
|
---|
282 | +
|
---|
283 | +// Copyright (C) 2011 Vicente J. Botet Escriba
|
---|
284 | +//
|
---|
285 | +// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
---|
286 | +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
---|
287 | +
|
---|
288 | +// <boost/thread/shared_lock_guard.hpp>
|
---|
289 | +
|
---|
290 | +// template <class Mutex> class shared_lock_guard;
|
---|
291 | +
|
---|
292 | +// shared_lock_guard(shared_lock_guard const&) = delete;
|
---|
293 | +
|
---|
294 | +#include <boost/thread/shared_lock_guard.hpp>
|
---|
295 | +#include <boost/thread/shared_mutex.hpp>
|
---|
296 | +#include <boost/thread/thread.hpp>
|
---|
297 | +#include <boost/detail/lightweight_test.hpp>
|
---|
298 | +
|
---|
299 | +typedef boost::chrono::high_resolution_clock Clock;
|
---|
300 | +typedef Clock::time_point time_point;
|
---|
301 | +typedef Clock::duration duration;
|
---|
302 | +typedef boost::chrono::milliseconds ms;
|
---|
303 | +typedef boost::chrono::nanoseconds ns;
|
---|
304 | +
|
---|
305 | +boost::shared_mutex m;
|
---|
306 | +
|
---|
307 | +void f()
|
---|
308 | +{
|
---|
309 | + time_point t0 = Clock::now();
|
---|
310 | + time_point t1;
|
---|
311 | + {
|
---|
312 | + boost::shared_lock_guard<boost::shared_mutex> lg(m);
|
---|
313 | + t1 = Clock::now();
|
---|
314 | + }
|
---|
315 | + ns d = t1 - t0 - ms(250);
|
---|
316 | + // This test is spurious as it depends on the time the thread system switches the threads
|
---|
317 | + BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
|
---|
318 | +}
|
---|
319 | +
|
---|
320 | +int main()
|
---|
321 | +{
|
---|
322 | + m.lock();
|
---|
323 | + boost::thread t(f);
|
---|
324 | + boost::this_thread::sleep_for(ms(250));
|
---|
325 | + m.unlock();
|
---|
326 | + t.join();
|
---|
327 | +
|
---|
328 | + return boost::report_errors();
|
---|
329 | +}
|
---|
330 |
|
---|
331 | Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/default_pass.cpp
|
---|
332 | ___________________________________________________________________
|
---|
333 | Added: svn:executable
|
---|
334 | + *
|
---|
335 | Added: svn:mime-type
|
---|
336 | + text/plain
|
---|
337 | Added: svn:keywords
|
---|
338 | + Id
|
---|
339 | Added: svn:eol-style
|
---|
340 | + native
|
---|
341 |
|
---|
342 | Index: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/types_pass.cpp
|
---|
343 | ===================================================================
|
---|
344 | --- ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/types_pass.cpp (revision 0)
|
---|
345 | +++ ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/types_pass.cpp (revision 0)
|
---|
346 | @@ -0,0 +1,40 @@
|
---|
347 | +//===----------------------------------------------------------------------===//
|
---|
348 | +//
|
---|
349 | +// The LLVM Compiler Infrastructure
|
---|
350 | +//
|
---|
351 | +// This file is dual licensed under the MIT and the University of Illinois Open
|
---|
352 | +// Source Licenses. See LICENSE.TXT for details.
|
---|
353 | +//
|
---|
354 | +//===----------------------------------------------------------------------===//
|
---|
355 | +
|
---|
356 | +// Copyright (C) 2012 Vicente J. Botet Escriba
|
---|
357 | +//
|
---|
358 | +// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
---|
359 | +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
---|
360 | +
|
---|
361 | +// <boost/thread/shared_lock_guard.hpp>
|
---|
362 | +
|
---|
363 | +// <mutex>
|
---|
364 | +
|
---|
365 | +// template <class Mutex>
|
---|
366 | +// class shared_lock_guard
|
---|
367 | +// {
|
---|
368 | +// public:
|
---|
369 | +// typedef Mutex mutex_type;
|
---|
370 | +// ...
|
---|
371 | +// };
|
---|
372 | +
|
---|
373 | +
|
---|
374 | +#include <boost/thread/shared_mutex.hpp>
|
---|
375 | +#include <boost/thread/shared_lock_guard.hpp>
|
---|
376 | +#include <boost/static_assert.hpp>
|
---|
377 | +#include <boost/detail/lightweight_test.hpp>
|
---|
378 | +
|
---|
379 | +int main()
|
---|
380 | +{
|
---|
381 | + BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::shared_lock_guard<boost::shared_mutex>::mutex_type,
|
---|
382 | + boost::shared_mutex>::value), "");
|
---|
383 | +
|
---|
384 | + return boost::report_errors();
|
---|
385 | +}
|
---|
386 | +
|
---|
387 |
|
---|
388 | Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/types_pass.cpp
|
---|
389 | ___________________________________________________________________
|
---|
390 | Added: svn:executable
|
---|
391 | + *
|
---|
392 | Added: svn:mime-type
|
---|
393 | + text/plain
|
---|
394 | Added: svn:keywords
|
---|
395 | + Id
|
---|
396 | Added: svn:eol-style
|
---|
397 | + native
|
---|
398 |
|
---|
399 | Index: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_ctor_fail.cpp
|
---|
400 | ===================================================================
|
---|
401 | --- ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_ctor_fail.cpp (revision 0)
|
---|
402 | +++ ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_ctor_fail.cpp (revision 0)
|
---|
403 | @@ -0,0 +1,34 @@
|
---|
404 | +//===----------------------------------------------------------------------===//
|
---|
405 | +//
|
---|
406 | +// The LLVM Compiler Infrastructure
|
---|
407 | +//
|
---|
408 | +// This file is dual licensed under the MIT and the University of Illinois Open
|
---|
409 | +// Source Licenses. See LICENSE.TXT for details.
|
---|
410 | +//
|
---|
411 | +//===----------------------------------------------------------------------===//
|
---|
412 | +
|
---|
413 | +// Copyright (C) 2011 Vicente J. Botet Escriba
|
---|
414 | +//
|
---|
415 | +// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
---|
416 | +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
---|
417 | +
|
---|
418 | +// <boost/thread/shared_lock_guard.hpp>
|
---|
419 | +
|
---|
420 | +// template <class Mutex> class shared_lock_guard;
|
---|
421 | +
|
---|
422 | +// shared_lock_guard(shared_lock_guard const&) = delete;
|
---|
423 | +
|
---|
424 | +
|
---|
425 | +#include <boost/thread/shared_lock_guard.hpp>
|
---|
426 | +#include <boost/thread/shared_mutex.hpp>
|
---|
427 | +#include <boost/detail/lightweight_test.hpp>
|
---|
428 | +
|
---|
429 | +boost::shared_mutex m0;
|
---|
430 | +boost::shared_mutex m1;
|
---|
431 | +
|
---|
432 | +int main()
|
---|
433 | +{
|
---|
434 | + boost::shared_lock_guard<boost::shared_mutex> lk0(m0);
|
---|
435 | + boost::shared_lock_guard<boost::shared_mutex> lk1 = lk0;
|
---|
436 | +}
|
---|
437 | +
|
---|
438 |
|
---|
439 | Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/shared_lock_guard/copy_ctor_fail.cpp
|
---|
440 | ___________________________________________________________________
|
---|
441 | Added: svn:executable
|
---|
442 | + *
|
---|
443 | Added: svn:mime-type
|
---|
444 | + text/plain
|
---|
445 | Added: svn:keywords
|
---|
446 | + Id
|
---|
447 | Added: svn:eol-style
|
---|
448 | + native
|
---|
449 |
|
---|