From 055a05a6ec9551d07716c54cd88c071565dd6f9e Mon Sep 17 00:00:00 2001 From: khizmax Date: Sat, 31 Jan 2015 17:38:07 +0300 Subject: [PATCH] Added sync::injected_monitor --- cds/sync/injected_monitor.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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(); -- 2.34.1