fixed adding file problem
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / libcds-2.3.2 / cds / sync / injecting_monitor.h
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
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.
18
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.
29 */
30
31 #ifndef CDSLIB_SYNC_INJECTING_MONITOR_H
32 #define CDSLIB_SYNC_INJECTING_MONITOR_H
33
34 #include <cds/sync/monitor.h>
35
36 namespace cds { namespace sync {
37
38     //@cond
39     struct injecting_monitor_traits {
40         struct empty_stat
41         {};
42     };
43     //@endcond
44
45     /// @ref cds_sync_monitor "Monitor" that injects the lock into each node
46     /**
47         This simple monitor injects the lock object of type \p Lock into each node.
48         The monitor is designed for user-space locking primitives like \ref sync::spin_lock "spin-lock".
49
50         Template arguments:
51         - Lock - lock type like \p std::mutex or \p cds::sync::spin
52     */
53     template <typename Lock>
54     class injecting_monitor
55     {
56     public:
57         typedef Lock lock_type; ///< Lock type
58
59         /// Node injection
60         struct node_injection {
61             mutable lock_type m_Lock;   ///< Node spin-lock
62
63             //@cond
64             constexpr bool check_free() const
65             {
66                 return true;
67             }
68             //@endcond
69         };
70
71         /// Makes exclusive access to node \p p
72         template <typename Node>
73         void lock( Node const& p ) const
74         {
75             p.m_SyncMonitorInjection.m_Lock.lock();
76         }
77
78         /// Unlocks the node \p p
79         template <typename Node>
80         void unlock( Node const& p ) const
81         {
82             p.m_SyncMonitorInjection.m_Lock.unlock();
83         }
84
85         //@cond
86         injecting_monitor_traits::empty_stat statistics() const
87         {
88             return injecting_monitor_traits::empty_stat();
89         }
90         //@endcond
91
92         /// Scoped lock
93         template <typename Node>
94         using scoped_lock = monitor_scoped_lock< injecting_monitor, Node >;
95     };
96 }} // namespace cds::sync
97
98 #endif // #ifndef CDSLIB_SYNC_INJECTING_MONITOR_H