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_LOCKABLE_ADAPTER_HPP
12 #define BOOST_THREAD_POLY_LOCKABLE_ADAPTER_HPP
14 #include <boost/thread/poly_lockable.hpp>
19 //[poly_basic_lockable_adapter
20 template <typename Mutex, typename Base=poly_basic_lockable>
21 class poly_basic_lockable_adapter : public Base
24 typedef Mutex mutex_type;
27 mutex_type& mtx() const
31 mutable mutex_type mtx_; /*< mutable so that it can be modified by const functions >*/
34 BOOST_THREAD_NO_COPYABLE( poly_basic_lockable_adapter) /*< no copyable >*/
36 poly_basic_lockable_adapter()
51 //[poly_lockable_adapter
52 template <typename Mutex, typename Base=poly_lockable>
53 class poly_lockable_adapter : public poly_basic_lockable_adapter<Mutex, Base>
56 typedef Mutex mutex_type;
60 return this->mtx().try_lock();
65 //[poly_timed_lockable_adapter
66 template <typename Mutex, typename Base=poly_timed_lockable>
67 class poly_timed_lockable_adapter: public poly_lockable_adapter<Mutex, Base>
70 typedef Mutex mutex_type;
72 bool try_lock_until(chrono::system_clock::time_point const & abs_time)
74 return this->mtx().try_lock_until(abs_time);
76 bool try_lock_until(chrono::steady_clock::time_point const & abs_time)
78 return this->mtx().try_lock_until(abs_time);
80 bool try_lock_for(chrono::nanoseconds const & rel_time)
82 return this->mtx().try_lock_for(rel_time);