Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion stl/src/xonce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@ _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Execute_once(
once_flag& _Flag, _Execute_once_fp_t _Callback, void* _Pv) noexcept { // wrap Win32 InitOnceExecuteOnce()
static_assert(sizeof(_Flag._Opaque) == sizeof(INIT_ONCE), "invalid size");

// _Execute_once_fp_t and PINIT_ONCE_FN differ in type signature, therefore
// we introduce _Xfg_trampoline which has PINIT_ONCE_FN's type signature and
// calls into _Callback as an _Execute_once_fp_t for XFG compatibility.

PINIT_ONCE_FN _Xfg_trampoline = [](PINIT_ONCE _InitOnce, PVOID _Parameter, PVOID* _Context) {
const auto _Callback = reinterpret_cast<_Execute_once_fp_t>(_Context);
return static_cast<BOOL>(_Callback(_InitOnce, _Parameter, nullptr));
};

return __crtInitOnceExecuteOnce(
reinterpret_cast<PINIT_ONCE>(&_Flag._Opaque), reinterpret_cast<PINIT_ONCE_FN>(_Callback), _Pv, nullptr);
reinterpret_cast<PINIT_ONCE>(&_Flag._Opaque), _Xfg_trampoline, _Pv, reinterpret_cast<PVOID*>(_Callback));
}

[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
Expand Down