1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/thread for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_THREAD_POLY_SHARED_LOCKABLE_HPP
12 #define BOOST_THREAD_POLY_SHARED_LOCKABLE_HPP
14 #include <boost/thread/poly_lockable.hpp>
15 #include <boost/chrono/chrono.hpp>
21 //[shared_poly_lockable
22 class shared_poly_lockable: public timed_poly_lockable
25 virtual ~shared_poly_lockable() = 0;
27 virtual void lock_shared() = 0;
28 virtual bool try_lock_shared() = 0;
29 virtual void unlock_shared() = 0;
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)
36 return try_lock_shared_until(chrono::time_point_cast<Clock::time_point>(abs_time));
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)
43 return try_lock_shared_for(chrono::duration_cast<chrono::nanoseconds>(rel_time));
49 // A proper name for shared_poly_lockable, consistent with naming scheme of other polymorphic wrappers
50 typedef shared_poly_lockable poly_shared_lockable;
52 //[upgrade_poly_lockable
53 class upgrade_poly_lockable: public shared_poly_lockable
56 virtual ~upgrade_poly_lockable() = 0;
58 virtual void lock_upgrade() = 0;
59 virtual bool try_lock_upgrade() = 0;
60 virtual void unlock_upgrade() = 0;
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)
67 return try_lock_upgrade_until(chrono::time_point_cast<Clock::time_point>(abs_time));
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)
74 return try_lock_upgrade_for(chrono::duration_cast<chrono::nanoseconds>(rel_time));
77 virtual bool try_unlock_shared_and_lock() = 0;
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)
84 return try_unlock_shared_and_lock_until(chrono::time_point_cast<Clock::time_point>(abs_time));
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)
91 return try_unlock_shared_and_lock_for(chrono::duration_cast<chrono::nanoseconds>(rel_time));
94 virtual void unlock_and_lock_shared() = 0;
95 virtual bool try_unlock_shared_and_lock_upgrade() = 0;
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)
102 return try_unlock_shared_and_lock_upgrade_until(chrono::time_point_cast<Clock::time_point>(abs_time));
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)
109 return try_unlock_shared_and_lock_upgrade_for(chrono::duration_cast<chrono::nanoseconds>(rel_time));
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;
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)
121 return try_unlock_upgrade_and_lock_until(chrono::time_point_cast<Clock::time_point>(abs_time));
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)
128 return try_unlock_upgrade_and_lock_for(chrono::duration_cast<chrono::nanoseconds>(rel_time));
131 virtual void unlock_upgrade_and_lock_shared() = 0;
136 // A proper name for upgrade_poly_lockable, consistent with naming scheme of other polymorphic wrappers
137 typedef upgrade_poly_lockable poly_upgrade_lockable;