blob: 9c26356590d36387593385f67eeb56bf768e9d52 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===--------------------------- mutex ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:168//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_MUTEX
12#define _LIBCPP_MUTEX
13
14/*
15 mutex synopsis
16
17namespace std
18{
19
20class mutex
21{
22public:
Howard Hinnant499c61f2012-07-21 16:13:0923 constexpr mutex() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1624 ~mutex();
25
26 mutex(const mutex&) = delete;
27 mutex& operator=(const mutex&) = delete;
28
29 void lock();
30 bool try_lock();
31 void unlock();
32
33 typedef pthread_mutex_t* native_handle_type;
34 native_handle_type native_handle();
35};
36
37class recursive_mutex
38{
39public:
40 recursive_mutex();
41 ~recursive_mutex();
42
43 recursive_mutex(const recursive_mutex&) = delete;
44 recursive_mutex& operator=(const recursive_mutex&) = delete;
45
46 void lock();
Howard Hinnant499c61f2012-07-21 16:13:0947 bool try_lock() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1648 void unlock();
49
50 typedef pthread_mutex_t* native_handle_type;
51 native_handle_type native_handle();
52};
53
54class timed_mutex
55{
56public:
57 timed_mutex();
58 ~timed_mutex();
59
60 timed_mutex(const timed_mutex&) = delete;
61 timed_mutex& operator=(const timed_mutex&) = delete;
62
63 void lock();
64 bool try_lock();
65 template <class Rep, class Period>
66 bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
67 template <class Clock, class Duration>
68 bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
69 void unlock();
70};
71
72class recursive_timed_mutex
73{
74public:
75 recursive_timed_mutex();
76 ~recursive_timed_mutex();
77
78 recursive_timed_mutex(const recursive_timed_mutex&) = delete;
79 recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
80
81 void lock();
Howard Hinnant499c61f2012-07-21 16:13:0982 bool try_lock() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1683 template <class Rep, class Period>
84 bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
85 template <class Clock, class Duration>
86 bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
87 void unlock();
88};
89
90struct defer_lock_t {};
91struct try_to_lock_t {};
92struct adopt_lock_t {};
93
94constexpr defer_lock_t defer_lock{};
95constexpr try_to_lock_t try_to_lock{};
96constexpr adopt_lock_t adopt_lock{};
97
98template <class Mutex>
99class lock_guard
100{
101public:
102 typedef Mutex mutex_type;
103
104 explicit lock_guard(mutex_type& m);
105 lock_guard(mutex_type& m, adopt_lock_t);
106 ~lock_guard();
107
108 lock_guard(lock_guard const&) = delete;
109 lock_guard& operator=(lock_guard const&) = delete;
110};
111
112template <class Mutex>
113class unique_lock
114{
115public:
116 typedef Mutex mutex_type;
Howard Hinnant499c61f2012-07-21 16:13:09117 unique_lock() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16118 explicit unique_lock(mutex_type& m);
Howard Hinnant499c61f2012-07-21 16:13:09119 unique_lock(mutex_type& m, defer_lock_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16120 unique_lock(mutex_type& m, try_to_lock_t);
121 unique_lock(mutex_type& m, adopt_lock_t);
122 template <class Clock, class Duration>
123 unique_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
124 template <class Rep, class Period>
125 unique_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time);
126 ~unique_lock();
127
128 unique_lock(unique_lock const&) = delete;
129 unique_lock& operator=(unique_lock const&) = delete;
130
Howard Hinnant499c61f2012-07-21 16:13:09131 unique_lock(unique_lock&& u) noexcept;
132 unique_lock& operator=(unique_lock&& u) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16133
134 void lock();
135 bool try_lock();
136
137 template <class Rep, class Period>
138 bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
139 template <class Clock, class Duration>
140 bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
141
142 void unlock();
143
Howard Hinnant499c61f2012-07-21 16:13:09144 void swap(unique_lock& u) noexcept;
145 mutex_type* release() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16146
Howard Hinnant499c61f2012-07-21 16:13:09147 bool owns_lock() const noexcept;
148 explicit operator bool () const noexcept;
149 mutex_type* mutex() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16150};
151
152template <class Mutex>
Howard Hinnant499c61f2012-07-21 16:13:09153 void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16154
155template <class L1, class L2, class... L3>
156 int try_lock(L1&, L2&, L3&...);
157template <class L1, class L2, class... L3>
158 void lock(L1&, L2&, L3&...);
159
160struct once_flag
161{
Howard Hinnant499c61f2012-07-21 16:13:09162 constexpr once_flag() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16163
164 once_flag(const once_flag&) = delete;
165 once_flag& operator=(const once_flag&) = delete;
166};
167
168template<class Callable, class ...Args>
169 void call_once(once_flag& flag, Callable&& func, Args&&... args);
170
171} // std
172
173*/
174
175#include <__config>
176#include <__mutex_base>
177#include <functional>
Howard Hinnantad935d52011-05-16 19:05:11178#ifndef _LIBCPP_HAS_NO_VARIADICS
179#include <tuple>
180#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16181
Howard Hinnant66c6f972011-11-29 16:45:27182#include <__undef_min_max>
183
Howard Hinnant08e17472011-10-17 20:05:10184#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16185#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10186#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16187
188_LIBCPP_BEGIN_NAMESPACE_STD
189
Jonathan Roelofs8d86b2e2014-09-05 19:45:05190#ifndef _LIBCPP_HAS_NO_THREADS
191
Howard Hinnant83eade62013-03-06 23:30:19192class _LIBCPP_TYPE_VIS recursive_mutex
Howard Hinnantbc8d3f92010-05-11 19:42:16193{
194 pthread_mutex_t __m_;
195
196public:
197 recursive_mutex();
198 ~recursive_mutex();
199
200private:
201 recursive_mutex(const recursive_mutex&); // = delete;
202 recursive_mutex& operator=(const recursive_mutex&); // = delete;
203
204public:
205 void lock();
Howard Hinnant499c61f2012-07-21 16:13:09206 bool try_lock() _NOEXCEPT;
207 void unlock() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16208
209 typedef pthread_mutex_t* native_handle_type;
Howard Hinnantb9af2ea2010-09-22 18:02:38210 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16211 native_handle_type native_handle() {return &__m_;}
212};
213
Howard Hinnant83eade62013-03-06 23:30:19214class _LIBCPP_TYPE_VIS timed_mutex
Howard Hinnantbc8d3f92010-05-11 19:42:16215{
216 mutex __m_;
217 condition_variable __cv_;
218 bool __locked_;
219public:
220 timed_mutex();
221 ~timed_mutex();
222
223private:
224 timed_mutex(const timed_mutex&); // = delete;
225 timed_mutex& operator=(const timed_mutex&); // = delete;
226
227public:
228 void lock();
Howard Hinnant499c61f2012-07-21 16:13:09229 bool try_lock() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16230 template <class _Rep, class _Period>
Howard Hinnantb9af2ea2010-09-22 18:02:38231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16232 bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
Howard Hinnantf8f85212010-11-20 19:16:30233 {return try_lock_until(chrono::steady_clock::now() + __d);}
Howard Hinnantbc8d3f92010-05-11 19:42:16234 template <class _Clock, class _Duration>
235 bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
Howard Hinnant499c61f2012-07-21 16:13:09236 void unlock() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16237};
238
239template <class _Clock, class _Duration>
240bool
241timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
242{
243 using namespace chrono;
244 unique_lock<mutex> __lk(__m_);
245 bool no_timeout = _Clock::now() < __t;
246 while (no_timeout && __locked_)
247 no_timeout = __cv_.wait_until(__lk, __t) == cv_status::no_timeout;
248 if (!__locked_)
249 {
250 __locked_ = true;
251 return true;
252 }
253 return false;
254}
255
Howard Hinnant83eade62013-03-06 23:30:19256class _LIBCPP_TYPE_VIS recursive_timed_mutex
Howard Hinnantbc8d3f92010-05-11 19:42:16257{
258 mutex __m_;
259 condition_variable __cv_;
260 size_t __count_;
261 pthread_t __id_;
262public:
263 recursive_timed_mutex();
264 ~recursive_timed_mutex();
265
266private:
267 recursive_timed_mutex(const recursive_timed_mutex&); // = delete;
268 recursive_timed_mutex& operator=(const recursive_timed_mutex&); // = delete;
269
270public:
271 void lock();
Howard Hinnant499c61f2012-07-21 16:13:09272 bool try_lock() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16273 template <class _Rep, class _Period>
Howard Hinnantb9af2ea2010-09-22 18:02:38274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16275 bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
Howard Hinnantf8f85212010-11-20 19:16:30276 {return try_lock_until(chrono::steady_clock::now() + __d);}
Howard Hinnantbc8d3f92010-05-11 19:42:16277 template <class _Clock, class _Duration>
278 bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
Howard Hinnant499c61f2012-07-21 16:13:09279 void unlock() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16280};
281
282template <class _Clock, class _Duration>
283bool
284recursive_timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
285{
286 using namespace chrono;
287 pthread_t __id = pthread_self();
288 unique_lock<mutex> lk(__m_);
289 if (pthread_equal(__id, __id_))
290 {
291 if (__count_ == numeric_limits<size_t>::max())
292 return false;
293 ++__count_;
294 return true;
295 }
296 bool no_timeout = _Clock::now() < __t;
297 while (no_timeout && __count_ != 0)
298 no_timeout = __cv_.wait_until(lk, __t) == cv_status::no_timeout;
299 if (__count_ == 0)
300 {
301 __count_ = 1;
302 __id_ = __id;
303 return true;
304 }
305 return false;
306}
307
308template <class _L0, class _L1>
309int
310try_lock(_L0& __l0, _L1& __l1)
311{
312 unique_lock<_L0> __u0(__l0, try_to_lock);
313 if (__u0.owns_lock())
314 {
315 if (__l1.try_lock())
316 {
317 __u0.release();
318 return -1;
319 }
320 else
321 return 1;
322 }
323 return 0;
324}
325
326#ifndef _LIBCPP_HAS_NO_VARIADICS
327
328template <class _L0, class _L1, class _L2, class... _L3>
329int
330try_lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3)
331{
332 int __r = 0;
333 unique_lock<_L0> __u0(__l0, try_to_lock);
334 if (__u0.owns_lock())
335 {
336 __r = try_lock(__l1, __l2, __l3...);
337 if (__r == -1)
338 __u0.release();
339 else
340 ++__r;
341 }
342 return __r;
343}
344
Howard Hinnant324bb032010-08-22 00:02:43345#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16346
347template <class _L0, class _L1>
348void
349lock(_L0& __l0, _L1& __l1)
350{
351 while (true)
352 {
353 {
354 unique_lock<_L0> __u0(__l0);
355 if (__l1.try_lock())
356 {
357 __u0.release();
358 break;
359 }
360 }
361 sched_yield();
362 {
363 unique_lock<_L1> __u1(__l1);
364 if (__l0.try_lock())
365 {
366 __u1.release();
367 break;
368 }
369 }
370 sched_yield();
371 }
372}
373
374#ifndef _LIBCPP_HAS_NO_VARIADICS
375
Howard Hinnant6fd4b662011-01-12 22:56:59376template <class _L0, class _L1, class _L2, class ..._L3>
Howard Hinnantbc8d3f92010-05-11 19:42:16377void
Howard Hinnant6fd4b662011-01-12 22:56:59378__lock_first(int __i, _L0& __l0, _L1& __l1, _L2& __l2, _L3& ...__l3)
Howard Hinnantbc8d3f92010-05-11 19:42:16379{
380 while (true)
381 {
382 switch (__i)
383 {
384 case 0:
385 {
386 unique_lock<_L0> __u0(__l0);
Howard Hinnant6fd4b662011-01-12 22:56:59387 __i = try_lock(__l1, __l2, __l3...);
Howard Hinnantbc8d3f92010-05-11 19:42:16388 if (__i == -1)
389 {
390 __u0.release();
391 return;
392 }
393 }
394 ++__i;
395 sched_yield();
396 break;
397 case 1:
398 {
399 unique_lock<_L1> __u1(__l1);
Howard Hinnant6fd4b662011-01-12 22:56:59400 __i = try_lock(__l2, __l3..., __l0);
Howard Hinnantbc8d3f92010-05-11 19:42:16401 if (__i == -1)
402 {
403 __u1.release();
404 return;
405 }
406 }
Howard Hinnant6fd4b662011-01-12 22:56:59407 if (__i == sizeof...(_L3) + 1)
Howard Hinnantbc8d3f92010-05-11 19:42:16408 __i = 0;
409 else
410 __i += 2;
411 sched_yield();
412 break;
413 default:
Howard Hinnant6fd4b662011-01-12 22:56:59414 __lock_first(__i - 2, __l2, __l3..., __l0, __l1);
Howard Hinnantbc8d3f92010-05-11 19:42:16415 return;
416 }
417 }
418}
419
Howard Hinnant6fd4b662011-01-12 22:56:59420template <class _L0, class _L1, class _L2, class ..._L3>
Howard Hinnantb9af2ea2010-09-22 18:02:38421inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16422void
Howard Hinnant6fd4b662011-01-12 22:56:59423lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3& ...__l3)
Howard Hinnantbc8d3f92010-05-11 19:42:16424{
Howard Hinnant6fd4b662011-01-12 22:56:59425 __lock_first(0, __l0, __l1, __l2, __l3...);
Howard Hinnantbc8d3f92010-05-11 19:42:16426}
427
Howard Hinnant324bb032010-08-22 00:02:43428#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16429
Jonathan Roelofs8d86b2e2014-09-05 19:45:05430#endif // !_LIBCPP_HAS_NO_THREADS
431
Marshall Clow05d116e2014-07-29 21:05:31432struct _LIBCPP_TYPE_VIS_ONLY once_flag;
Howard Hinnantbc8d3f92010-05-11 19:42:16433
434#ifndef _LIBCPP_HAS_NO_VARIADICS
435
436template<class _Callable, class... _Args>
Howard Hinnant33be35e2012-09-14 00:39:16437_LIBCPP_INLINE_VISIBILITY
438void call_once(once_flag&, _Callable&&, _Args&&...);
Howard Hinnantbc8d3f92010-05-11 19:42:16439
Howard Hinnant324bb032010-08-22 00:02:43440#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16441
442template<class _Callable>
Howard Hinnant33be35e2012-09-14 00:39:16443_LIBCPP_INLINE_VISIBILITY
444void call_once(once_flag&, _Callable);
Howard Hinnantbc8d3f92010-05-11 19:42:16445
Howard Hinnant324bb032010-08-22 00:02:43446#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16447
Howard Hinnant0f678bd2013-08-12 18:38:34448struct _LIBCPP_TYPE_VIS_ONLY once_flag
Howard Hinnantbc8d3f92010-05-11 19:42:16449{
Howard Hinnantb9af2ea2010-09-22 18:02:38450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant499c61f2012-07-21 16:13:09451 _LIBCPP_CONSTEXPR
452 once_flag() _NOEXCEPT : __state_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16453
454private:
455 once_flag(const once_flag&); // = delete;
456 once_flag& operator=(const once_flag&); // = delete;
457
458 unsigned long __state_;
459
460#ifndef _LIBCPP_HAS_NO_VARIADICS
461 template<class _Callable, class... _Args>
462 friend
463 void call_once(once_flag&, _Callable&&, _Args&&...);
Howard Hinnant324bb032010-08-22 00:02:43464#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16465 template<class _Callable>
466 friend
467 void call_once(once_flag&, _Callable);
Howard Hinnant324bb032010-08-22 00:02:43468#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16469};
470
Howard Hinnantad935d52011-05-16 19:05:11471#ifndef _LIBCPP_HAS_NO_VARIADICS
472
Howard Hinnant99968442011-11-29 18:15:50473template <class _Fp>
Howard Hinnantad935d52011-05-16 19:05:11474class __call_once_param
475{
Howard Hinnant99968442011-11-29 18:15:50476 _Fp __f_;
Howard Hinnantad935d52011-05-16 19:05:11477public:
478#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50480 explicit __call_once_param(_Fp&& __f) : __f_(_VSTD::move(__f)) {}
Howard Hinnantad935d52011-05-16 19:05:11481#else
482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50483 explicit __call_once_param(const _Fp& __f) : __f_(__f) {}
Howard Hinnantad935d52011-05-16 19:05:11484#endif
485
486 _LIBCPP_INLINE_VISIBILITY
487 void operator()()
488 {
Howard Hinnant99968442011-11-29 18:15:50489 typedef typename __make_tuple_indices<tuple_size<_Fp>::value, 1>::type _Index;
Howard Hinnantad935d52011-05-16 19:05:11490 __execute(_Index());
491 }
492
493private:
494 template <size_t ..._Indices>
495 _LIBCPP_INLINE_VISIBILITY
496 void __execute(__tuple_indices<_Indices...>)
497 {
Howard Hinnant0949eed2011-06-30 21:18:19498 __invoke(_VSTD::move(_VSTD::get<0>(__f_)), _VSTD::move(_VSTD::get<_Indices>(__f_))...);
Howard Hinnantad935d52011-05-16 19:05:11499 }
500};
501
502#else
503
Howard Hinnant99968442011-11-29 18:15:50504template <class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16505class __call_once_param
506{
Howard Hinnant99968442011-11-29 18:15:50507 _Fp __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:16508public:
Howard Hinnant73d21a42010-09-04 23:28:19509#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50511 explicit __call_once_param(_Fp&& __f) : __f_(_VSTD::move(__f)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16512#else
Howard Hinnantb9af2ea2010-09-22 18:02:38513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50514 explicit __call_once_param(const _Fp& __f) : __f_(__f) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16515#endif
516
Howard Hinnantb9af2ea2010-09-22 18:02:38517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16518 void operator()()
519 {
520 __f_();
521 }
522};
523
Howard Hinnantad935d52011-05-16 19:05:11524#endif
525
Howard Hinnant99968442011-11-29 18:15:50526template <class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16527void
528__call_once_proxy(void* __vp)
529{
Howard Hinnant99968442011-11-29 18:15:50530 __call_once_param<_Fp>* __p = static_cast<__call_once_param<_Fp>*>(__vp);
Howard Hinnantbc8d3f92010-05-11 19:42:16531 (*__p)();
532}
533
Howard Hinnant0f678bd2013-08-12 18:38:34534_LIBCPP_FUNC_VIS void __call_once(volatile unsigned long&, void*, void(*)(void*));
Howard Hinnantbc8d3f92010-05-11 19:42:16535
536#ifndef _LIBCPP_HAS_NO_VARIADICS
537
538template<class _Callable, class... _Args>
539inline _LIBCPP_INLINE_VISIBILITY
540void
541call_once(once_flag& __flag, _Callable&& __func, _Args&&... __args)
542{
Howard Hinnantec3773c2011-12-01 20:21:04543 if (__flag.__state_ != ~0ul)
Howard Hinnantbc8d3f92010-05-11 19:42:16544 {
Howard Hinnant99968442011-11-29 18:15:50545 typedef tuple<typename decay<_Callable>::type, typename decay<_Args>::type...> _Gp;
546 __call_once_param<_Gp> __p(_Gp(__decay_copy(_VSTD::forward<_Callable>(__func)),
Howard Hinnant0949eed2011-06-30 21:18:19547 __decay_copy(_VSTD::forward<_Args>(__args))...));
Howard Hinnant99968442011-11-29 18:15:50548 __call_once(__flag.__state_, &__p, &__call_once_proxy<_Gp>);
Howard Hinnantbc8d3f92010-05-11 19:42:16549 }
550}
551
Howard Hinnant324bb032010-08-22 00:02:43552#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16553
554template<class _Callable>
555inline _LIBCPP_INLINE_VISIBILITY
556void
557call_once(once_flag& __flag, _Callable __func)
558{
559 if (__flag.__state_ != ~0ul)
560 {
561 __call_once_param<_Callable> __p(__func);
562 __call_once(__flag.__state_, &__p, &__call_once_proxy<_Callable>);
563 }
564}
565
Howard Hinnant324bb032010-08-22 00:02:43566#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16567
568_LIBCPP_END_NAMESPACE_STD
569
570#endif // _LIBCPP_MUTEX