]>
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_SHARED_LOCKABLE_HPP | |
12 | #define BOOST_THREAD_POLY_SHARED_LOCKABLE_HPP | |
13 | ||
14 | #include <boost/thread/poly_lockable.hpp> | |
15 | #include <boost/chrono/chrono.hpp> | |
16 | ||
17 | namespace boost | |
18 | { | |
19 | ||
20 | ||
21 | //[shared_poly_lockable | |
22 | class shared_poly_lockable: public timed_poly_lockable | |
23 | { | |
24 | public: | |
25 | virtual ~shared_poly_lockable() = 0; | |
26 | ||
27 | virtual void lock_shared() = 0; | |
28 | virtual bool try_lock_shared() = 0; | |
29 | virtual void unlock_shared() = 0; | |
30 | ||
31 | virtual bool try_lock_shared_until(chrono::system_clock::time_point const & abs_time)=0; | |
32 | virtual bool try_lock_shared_until(chrono::steady_clock::time_point const & abs_time)=0; | |
33 | template <typename Clock, typename Duration> | |
34 | bool try_lock_shared_until(chrono::time_point<Clock, Duration> const & abs_time) | |
35 | { | |
92f5a8d4 | 36 | return try_lock_shared_until(chrono::time_point_cast<Clock::time_point>(abs_time)); |
7c673cae FG |
37 | } |
38 | ||
39 | virtual bool try_lock_shared_for(chrono::nanoseconds const & relative_time)=0; | |
40 | template <typename Rep, typename Period> | |
41 | bool try_lock_shared_for(chrono::duration<Rep, Period> const & rel_time) | |
42 | { | |
92f5a8d4 | 43 | return try_lock_shared_for(chrono::duration_cast<chrono::nanoseconds>(rel_time)); |
7c673cae FG |
44 | } |
45 | ||
46 | }; | |
7c673cae FG |
47 | //] |
48 | ||
92f5a8d4 TL |
49 | // A proper name for shared_poly_lockable, consistent with naming scheme of other polymorphic wrappers |
50 | typedef shared_poly_lockable poly_shared_lockable; | |
51 | ||
7c673cae FG |
52 | //[upgrade_poly_lockable |
53 | class upgrade_poly_lockable: public shared_poly_lockable | |
54 | { | |
55 | public: | |
56 | virtual ~upgrade_poly_lockable() = 0; | |
57 | ||
58 | virtual void lock_upgrade() = 0; | |
59 | virtual bool try_lock_upgrade() = 0; | |
60 | virtual void unlock_upgrade() = 0; | |
61 | ||
62 | virtual bool try_lock_upgrade_until(chrono::system_clock::time_point const & abs_time)=0; | |
63 | virtual bool try_lock_upgrade_until(chrono::steady_clock::time_point const & abs_time)=0; | |
64 | template <typename Clock, typename Duration> | |
65 | bool try_lock_upgrade_until(chrono::time_point<Clock, Duration> const & abs_time) | |
66 | { | |
92f5a8d4 | 67 | return try_lock_upgrade_until(chrono::time_point_cast<Clock::time_point>(abs_time)); |
7c673cae FG |
68 | } |
69 | ||
70 | virtual bool try_lock_upgrade_for(chrono::nanoseconds const & relative_time)=0; | |
71 | template <typename Rep, typename Period> | |
72 | bool try_lock_upgrade_for(chrono::duration<Rep, Period> const & rel_time) | |
73 | { | |
92f5a8d4 | 74 | return try_lock_upgrade_for(chrono::duration_cast<chrono::nanoseconds>(rel_time)); |
7c673cae FG |
75 | } |
76 | ||
77 | virtual bool try_unlock_shared_and_lock() = 0; | |
78 | ||
79 | virtual bool try_unlock_shared_and_lock_until(chrono::system_clock::time_point const & abs_time)=0; | |
80 | virtual bool try_unlock_shared_and_lock_until(chrono::steady_clock::time_point const & abs_time)=0; | |
81 | template <typename Clock, typename Duration> | |
82 | bool try_unlock_shared_and_lock_until(chrono::time_point<Clock, Duration> const & abs_time) | |
83 | { | |
92f5a8d4 | 84 | return try_unlock_shared_and_lock_until(chrono::time_point_cast<Clock::time_point>(abs_time)); |
7c673cae FG |
85 | } |
86 | ||
87 | virtual bool try_unlock_shared_and_lock_for(chrono::nanoseconds const & relative_time)=0; | |
88 | template <typename Rep, typename Period> | |
89 | bool try_unlock_shared_and_lock_for(chrono::duration<Rep, Period> const & rel_time) | |
90 | { | |
92f5a8d4 | 91 | return try_unlock_shared_and_lock_for(chrono::duration_cast<chrono::nanoseconds>(rel_time)); |
7c673cae FG |
92 | } |
93 | ||
94 | virtual void unlock_and_lock_shared() = 0; | |
95 | virtual bool try_unlock_shared_and_lock_upgrade() = 0; | |
96 | ||
97 | virtual bool try_unlock_shared_and_lock_upgrade_until(chrono::system_clock::time_point const & abs_time)=0; | |
98 | virtual bool try_unlock_shared_and_lock_upgrade_until(chrono::steady_clock::time_point const & abs_time)=0; | |
99 | template <typename Clock, typename Duration> | |
100 | bool try_unlock_shared_and_lock_upgrade_until(chrono::time_point<Clock, Duration> const & abs_time) | |
101 | { | |
92f5a8d4 | 102 | return try_unlock_shared_and_lock_upgrade_until(chrono::time_point_cast<Clock::time_point>(abs_time)); |
7c673cae FG |
103 | } |
104 | ||
105 | virtual bool try_unlock_shared_and_lock_upgrade_for(chrono::nanoseconds const & relative_time)=0; | |
106 | template <typename Rep, typename Period> | |
107 | bool try_unlock_shared_and_lock_upgrade_for(chrono::duration<Rep, Period> const & rel_time) | |
108 | { | |
92f5a8d4 | 109 | return try_unlock_shared_and_lock_upgrade_for(chrono::duration_cast<chrono::nanoseconds>(rel_time)); |
7c673cae FG |
110 | } |
111 | ||
112 | virtual void unlock_and_lock_upgrade() = 0; | |
113 | virtual void unlock_upgrade_and_lock() = 0; | |
114 | virtual bool try_unlock_upgrade_and_lock() = 0; | |
115 | ||
116 | virtual bool try_unlock_upgrade_and_lock_until(chrono::system_clock::time_point const & abs_time)=0; | |
117 | virtual bool try_unlock_upgrade_and_lock_until(chrono::steady_clock::time_point const & abs_time)=0; | |
118 | template <typename Clock, typename Duration> | |
119 | bool try_unlock_upgrade_and_lock_until(chrono::time_point<Clock, Duration> const & abs_time) | |
120 | { | |
92f5a8d4 | 121 | return try_unlock_upgrade_and_lock_until(chrono::time_point_cast<Clock::time_point>(abs_time)); |
7c673cae FG |
122 | } |
123 | ||
124 | virtual bool try_unlock_upgrade_and_lock_for(chrono::nanoseconds const & relative_time)=0; | |
125 | template <typename Rep, typename Period> | |
126 | bool try_unlock_upgrade_and_lock_for(chrono::duration<Rep, Period> const & rel_time) | |
127 | { | |
92f5a8d4 | 128 | return try_unlock_upgrade_and_lock_for(chrono::duration_cast<chrono::nanoseconds>(rel_time)); |
7c673cae FG |
129 | } |
130 | ||
131 | virtual void unlock_upgrade_and_lock_shared() = 0; | |
132 | ||
133 | }; | |
92f5a8d4 | 134 | //] |
7c673cae | 135 | |
92f5a8d4 TL |
136 | // A proper name for upgrade_poly_lockable, consistent with naming scheme of other polymorphic wrappers |
137 | typedef upgrade_poly_lockable poly_upgrade_lockable; | |
7c673cae FG |
138 | } |
139 | #endif |