3 #ifndef CDSLIB_SYNC_INJECTING_MONITOR_H
4 #define CDSLIB_SYNC_INJECTING_MONITOR_H
6 #include <cds/sync/monitor.h>
8 namespace cds { namespace sync {
10 /// @ref cds_sync_monitor "Monitor" that injects the lock into each node
12 This monitor injects the lock object of type \p Lock into each node.
13 The monitor is designed for user-space locking primitives like \ref sync::spin_lock "spin-lock".
16 - Lock - lock type like \p std::mutex or \p cds::sync::spin
18 template <typename Lock>
19 class injecting_monitor
22 typedef Lock lock_type; ///< Lock type
24 /// Monitor injection into \p Node
25 template <typename Node>
26 struct node_wrapper : public Node
29 mutable lock_type m_Lock; ///< Node-level lock
31 /// Makes exclusive access to the object
37 /// Unlocks the object
44 /// Makes exclusive access to node \p p
46 \p p must have method \p lock()
48 template <typename Node>
49 void lock( Node const& p ) const
54 /// Unlocks the node \p p
56 \p p must have method \p unlock()
58 template <typename Node>
59 void unlock( Node const& p ) const
65 template <typename Node>
68 Node const& m_Locked; ///< Our locked node
71 /// Makes exclusive access to node \p p
72 scoped_lock( injecting_monitor const&, Node const& p )
85 }} // namespace cds::sync
87 #endif // #ifndef CDSLIB_SYNC_INJECTING_MONITOR_H