Debian Codegraph @

headers/mutex

raw
1 /* Copyright (C) 2015 Povilas Kanapickas <[email protected]>
2
3 This file is part of cppreference-doc
4
5 This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
6 Unported License. To view a copy of this license, visit
7 http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
8 Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
9
10 Permission is granted to copy, distribute and/or modify this document
11 under the terms of the GNU Free Documentation License, Version 1.3 or
12 any later version published by the Free Software Foundation; with no
13 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
14 */
15
16 #ifndef CPPREFERENCE_MUTEX_H
17 #define CPPREFERENCE_MUTEX_H
18
19 #if CPPREFERENCE_STDVER>= 2011
20
21 namespace std {
22
23 struct defer_lock_t { };
24 struct try_to_lock_t { };
25 struct adopt_lock_t { };
26
27 constexpr std::defer_lock_t defer_lock;
28 constexpr std::try_to_lock_t try_to_lock;
29 constexpr std::adopt_lock_t adopt_lock;
30
31 class mutex {
32 public:
33 typedef void* native_handle_type; // actually impl-defined
34
35 constexpr mutex();
36 mutex(const mutex&) = delete;
37 mutex& operator=(const mutex&) = delete;
38
39 ~mutex();
40
41 void lock();
42 bool try_lock();
43 void unlock();
44 native_handle_type native_handle();
45 };
46
47 class recursive_mutex {
48 public:
49 typedef void* native_handle_type; // actually impl-defined
50
51 recursive_mutex();
52 recursive_mutex(const recursive_mutex&) = delete;
53 recursive_mutex& operator=(const recursive_mutex&) = delete;
54
55 ~recursive_mutex();
56
57 void lock();
58 bool try_lock();
59 void unlock();
60 native_handle_type native_handle();
61 };
62
63 class timed_mutex {
64 public:
65 typedef void* native_handle_type; // actually impl-defined
66
67 timed_mutex();
68 timed_mutex(const timed_mutex&) = delete;
69 timed_mutex& operator=(const timed_mutex&) = delete;
70
71 ~timed_mutex();
72
73 void lock();
74 bool try_lock();
75
76 template<class Rep, class Period>
77 bool try_lock_for(const std::chrono::duration<Rep, Period>& timeout_duration);
78
79 template<class Clock, class Duration>
80 bool try_lock_until(const std::chrono::time_point<Clock, Duration>& timeout_time);
81
82 void unlock();
83 native_handle_type native_handle();
84 };
85
86 class recursive_timed_mutex {
87 public:
88 typedef void* native_handle_type; // actually impl-defined
89
90 recursive_timed_mutex();
91 recursive_timed_mutex(const recursive_timed_mutex&) = delete;
92 recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
93
94 ~recursive_timed_mutex();
95
96 void lock();
97 bool try_lock();
98
99 template<class Rep, class Period>
100 bool try_lock_for(const std::chrono::duration<Rep, Period>& timeout_duration);
101
102 template<class Clock, class Duration>
103 bool try_lock_until(const std::chrono::time_point<Clock, Duration>& timeout_time);
104
105 void unlock();
106 native_handle_type native_handle();
107 };
108
109
110 template<class Mutex>
111 class lock_guard {
112 public:
113 typedef Mutex mutex_type;
114
115 explicit lock_guard(mutex_type& m);
116 lock_guard(mutex_type& m, std::adopt_lock_t t);
117 lock_guard(const lock_guard&) = delete;
118 lock_guard& operator=(const lock_guard&) = delete;
119 ~lock_guard();
120 };
121
122 template<class Mutex>
123 class unique_lock {
124 public:
125 typedef Mutex mutex_type;
126
127 unique_lock();
128 unique_lock(unique_lock&& other);
129 explicit unique_lock(mutex_type& m);
130 unique_lock(mutex_type& m, std::defer_lock_t t);
131 unique_lock(mutex_type& m, std::try_to_lock_t t);
132 unique_lock(mutex_type& m, std::adopt_lock_t t);
133
134 template<class Rep, class Period>
135 unique_lock(mutex_type& m,
136 const std::chrono::duration<Rep, Period>& timeout_duration);
137
138 template<class Clock, class Duration>
139 unique_lock(mutex_type& m,
140 const std::chrono::time_point<Clock, Duration>& timeout_time);
141
142 ~unique_lock();
143 unique_lock& operator=(unique_lock&& other);
144
145 void lock();
146 bool try_lock();
147 template<class Rep, class Period>
148 bool try_lock_for(const std::chrono::duration<Rep, Period>& timeout_duration);
149 template<class Clock, class Duration>
150 bool try_lock_until(const std::chrono::time_point<Clock, Duration>& timeout_time);
151 void unlock();
152
153 void swap(unique_lock<Mutex>& other);
154
155 mutex_type* release();
156 mutex_type* mutex() const;
157 bool owns_lock() const;
158 explicit operator bool() const;
159 };
160
161 template<class Mutex>
162 void swap(unique_lock<Mutex>& lhs,
163 unique_lock<Mutex>& rhs);
164
165 class once_flag {
166 public:
167 constexpr once_flag();
168 };
169
170 template<class Lockable1, class Lockable2, class... LockableN>
171 int try_lock(Lockable1& lock1, Lockable2& lock2, LockableN& ... lockn);
172
173 template<class Lockable1, class Lockable2, class... LockableN>
174 void lock(Lockable1& lock1, Lockable2& lock2, LockableN& ... lockn);
175
176 template<class Callable, class... Args>
177 void call_once(std::once_flag& flag, Callable&& f, Args&& ... args);
178
179 } // namespace std
180
181 #endif // CPPREFERENCE_STDVER>= 2011
182
183 #endif // CPPREFERENCE_MUTEX_H