3 #ifndef CDSLIB_SYNC_INJECTING_MONITOR_H
4 #define CDSLIB_SYNC_INJECTING_MONITOR_H
6 #include <cds/sync/monitor.h>
7 #ifndef CDS_CXX11_INHERITING_CTOR
8 # include <utility> // std::forward
11 namespace cds { namespace sync {
13 /// @ref cds_sync_monitor "Monitor" that injects the lock into each node
15 This monitor injects the lock object of type \p Lock into each node.
16 The monitor is designed for user-space locking primitives like \ref sync::spin_lock "spin-lock".
19 - Lock - lock type like \p std::mutex or \p cds::sync::spin
21 template <typename Lock>
22 class injecting_monitor
25 typedef Lock lock_type; ///< Lock type
27 /// Monitor injection into \p Node
30 # ifdef CDS_CXX11_INHERITING_CTOR
33 // Inheriting ctor emulation
34 template <typename... Args>
35 node_injection( Args&&... args )
36 : Node( std::forward<Args>( args )... )
39 mutable lock_type m_Lock; ///< Node-level lock
41 /// Makes exclusive access to the node
54 /// Makes exclusive access to node \p p
56 \p p must have method \p lock()
58 template <typename Node>
59 void lock( Node const& p ) const
64 /// Unlocks the node \p p
66 \p p must have method \p unlock()
68 template <typename Node>
69 void unlock( Node const& p ) const
75 template <typename Node>
78 Node const& m_Locked; ///< Our locked node
81 /// Makes exclusive access to node \p p
82 scoped_lock( injecting_monitor const&, Node const& p )
95 }} // namespace cds::sync
97 #endif // #ifndef CDSLIB_SYNC_INJECTING_MONITOR_H