@@ -45,7 +45,7 @@ _LIBCPP_HIDE_FROM_ABI void call_once(once_flag&, const _Callable&);
4545#endif // _LIBCPP_CXX03_LANG
4646
4747struct _LIBCPP_TEMPLATE_VIS once_flag {
48- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR once_flag () _NOEXCEPT : __state_(0 ) {}
48+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR once_flag () _NOEXCEPT : __state_(_Unset ) {}
4949 once_flag (const once_flag&) = delete ;
5050 once_flag& operator =(const once_flag&) = delete ;
5151
@@ -55,6 +55,10 @@ struct _LIBCPP_TEMPLATE_VIS once_flag {
5555 typedef unsigned long _State_type;
5656#endif
5757
58+ static const _State_type _Unset = 0 ;
59+ static const _State_type _Pending = 1 ;
60+ static const _State_type _Complete = ~_State_type (0 );
61+
5862private:
5963 _State_type __state_;
6064
@@ -117,7 +121,7 @@ _LIBCPP_EXPORTED_FROM_ABI void __call_once(volatile once_flag::_State_type&, voi
117121
118122template <class _Callable , class ... _Args>
119123inline _LIBCPP_HIDE_FROM_ABI void call_once (once_flag& __flag, _Callable&& __func, _Args&&... __args) {
120- if (__libcpp_acquire_load (&__flag.__state_ ) != ~ once_flag::_State_type ( 0 ) ) {
124+ if (__libcpp_acquire_load (&__flag.__state_ ) != once_flag::_Complete ) {
121125 typedef tuple<_Callable&&, _Args&&...> _Gp;
122126 _Gp __f (_VSTD::forward<_Callable>(__func), _VSTD::forward<_Args>(__args)...);
123127 __call_once_param<_Gp> __p (__f);
@@ -129,15 +133,15 @@ inline _LIBCPP_HIDE_FROM_ABI void call_once(once_flag& __flag, _Callable&& __fun
129133
130134template <class _Callable >
131135inline _LIBCPP_HIDE_FROM_ABI void call_once (once_flag& __flag, _Callable& __func) {
132- if (__libcpp_acquire_load (&__flag.__state_ ) != ~ once_flag::_State_type ( 0 ) ) {
136+ if (__libcpp_acquire_load (&__flag.__state_ ) != once_flag::_Complete ) {
133137 __call_once_param<_Callable> __p (__func);
134138 std::__call_once (__flag.__state_ , &__p, &__call_once_proxy<_Callable>);
135139 }
136140}
137141
138142template <class _Callable >
139143inline _LIBCPP_HIDE_FROM_ABI void call_once (once_flag& __flag, const _Callable& __func) {
140- if (__libcpp_acquire_load (&__flag.__state_ ) != ~ once_flag::_State_type ( 0 ) ) {
144+ if (__libcpp_acquire_load (&__flag.__state_ ) != once_flag::_Complete ) {
141145 __call_once_param<const _Callable> __p (__func);
142146 std::__call_once (__flag.__state_ , &__p, &__call_once_proxy<const _Callable>);
143147 }
0 commit comments