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 simple 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
28 template <typename Node>
29 struct node_injection: public Node
31 # ifdef CDS_CXX11_INHERITING_CTOR
34 // Inheriting ctor emulation
35 template <typename... Args>
36 node_injection( Args&&... args )
37 : Node( std::forward<Args>( args )... )
40 mutable lock_type m_Lock; ///< Node-level lock
43 /// Makes exclusive access to node \p p
44 template <typename Node>
45 void lock( Node const& p ) const
50 /// Unlocks the node \p p
51 template <typename Node>
52 void unlock( Node const& p ) const
58 template <typename Node>
59 using scoped_lock = monitor_scoped_lock< injecting_monitor, Node > ;
61 }} // namespace cds::sync
63 #endif // #ifndef CDSLIB_SYNC_INJECTING_MONITOR_H