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(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(duration_cast<Clock::duration>(rel_time));
50 //[upgrade_poly_lockable
51 class upgrade_poly_lockable: public shared_poly_lockable
54 virtual ~upgrade_poly_lockable() = 0;
56 virtual void lock_upgrade() = 0;
57 virtual bool try_lock_upgrade() = 0;
58 virtual void unlock_upgrade() = 0;
60 virtual bool try_lock_upgrade_until(chrono::system_clock::time_point const & abs_time)=0;
61 virtual bool try_lock_upgrade_until(chrono::steady_clock::time_point const & abs_time)=0;
62 template <typename Clock, typename Duration>
63 bool try_lock_upgrade_until(chrono::time_point<Clock, Duration> const & abs_time)
65 return try_lock_upgrade_until(time_point_cast<Clock::time_point>(abs_time));
68 virtual bool try_lock_upgrade_for(chrono::nanoseconds const & relative_time)=0;
69 template <typename Rep, typename Period>
70 bool try_lock_upgrade_for(chrono::duration<Rep, Period> const & rel_time)
72 return try_lock_upgrade_for(duration_cast<Clock::duration>(rel_time));
75 virtual bool try_unlock_shared_and_lock() = 0;
77 virtual bool try_unlock_shared_and_lock_until(chrono::system_clock::time_point const & abs_time)=0;
78 virtual bool try_unlock_shared_and_lock_until(chrono::steady_clock::time_point const & abs_time)=0;
79 template <typename Clock, typename Duration>
80 bool try_unlock_shared_and_lock_until(chrono::time_point<Clock, Duration> const & abs_time)
82 return try_unlock_shared_and_lock_until(time_point_cast<Clock::time_point>(abs_time));
85 virtual bool try_unlock_shared_and_lock_for(chrono::nanoseconds const & relative_time)=0;
86 template <typename Rep, typename Period>
87 bool try_unlock_shared_and_lock_for(chrono::duration<Rep, Period> const & rel_time)
89 return try_unlock_shared_and_lock_for(duration_cast<Clock::duration>(rel_time));
92 virtual void unlock_and_lock_shared() = 0;
93 virtual bool try_unlock_shared_and_lock_upgrade() = 0;
95 virtual bool try_unlock_shared_and_lock_upgrade_until(chrono::system_clock::time_point const & abs_time)=0;
96 virtual bool try_unlock_shared_and_lock_upgrade_until(chrono::steady_clock::time_point const & abs_time)=0;
97 template <typename Clock, typename Duration>
98 bool try_unlock_shared_and_lock_upgrade_until(chrono::time_point<Clock, Duration> const & abs_time)
100 return try_unlock_shared_and_lock_upgrade_until(time_point_cast<Clock::time_point>(abs_time));
103 virtual bool try_unlock_shared_and_lock_upgrade_for(chrono::nanoseconds const & relative_time)=0;
104 template <typename Rep, typename Period>
105 bool try_unlock_shared_and_lock_upgrade_for(chrono::duration<Rep, Period> const & rel_time)
107 return try_unlock_shared_and_lock_upgrade_for(duration_cast<Clock::duration>(rel_time));
110 virtual void unlock_and_lock_upgrade() = 0;
111 virtual void unlock_upgrade_and_lock() = 0;
112 virtual bool try_unlock_upgrade_and_lock() = 0;
114 virtual bool try_unlock_upgrade_and_lock_until(chrono::system_clock::time_point const & abs_time)=0;
115 virtual bool try_unlock_upgrade_and_lock_until(chrono::steady_clock::time_point const & abs_time)=0;
116 template <typename Clock, typename Duration>
117 bool try_unlock_upgrade_and_lock_until(chrono::time_point<Clock, Duration> const & abs_time)
119 return try_unlock_upgrade_and_lock_until(time_point_cast<Clock::time_point>(abs_time));
122 virtual bool try_unlock_upgrade_and_lock_for(chrono::nanoseconds const & relative_time)=0;
123 template <typename Rep, typename Period>
124 bool try_unlock_upgrade_and_lock_for(chrono::duration<Rep, Period> const & rel_time)
126 return try_unlock_upgrade_and_lock_for(duration_cast<Clock::duration>(rel_time));
129 virtual void unlock_upgrade_and_lock_shared() = 0;