2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CDSLIB_SYNC_INJECTING_MONITOR_H
32 #define CDSLIB_SYNC_INJECTING_MONITOR_H
34 #include <cds/sync/monitor.h>
35 #ifndef CDS_CXX11_INHERITING_CTOR
36 # include <utility> // std::forward
39 namespace cds { namespace sync {
42 struct injecting_monitor_traits {
48 /// @ref cds_sync_monitor "Monitor" that injects the lock into each node
50 This simple monitor injects the lock object of type \p Lock into each node.
51 The monitor is designed for user-space locking primitives like \ref sync::spin_lock "spin-lock".
54 - Lock - lock type like \p std::mutex or \p cds::sync::spin
56 template <typename Lock>
57 class injecting_monitor
60 typedef Lock lock_type; ///< Lock type
63 struct node_injection {
64 mutable lock_type m_Lock; ///< Node spin-lock
67 CDS_CONSTEXPR bool check_free() const
74 /// Makes exclusive access to node \p p
75 template <typename Node>
76 void lock( Node const& p ) const
78 p.m_SyncMonitorInjection.m_Lock.lock();
81 /// Unlocks the node \p p
82 template <typename Node>
83 void unlock( Node const& p ) const
85 p.m_SyncMonitorInjection.m_Lock.unlock();
89 injecting_monitor_traits::empty_stat statistics() const
91 return injecting_monitor_traits::empty_stat();
96 template <typename Node>
97 using scoped_lock = monitor_scoped_lock< injecting_monitor, Node >;
99 }} // namespace cds::sync
101 #endif // #ifndef CDSLIB_SYNC_INJECTING_MONITOR_H