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 {
14 struct injecting_monitor_traits {
20 /// @ref cds_sync_monitor "Monitor" that injects the lock into each node
22 This simple monitor injects the lock object of type \p Lock into each node.
23 The monitor is designed for user-space locking primitives like \ref sync::spin_lock "spin-lock".
26 - Lock - lock type like \p std::mutex or \p cds::sync::spin
28 template <typename Lock>
29 class injecting_monitor
32 typedef Lock lock_type; ///< Lock type
35 struct node_injection {
36 mutable lock_type m_Lock; ///< Node spin-lock
39 CDS_CONSTEXPR bool check_free() const
46 /// Makes exclusive access to node \p p
47 template <typename Node>
48 void lock( Node const& p ) const
50 p.m_SyncMonitorInjection.m_Lock.lock();
53 /// Unlocks the node \p p
54 template <typename Node>
55 void unlock( Node const& p ) const
57 p.m_SyncMonitorInjection.m_Lock.unlock();
61 injecting_monitor_traits::empty_stat statistics() const
63 return injecting_monitor_traits::empty_stat();
68 template <typename Node>
69 using scoped_lock = monitor_scoped_lock< injecting_monitor, Node > ;
71 }} // namespace cds::sync
73 #endif // #ifndef CDSLIB_SYNC_INJECTING_MONITOR_H