@@ -45,7 +45,7 @@ _LIBCPP_HIDE_FROM_ABI void call_once(once_flag&, const _Callable&);
45
45
#endif // _LIBCPP_CXX03_LANG
46
46
47
47
struct _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 ) {}
49
49
once_flag (const once_flag&) = delete ;
50
50
once_flag& operator =(const once_flag&) = delete ;
51
51
@@ -55,6 +55,10 @@ struct _LIBCPP_TEMPLATE_VIS once_flag {
55
55
typedef unsigned long _State_type;
56
56
#endif
57
57
58
+ static const _State_type _Unset = 0 ;
59
+ static const _State_type _Pending = 1 ;
60
+ static const _State_type _Complete = ~_State_type (0 );
61
+
58
62
private:
59
63
_State_type __state_;
60
64
@@ -117,7 +121,7 @@ _LIBCPP_EXPORTED_FROM_ABI void __call_once(volatile once_flag::_State_type&, voi
117
121
118
122
template <class _Callable , class ... _Args>
119
123
inline _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 ) {
121
125
typedef tuple<_Callable&&, _Args&&...> _Gp;
122
126
_Gp __f (_VSTD::forward<_Callable>(__func), _VSTD::forward<_Args>(__args)...);
123
127
__call_once_param<_Gp> __p (__f);
@@ -129,15 +133,15 @@ inline _LIBCPP_HIDE_FROM_ABI void call_once(once_flag& __flag, _Callable&& __fun
129
133
130
134
template <class _Callable >
131
135
inline _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 ) {
133
137
__call_once_param<_Callable> __p (__func);
134
138
std::__call_once (__flag.__state_ , &__p, &__call_once_proxy<_Callable>);
135
139
}
136
140
}
137
141
138
142
template <class _Callable >
139
143
inline _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 ) {
141
145
__call_once_param<const _Callable> __p (__func);
142
146
std::__call_once (__flag.__state_ , &__p, &__call_once_proxy<const _Callable>);
143
147
}
0 commit comments