File indexing completed on 2025-12-15 10:09:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_THREAD_POLY_LOCKABLE_ADAPTER_HPP
0012 #define BOOST_THREAD_POLY_LOCKABLE_ADAPTER_HPP
0013
0014 #include <boost/thread/poly_lockable.hpp>
0015
0016 namespace boost
0017 {
0018
0019
0020 template <typename Mutex, typename Base=poly_basic_lockable>
0021 class poly_basic_lockable_adapter : public Base
0022 {
0023 public:
0024 typedef Mutex mutex_type;
0025
0026 protected:
0027 mutex_type& mtx() const
0028 {
0029 return mtx_;
0030 }
0031 mutable mutex_type mtx_;
0032 public:
0033
0034 BOOST_THREAD_NO_COPYABLE( poly_basic_lockable_adapter)
0035
0036 poly_basic_lockable_adapter()
0037 {}
0038
0039 void lock()
0040 {
0041 mtx().lock();
0042 }
0043 void unlock()
0044 {
0045 mtx().unlock();
0046 }
0047
0048 };
0049
0050
0051
0052 template <typename Mutex, typename Base=poly_lockable>
0053 class poly_lockable_adapter : public poly_basic_lockable_adapter<Mutex, Base>
0054 {
0055 public:
0056 typedef Mutex mutex_type;
0057
0058 bool try_lock()
0059 {
0060 return this->mtx().try_lock();
0061 }
0062 };
0063
0064
0065
0066 template <typename Mutex, typename Base=poly_timed_lockable>
0067 class poly_timed_lockable_adapter: public poly_lockable_adapter<Mutex, Base>
0068 {
0069 public:
0070 typedef Mutex mutex_type;
0071
0072 bool try_lock_until(chrono::system_clock::time_point const & abs_time)
0073 {
0074 return this->mtx().try_lock_until(abs_time);
0075 }
0076 bool try_lock_until(chrono::steady_clock::time_point const & abs_time)
0077 {
0078 return this->mtx().try_lock_until(abs_time);
0079 }
0080 bool try_lock_for(chrono::nanoseconds const & rel_time)
0081 {
0082 return this->mtx().try_lock_for(rel_time);
0083 }
0084
0085 };
0086
0087
0088 }
0089 #endif