]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // | |
3 | // (C) Copyright Vicente J. Botet Escriba 2008-2009,2012. Distributed under the Boost | |
4 | // Software License, Version 1.0. (See accompanying file | |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | // | |
7 | // See http://www.boost.org/libs/thread for documentation. | |
8 | // | |
9 | ////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef BOOST_THREAD_POLY_LOCKABLE_ADAPTER_HPP | |
12 | #define BOOST_THREAD_POLY_LOCKABLE_ADAPTER_HPP | |
13 | ||
14 | #include <boost/thread/poly_lockable.hpp> | |
15 | ||
16 | namespace boost | |
17 | { | |
18 | ||
19 | //[poly_basic_lockable_adapter | |
20 | template <typename Mutex, typename Base=poly_basic_lockable> | |
21 | class poly_basic_lockable_adapter : public Base | |
22 | { | |
23 | public: | |
24 | typedef Mutex mutex_type; | |
25 | ||
26 | protected: | |
27 | mutex_type& mtx() const | |
28 | { | |
29 | return mtx_; | |
30 | } | |
31 | mutable mutex_type mtx_; /*< mutable so that it can be modified by const functions >*/ | |
32 | public: | |
33 | ||
34 | BOOST_THREAD_NO_COPYABLE( poly_basic_lockable_adapter) /*< no copyable >*/ | |
35 | ||
36 | poly_basic_lockable_adapter() | |
37 | {} | |
38 | ||
39 | void lock() | |
40 | { | |
41 | mtx().lock(); | |
42 | } | |
43 | void unlock() | |
44 | { | |
45 | mtx().unlock(); | |
46 | } | |
47 | ||
48 | }; | |
49 | //] | |
50 | ||
51 | //[poly_lockable_adapter | |
52 | template <typename Mutex, typename Base=poly_lockable> | |
53 | class poly_lockable_adapter : public poly_basic_lockable_adapter<Mutex, Base> | |
54 | { | |
55 | public: | |
56 | typedef Mutex mutex_type; | |
57 | ||
58 | bool try_lock() | |
59 | { | |
60 | return this->mtx().try_lock(); | |
61 | } | |
62 | }; | |
63 | //] | |
64 | ||
65 | //[poly_timed_lockable_adapter | |
66 | template <typename Mutex, typename Base=poly_timed_lockable> | |
67 | class poly_timed_lockable_adapter: public poly_lockable_adapter<Mutex, Base> | |
68 | { | |
69 | public: | |
70 | typedef Mutex mutex_type; | |
71 | ||
72 | bool try_lock_until(chrono::system_clock::time_point const & abs_time) | |
73 | { | |
74 | return this->mtx().try_lock_until(abs_time); | |
75 | } | |
76 | bool try_lock_until(chrono::steady_clock::time_point const & abs_time) | |
77 | { | |
78 | return this->mtx().try_lock_until(abs_time); | |
79 | } | |
80 | bool try_lock_for(chrono::nanoseconds const & rel_time) | |
81 | { | |
82 | return this->mtx().try_lock_for(rel_time); | |
83 | } | |
84 | ||
85 | }; | |
86 | //] | |
87 | ||
88 | } | |
89 | #endif |