////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Vicente J. Botet Escriba 2008. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/sync for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef __BOOST_SYNC_MAKE_LOCKABLE__HPP #define __BOOST_SYNC_MAKE_LOCKABLE__HPP #include #include "boost/noncopyable.hpp" namespace boost { namespace sync { //[make_exclusive_lockable template class make_exclusive_lockable : private boost::noncopyable { public: typedef Lockable lockable_type; typedef typename scope_tag::type scope; typedef typename category_tag::type category; typedef typename reentrancy_tag::type reentrancy; typedef typename timed_interface_tag::type timed_interface; void lock() {lock_.lock();} void unlock() {lock_.unlock();} bool try_lock() { return lock_.try_lock();} lockable_type* mutex() const { return &lock_; } protected: mutable Lockable lock_; }; //] //[make_share_lockable template class make_share_lockable : public make_exclusive_lockable { public: typedef SharableLock lockable_base_type; void lock_shared() {the_lock().lock_shared();} bool try_lock_shared() {return the_lock().try_lock_shared();} void unlock_shared() {the_lock().unlock_shared();} private: SharableLock& the_lock() {return *static_cast(&this->lock_);} }; //] //[make_upgrade_lockable template class make_upgrade_lockable : public make_share_lockable { public: typedef UpgradableLock lockable_base_type; void lock_upgrade() {the_lock().lock_upgrade();} void unlock_upgrade() {the_lock().unlock_upgrade();} void unlock_upgrade_and_lock() {the_lock().unlock_upgrade_and_lock();} void unlock_and_lock_upgrade() {the_lock().unlock_and_lock_upgrade();} void unlock_and_lock_shared() {the_lock().unlock_and_lock_shared();} void unlock_upgrade_and_lock_shared() {the_lock().unlock_upgrade_and_lock_shared();} private: UpgradableLock& the_lock() {return *static_cast(&this->lock_);} }; //] } } #endif