1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #ifndef BOOST_THREAD_POLY_LOCKABLE_ADAPTER_HPP
- #define BOOST_THREAD_POLY_LOCKABLE_ADAPTER_HPP
- #include <boost/thread/poly_lockable.hpp>
- namespace boost
- {
-
- template <typename Mutex, typename Base=poly_basic_lockable>
- class poly_basic_lockable_adapter : public Base
- {
- public:
- typedef Mutex mutex_type;
- protected:
- mutex_type& mtx() const
- {
- return mtx_;
- }
- mutable mutex_type mtx_;
- public:
- BOOST_THREAD_NO_COPYABLE( poly_basic_lockable_adapter)
- poly_basic_lockable_adapter()
- {}
- void lock()
- {
- mtx().lock();
- }
- void unlock()
- {
- mtx().unlock();
- }
- };
-
-
- template <typename Mutex, typename Base=poly_lockable>
- class poly_lockable_adapter : public poly_basic_lockable_adapter<Mutex, Base>
- {
- public:
- typedef Mutex mutex_type;
- bool try_lock()
- {
- return this->mtx().try_lock();
- }
- };
-
-
- template <typename Mutex, typename Base=poly_timed_lockable>
- class poly_timed_lockable_adapter: public poly_lockable_adapter<Mutex, Base>
- {
- public:
- typedef Mutex mutex_type;
- bool try_lock_until(chrono::system_clock::time_point const & abs_time)
- {
- return this->mtx().try_lock_until(abs_time);
- }
- bool try_lock_until(chrono::steady_clock::time_point const & abs_time)
- {
- return this->mtx().try_lock_until(abs_time);
- }
- bool try_lock_for(chrono::nanoseconds const & rel_time)
- {
- return this->mtx().try_lock_for(rel_time);
- }
- };
-
- }
- #endif
|