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
28 struct node_injection {
29 mutable lock_type m_Lock; ///< Node spin-lock
32 /// Makes exclusive access to node \p p
33 template <typename Node>
34 void lock( Node const& p ) const
36 p.m_SyncMonitorInjection.m_Lock.lock();
39 /// Unlocks the node \p p
40 template <typename Node>
41 void unlock( Node const& p ) const
43 p.m_SyncMonitorInjection.m_Lock.unlock();
47 template <typename Node>
48 using scoped_lock = monitor_scoped_lock< injecting_monitor, Node > ;
50 }} // namespace cds::sync
52 #endif // #ifndef CDSLIB_SYNC_INJECTING_MONITOR_H