'libstdc++-v3/include/std/mutex:939'
Код: Выделить всё
enum _Bits : int { _Init = 0, _Active = 1, _Done = 2 };
Код: Выделить всё
// RAII helper to call _M_finish.
struct _Active_execution
{
explicit _Active_execution(once_flag& __flag) : _M_flag(__flag) { }
~_Active_execution() { _M_flag._M_finish(_M_returning); }
_Active_execution(const _Active_execution&) = delete;
_Active_execution& operator=(const _Active_execution&) = delete;
once_flag& _M_flag;
bool _M_returning = false;
};
Код: Выделить всё
inline bool
once_flag::_M_passive() const noexcept
{ return _M_once == _Bits::_Done; }
inline bool
once_flag::_M_activate()
{
if (_M_once == _Bits::_Init) [[__likely__]]
{
_M_once = _Bits::_Active;
return true;
}
else if (_M_passive()) // Caller should have checked this already.
return false;
else
__throw_system_error(EDEADLK);
}
inline void
once_flag::_M_finish(bool __returning) noexcept
{ _M_once = __returning ? _Bits::_Done : _Bits::_Init; }
/// Invoke a callable and synchronize with other calls using the same flag
template
inline void
call_once(once_flag& __once, _Callable&& __f, _Args&&... __args)
{
if (__once._M_passive())
return;
else if (__once._M_activate()) //
Подробнее здесь: [url]https://stackoverflow.com/questions/79851546/is-there-a-race-condition-in-gccs-implementation-of-stdcall-once[/url]
Мобильная версия