From: khizmax Date: Sat, 31 Jan 2015 14:38:07 +0000 (+0300) Subject: Added sync::injected_monitor X-Git-Tag: v2.1.0~305^2~87 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=055a05a6ec9551d07716c54cd88c071565dd6f9e;p=libcds.git Added sync::injected_monitor --- diff --git a/cds/sync/injected_monitor.h b/cds/sync/injected_monitor.h index 063d90c1..2e567aac 100644 --- a/cds/sync/injected_monitor.h +++ b/cds/sync/injected_monitor.h @@ -14,49 +14,63 @@ namespace cds { namespace sync { class injected_monitor { public: - typedef Lock lock_type; + typedef Lock lock_type; ///< Lock type + /// Monitor injection into \p T template struct wrapper : public T { using T::T; - mutable lock_type m_Lock; + mutable lock_type m_Lock; ///< Node-level lock + /// Makes exclusive access to the object void lock() const { m_Lock.lock; } + /// Unlocks the object void unlock() const { m_Lock.unlock(); } }; + /// Makes exclusive access to node \p p of type \p T + /** + \p p must have method \p lock() + */ template void lock( T const& p ) const { p.lock(); } + /// Unlocks the node \p p of type \p T + /** + \p p must have method \p unlock() + */ template void unlock( T const& p ) const { p.unlock(); } + /// Scoped lock template class scoped_lock { T const& m_Locked; public: + /// Makes exclusive access to object \p p of type T scoped_lock( injected_monitor const&, T const& p ) : m_Locked( p ) { p.lock(); } + /// Unlocks the object ~scoped_lock() { p.unlock();