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 //[poly_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 //[poly_upgrade_lockable_adapter
58 template <typename Mutex, typename Base=poly_shared_lockable>
59 class poly_upgrade_lockable_adapter: public poly_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 bool try_unlock_shared_and_lock_for(chrono::nanoseconds const & rel_time)
107 return this->mtx().try_unlock_shared_and_lock_for(rel_time);
110 void unlock_and_lock_shared()
112 this->mtx().unlock_and_lock_shared();
115 bool try_unlock_shared_and_lock_upgrade()
117 return this->mtx().try_unlock_shared_and_lock_upgrade();
120 bool try_unlock_shared_and_lock_upgrade_until(chrono::system_clock::time_point const & abs_time)
122 return this->mtx().try_unlock_shared_and_lock_upgrade_until(abs_time);
124 bool try_unlock_shared_and_lock_upgrade_until(chrono::steady_clock::time_point const & abs_time)
126 return this->mtx().try_unlock_shared_and_lock_upgrade_until(abs_time);
128 bool try_unlock_shared_and_lock_upgrade_for(chrono::nanoseconds const & rel_time)
130 return this->mtx().try_unlock_shared_and_lock_upgrade_for(rel_time);
133 void unlock_and_lock_upgrade()
135 this->mtx().unlock_and_lock_upgrade();
138 void unlock_upgrade_and_lock()
140 this->mtx().unlock_upgrade_and_lock();
143 bool try_unlock_upgrade_and_lock()
145 return this->mtx().try_unlock_upgrade_and_lock();
147 bool try_unlock_upgrade_and_lock_until(chrono::system_clock::time_point const & abs_time)
149 return this->mtx().try_unlock_upgrade_and_lock_until(abs_time);
151 bool try_unlock_upgrade_and_lock_until(chrono::steady_clock::time_point const & abs_time)
153 return this->mtx().try_unlock_upgrade_and_lock_until(abs_time);
155 bool try_unlock_upgrade_and_lock_for(chrono::nanoseconds const & rel_time)
157 return this->mtx().try_unlock_upgrade_and_lock_for(rel_time);
160 void unlock_upgrade_and_lock_shared()
162 this->mtx().unlock_upgrade_and_lock_shared();