blob: e2b5d6bfd97362ea94efb34eec6bb8b1748e7617 [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
Howard Hinnant83eade62013-03-06 23:30:19190class _LIBCPP_TYPE_VIS recursive_mutex
Howard Hinnantbc8d3f92010-05-11 19:42:16191{
192 pthread_mutex_t __m_;
193
194public:
195 recursive_mutex();
196 ~recursive_mutex();
197
198private:
199 recursive_mutex(const recursive_mutex&); // = delete;
200 recursive_mutex& operator=(const recursive_mutex&); // = delete;
201
202public:
203 void lock();
Howard Hinnant499c61f2012-07-21 16:13:09204 bool try_lock() _NOEXCEPT;
205 void unlock() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16206
207 typedef pthread_mutex_t* native_handle_type;
Howard Hinnantb9af2ea2010-09-22 18:02:38208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16209 native_handle_type native_handle() {return &__m_;}
210};
211
Howard Hinnant83eade62013-03-06 23:30:19212class _LIBCPP_TYPE_VIS timed_mutex
Howard Hinnantbc8d3f92010-05-11 19:42:16213{
214 mutex __m_;
215 condition_variable __cv_;
216 bool __locked_;
217public:
218 timed_mutex();
219 ~timed_mutex();
220
221private:
222 timed_mutex(const timed_mutex&); // = delete;
223 timed_mutex& operator=(const timed_mutex&); // = delete;
224
225public:
226 void lock();
Howard Hinnant499c61f2012-07-21 16:13:09227 bool try_lock() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16228 template <class _Rep, class _Period>
Howard Hinnantb9af2ea2010-09-22 18:02:38229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16230 bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
Howard Hinnantf8f85212010-11-20 19:16:30231 {return try_lock_until(chrono::steady_clock::now() + __d);}
Howard Hinnantbc8d3f92010-05-11 19:42:16232 template <class _Clock, class _Duration>
233 bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
Howard Hinnant499c61f2012-07-21 16:13:09234 void unlock() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16235};
236
237template <class _Clock, class _Duration>
238bool
239timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
240{
241 using namespace chrono;
242 unique_lock<mutex> __lk(__m_);
243 bool no_timeout = _Clock::now() < __t;
244 while (no_timeout && __locked_)
245 no_timeout = __cv_.wait_until(__lk, __t) == cv_status::no_timeout;
246 if (!__locked_)
247 {
248 __locked_ = true;
249 return true;
250 }
251 return false;
252}
253
Howard Hinnant83eade62013-03-06 23:30:19254class _LIBCPP_TYPE_VIS recursive_timed_mutex
Howard Hinnantbc8d3f92010-05-11 19:42:16255{
256 mutex __m_;
257 condition_variable __cv_;
258 size_t __count_;
259 pthread_t __id_;
260public:
261 recursive_timed_mutex();
262 ~recursive_timed_mutex();
263
264private:
265 recursive_timed_mutex(const recursive_timed_mutex&); // = delete;
266 recursive_timed_mutex& operator=(const recursive_timed_mutex&); // = delete;
267
268public:
269 void lock();
Howard Hinnant499c61f2012-07-21 16:13:09270 bool try_lock() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16271 template <class _Rep, class _Period>
Howard Hinnantb9af2ea2010-09-22 18:02:38272 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16273 bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
Howard Hinnantf8f85212010-11-20 19:16:30274 {return try_lock_until(chrono::steady_clock::now() + __d);}
Howard Hinnantbc8d3f92010-05-11 19:42:16275 template <class _Clock, class _Duration>
276 bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
Howard Hinnant499c61f2012-07-21 16:13:09277 void unlock() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16278};
279
280template <class _Clock, class _Duration>
281bool
282recursive_timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
283{
284 using namespace chrono;
285 pthread_t __id = pthread_self();
286 unique_lock<mutex> lk(__m_);
287 if (pthread_equal(__id, __id_))
288 {
289 if (__count_ == numeric_limits<size_t>::max())
290 return false;
291 ++__count_;
292 return true;
293 }
294 bool no_timeout = _Clock::now() < __t;
295 while (no_timeout && __count_ != 0)
296 no_timeout = __cv_.wait_until(lk, __t) == cv_status::no_timeout;
297 if (__count_ == 0)
298 {
299 __count_ = 1;
300 __id_ = __id;
301 return true;
302 }
303 return false;
304}
305
306template <class _L0, class _L1>
307int
308try_lock(_L0& __l0, _L1& __l1)
309{
310 unique_lock<_L0> __u0(__l0, try_to_lock);
311 if (__u0.owns_lock())
312 {
313 if (__l1.try_lock())
314 {
315 __u0.release();
316 return -1;
317 }
318 else
319 return 1;
320 }
321 return 0;
322}
323
324#ifndef _LIBCPP_HAS_NO_VARIADICS
325
326template <class _L0, class _L1, class _L2, class... _L3>
327int
328try_lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3)
329{
330 int __r = 0;
331 unique_lock<_L0> __u0(__l0, try_to_lock);
332 if (__u0.owns_lock())
333 {
334 __r = try_lock(__l1, __l2, __l3...);
335 if (__r == -1)
336 __u0.release();
337 else
338 ++__r;
339 }
340 return __r;
341}
342
Howard Hinnant324bb032010-08-22 00:02:43343#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16344
345template <class _L0, class _L1>
346void
347lock(_L0& __l0, _L1& __l1)
348{
349 while (true)
350 {
351 {
352 unique_lock<_L0> __u0(__l0);
353 if (__l1.try_lock())
354 {
355 __u0.release();
356 break;
357 }
358 }
359 sched_yield();
360 {
361 unique_lock<_L1> __u1(__l1);
362 if (__l0.try_lock())
363 {
364 __u1.release();
365 break;
366 }
367 }
368 sched_yield();
369 }
370}
371
372#ifndef _LIBCPP_HAS_NO_VARIADICS
373
Howard Hinnant6fd4b662011-01-12 22:56:59374template <class _L0, class _L1, class _L2, class ..._L3>
Howard Hinnantbc8d3f92010-05-11 19:42:16375void
Howard Hinnant6fd4b662011-01-12 22:56:59376__lock_first(int __i, _L0& __l0, _L1& __l1, _L2& __l2, _L3& ...__l3)
Howard Hinnantbc8d3f92010-05-11 19:42:16377{
378 while (true)
379 {
380 switch (__i)
381 {
382 case 0:
383 {
384 unique_lock<_L0> __u0(__l0);
Howard Hinnant6fd4b662011-01-12 22:56:59385 __i = try_lock(__l1, __l2, __l3...);
Howard Hinnantbc8d3f92010-05-11 19:42:16386 if (__i == -1)
387 {
388 __u0.release();
389 return;
390 }
391 }
392 ++__i;
393 sched_yield();
394 break;
395 case 1:
396 {
397 unique_lock<_L1> __u1(__l1);
Howard Hinnant6fd4b662011-01-12 22:56:59398 __i = try_lock(__l2, __l3..., __l0);
Howard Hinnantbc8d3f92010-05-11 19:42:16399 if (__i == -1)
400 {
401 __u1.release();
402 return;
403 }
404 }
Howard Hinnant6fd4b662011-01-12 22:56:59405 if (__i == sizeof...(_L3) + 1)
Howard Hinnantbc8d3f92010-05-11 19:42:16406 __i = 0;
407 else
408 __i += 2;
409 sched_yield();
410 break;
411 default:
Howard Hinnant6fd4b662011-01-12 22:56:59412 __lock_first(__i - 2, __l2, __l3..., __l0, __l1);
Howard Hinnantbc8d3f92010-05-11 19:42:16413 return;
414 }
415 }
416}
417
Howard Hinnant6fd4b662011-01-12 22:56:59418template <class _L0, class _L1, class _L2, class ..._L3>
Howard Hinnantb9af2ea2010-09-22 18:02:38419inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16420void
Howard Hinnant6fd4b662011-01-12 22:56:59421lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3& ...__l3)
Howard Hinnantbc8d3f92010-05-11 19:42:16422{
Howard Hinnant6fd4b662011-01-12 22:56:59423 __lock_first(0, __l0, __l1, __l2, __l3...);
Howard Hinnantbc8d3f92010-05-11 19:42:16424}
425
Howard Hinnant324bb032010-08-22 00:02:43426#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16427
Howard Hinnant83eade62013-03-06 23:30:19428struct _LIBCPP_TYPE_VIS once_flag;
Howard Hinnantbc8d3f92010-05-11 19:42:16429
430#ifndef _LIBCPP_HAS_NO_VARIADICS
431
432template<class _Callable, class... _Args>
Howard Hinnant33be35e2012-09-14 00:39:16433_LIBCPP_INLINE_VISIBILITY
434void call_once(once_flag&, _Callable&&, _Args&&...);
Howard Hinnantbc8d3f92010-05-11 19:42:16435
Howard Hinnant324bb032010-08-22 00:02:43436#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16437
438template<class _Callable>
Howard Hinnant33be35e2012-09-14 00:39:16439_LIBCPP_INLINE_VISIBILITY
440void call_once(once_flag&, _Callable);
Howard Hinnantbc8d3f92010-05-11 19:42:16441
Howard Hinnant324bb032010-08-22 00:02:43442#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16443
Howard Hinnant83eade62013-03-06 23:30:19444struct _LIBCPP_TYPE_VIS once_flag
Howard Hinnantbc8d3f92010-05-11 19:42:16445{
Howard Hinnantb9af2ea2010-09-22 18:02:38446 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant499c61f2012-07-21 16:13:09447 _LIBCPP_CONSTEXPR
448 once_flag() _NOEXCEPT : __state_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16449
450private:
451 once_flag(const once_flag&); // = delete;
452 once_flag& operator=(const once_flag&); // = delete;
453
454 unsigned long __state_;
455
456#ifndef _LIBCPP_HAS_NO_VARIADICS
457 template<class _Callable, class... _Args>
458 friend
459 void call_once(once_flag&, _Callable&&, _Args&&...);
Howard Hinnant324bb032010-08-22 00:02:43460#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16461 template<class _Callable>
462 friend
463 void call_once(once_flag&, _Callable);
Howard Hinnant324bb032010-08-22 00:02:43464#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16465};
466
Howard Hinnantad935d52011-05-16 19:05:11467#ifndef _LIBCPP_HAS_NO_VARIADICS
468
Howard Hinnant99968442011-11-29 18:15:50469template <class _Fp>
Howard Hinnantad935d52011-05-16 19:05:11470class __call_once_param
471{
Howard Hinnant99968442011-11-29 18:15:50472 _Fp __f_;
Howard Hinnantad935d52011-05-16 19:05:11473public:
474#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50476 explicit __call_once_param(_Fp&& __f) : __f_(_VSTD::move(__f)) {}
Howard Hinnantad935d52011-05-16 19:05:11477#else
478 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50479 explicit __call_once_param(const _Fp& __f) : __f_(__f) {}
Howard Hinnantad935d52011-05-16 19:05:11480#endif
481
482 _LIBCPP_INLINE_VISIBILITY
483 void operator()()
484 {
Howard Hinnant99968442011-11-29 18:15:50485 typedef typename __make_tuple_indices<tuple_size<_Fp>::value, 1>::type _Index;
Howard Hinnantad935d52011-05-16 19:05:11486 __execute(_Index());
487 }
488
489private:
490 template <size_t ..._Indices>
491 _LIBCPP_INLINE_VISIBILITY
492 void __execute(__tuple_indices<_Indices...>)
493 {
Howard Hinnant0949eed2011-06-30 21:18:19494 __invoke(_VSTD::move(_VSTD::get<0>(__f_)), _VSTD::move(_VSTD::get<_Indices>(__f_))...);
Howard Hinnantad935d52011-05-16 19:05:11495 }
496};
497
498#else
499
Howard Hinnant99968442011-11-29 18:15:50500template <class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16501class __call_once_param
502{
Howard Hinnant99968442011-11-29 18:15:50503 _Fp __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:16504public:
Howard Hinnant73d21a42010-09-04 23:28:19505#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38506 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50507 explicit __call_once_param(_Fp&& __f) : __f_(_VSTD::move(__f)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16508#else
Howard Hinnantb9af2ea2010-09-22 18:02:38509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50510 explicit __call_once_param(const _Fp& __f) : __f_(__f) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16511#endif
512
Howard Hinnantb9af2ea2010-09-22 18:02:38513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16514 void operator()()
515 {
516 __f_();
517 }
518};
519
Howard Hinnantad935d52011-05-16 19:05:11520#endif
521
Howard Hinnant99968442011-11-29 18:15:50522template <class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16523void
524__call_once_proxy(void* __vp)
525{
Howard Hinnant99968442011-11-29 18:15:50526 __call_once_param<_Fp>* __p = static_cast<__call_once_param<_Fp>*>(__vp);
Howard Hinnantbc8d3f92010-05-11 19:42:16527 (*__p)();
528}
529
530void __call_once(volatile unsigned long&, void*, void(*)(void*));
531
532#ifndef _LIBCPP_HAS_NO_VARIADICS
533
534template<class _Callable, class... _Args>
535inline _LIBCPP_INLINE_VISIBILITY
536void
537call_once(once_flag& __flag, _Callable&& __func, _Args&&... __args)
538{
Howard Hinnantec3773c2011-12-01 20:21:04539 if (__flag.__state_ != ~0ul)
Howard Hinnantbc8d3f92010-05-11 19:42:16540 {
Howard Hinnant99968442011-11-29 18:15:50541 typedef tuple<typename decay<_Callable>::type, typename decay<_Args>::type...> _Gp;
542 __call_once_param<_Gp> __p(_Gp(__decay_copy(_VSTD::forward<_Callable>(__func)),
Howard Hinnant0949eed2011-06-30 21:18:19543 __decay_copy(_VSTD::forward<_Args>(__args))...));
Howard Hinnant99968442011-11-29 18:15:50544 __call_once(__flag.__state_, &__p, &__call_once_proxy<_Gp>);
Howard Hinnantbc8d3f92010-05-11 19:42:16545 }
546}
547
Howard Hinnant324bb032010-08-22 00:02:43548#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16549
550template<class _Callable>
551inline _LIBCPP_INLINE_VISIBILITY
552void
553call_once(once_flag& __flag, _Callable __func)
554{
555 if (__flag.__state_ != ~0ul)
556 {
557 __call_once_param<_Callable> __p(__func);
558 __call_once(__flag.__state_, &__p, &__call_once_proxy<_Callable>);
559 }
560}
561
Howard Hinnant324bb032010-08-22 00:02:43562#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16563
564_LIBCPP_END_NAMESPACE_STD
565
566#endif // _LIBCPP_MUTEX