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_ADAPTER_HPP
12 #define BOOST_THREAD_POLY_SHARED_LOCKABLE_ADAPTER_HPP
14 #include <boost/thread/poly_lockable_adapter.hpp>
15 #include <boost/thread/poly_shared_lockable.hpp>
20 //[shared_lockable_adapter
21 template <typename Mutex, typename Base=poly_shared_lockable>
22 class poly_shared_lockable_adapter: public poly_timed_lockable_adapter<Mutex, Base>
25 typedef Mutex mutex_type;
29 this->mtx().lock_shared();
31 bool try_lock_shared()
33 return this->mtx().try_lock_shared();
37 this->mtx().unlock_shared();
40 bool try_lock_shared_until(chrono::system_clock::time_point const & abs_time)
42 return this->mtx().try_lock_shared_until(abs_time);
44 bool try_lock_shared_until(chrono::steady_clock::time_point const & abs_time)
46 return this->mtx().try_lock_shared_until(abs_time);
48 bool try_lock_shared_for(chrono::nanoseconds const & rel_time)
50 return this->mtx().try_lock_shared_for(rel_time);
57 //[upgrade_lockable_adapter
58 template <typename Mutex, typename Base=poly_shared_lockable>
59 class upgrade_lockable_adapter: public shared_lockable_adapter<Mutex, Base>
62 typedef Mutex mutex_type;
66 this->mtx().lock_upgrade();
69 bool try_lock_upgrade()
71 return this->mtx().try_lock_upgrade();
76 this->mtx().unlock_upgrade();
79 bool try_lock_upgrade_until(chrono::system_clock::time_point const & abs_time)
81 return this->mtx().try_lock_upgrade_until(abs_time);
83 bool try_lock_upgrade_until(chrono::steady_clock::time_point const & abs_time)
85 return this->mtx().try_lock_upgrade_until(abs_time);
87 bool try_lock_upgrade_for(chrono::nanoseconds const & rel_time)
89 return this->mtx().try_lock_upgrade_for(rel_time);
92 bool try_unlock_shared_and_lock()
94 return this->mtx().try_unlock_shared_and_lock();
97 bool try_unlock_shared_and_lock_until(chrono::system_clock::time_point const & abs_time)
99 return this->mtx().try_unlock_shared_and_lock_until(abs_time);
101 bool try_unlock_shared_and_lock_until(chrono::steady_clock::time_point const & abs_time)
103 return this->mtx().try_unlock_shared_and_lock_until(abs_time);
105 template <typename Rep, typename Period>
106 bool try_unlock_shared_and_lock_for(chrono::nanoseconds const & rel_time)
108 return this->mtx().try_unlock_shared_and_lock_for(rel_time);
111 void unlock_and_lock_shared()
113 this->mtx().unlock_and_lock_shared();
116 bool try_unlock_shared_and_lock_upgrade()
118 return this->mtx().try_unlock_shared_and_lock_upgrade();
121 bool try_unlock_shared_and_lock_upgrade_until(chrono::system_clock::time_point const & abs_time)
123 return this->mtx().try_unlock_shared_and_lock_upgrade_until(abs_time);
125 bool try_unlock_shared_and_lock_upgrade_until(chrono::steady_clock::time_point const & abs_time)
127 return this->mtx().try_unlock_shared_and_lock_upgrade_until(abs_time);
129 bool try_unlock_shared_and_lock_upgrade_for(chrono::nanoseconds const & rel_time)
131 return this->mtx().try_unlock_shared_and_lock_upgrade_for(rel_time);
134 void unlock_and_lock_upgrade()
136 this->mtx().unlock_and_lock_upgrade();
139 void unlock_upgrade_and_lock()
141 this->mtx().unlock_upgrade_and_lock();
144 bool try_unlock_upgrade_and_lock()
146 return this->mtx().try_unlock_upgrade_and_lock();
148 bool try_unlock_upgrade_and_lock_until(chrono::system_clock::time_point const & abs_time)
150 return this->mtx().try_unlock_upgrade_and_lock_until(abs_time);
152 bool try_unlock_upgrade_and_lock_until(chrono::steady_clock::time_point const & abs_time)
154 return this->mtx().try_unlock_upgrade_and_lock_until(abs_time);
156 bool try_unlock_upgrade_and_lock_for(chrono::nanoseconds const & rel_time)
158 return this->mtx().try_unlock_upgrade_and_lock_for(rel_time);
161 void unlock_upgrade_and_lock_shared()
163 this->mtx().unlock_upgrade_and_lock_shared();