diff --git a/stl/inc/xcall_once.h b/stl/inc/xcall_once.h index 5b9954a0d8..3a99d9bc03 100644 --- a/stl/inc/xcall_once.h +++ b/stl/inc/xcall_once.h @@ -28,15 +28,6 @@ _EXPORT_STD struct once_flag { // opaque data structure for call_once() void* _Opaque; }; -#ifdef _CRTBLD -// Returns BOOL, nonzero to indicate success, zero for failure -using _Execute_once_fp_t = int(__stdcall*)(void*, void*, void**); - -// Returns BOOL, nonzero to indicate success, zero for failure -extern "C++" _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Execute_once( - once_flag& _Flag, _Execute_once_fp_t _Callback, void* _Pv) noexcept; -#endif // _CRTBLD - template union _Immortalizer_impl { // constructs _Ty, never destroys constexpr _Immortalizer_impl() noexcept : _Storage{} {} diff --git a/stl/src/dllmain.cpp b/stl/src/dllmain.cpp index 23968536e8..3b1c647ae2 100644 --- a/stl/src/dllmain.cpp +++ b/stl/src/dllmain.cpp @@ -5,18 +5,6 @@ #include -#ifdef _CRT_APP -// free static resource used by causality -extern "C" void __cdecl __crtCleanupCausalityStaticFactories(); -#endif // defined(_CRT_APP) - -extern "C" BOOL APIENTRY DllMain(HMODULE /* hModule */, DWORD ul_reason_for_call, [[maybe_unused]] LPVOID lpReserved) { - if (ul_reason_for_call == DLL_PROCESS_DETACH) { -#ifdef _CRT_APP - if (lpReserved == nullptr) { // only when the process is not terminating - __crtCleanupCausalityStaticFactories(); - } -#endif // defined(_CRT_APP) - } +extern "C" BOOL APIENTRY DllMain(HMODULE, DWORD, LPVOID) noexcept { return TRUE; } diff --git a/stl/src/excptptr.cpp b/stl/src/excptptr.cpp index b36a2cf699..723666d2cc 100644 --- a/stl/src/excptptr.cpp +++ b/stl/src/excptptr.cpp @@ -68,22 +68,11 @@ namespace { return _Immortalize_impl<_Ty>._Storage; } #else // ^^^ !defined(_M_CEE) / defined(_M_CEE), TRANSITION, VSO-1153256 vvv - template - int __stdcall _Immortalize_impl(void*, void* _Storage_ptr, void**) noexcept { - // adapt True Placement New to _Execute_once - ::new (_Storage_ptr) _Ty(); - return 1; - } - template _Ty& _Immortalize() { // return a reference to an object that will live forever static once_flag _Flag; alignas(_Ty) static unsigned char _Storage[sizeof(_Ty)]; - if (!_Execute_once(_Flag, _Immortalize_impl<_Ty>, &_Storage)) { - // _Execute_once should never fail if the callback never fails - _CSTD abort(); - } - + call_once(_Flag, [&_Storage] { ::new (static_cast(&_Storage)) _Ty(); }); return reinterpret_cast<_Ty&>(_Storage); } #endif // ^^^ !defined(_M_CEE_PURE) && defined(_M_CEE), TRANSITION, VSO-1153256 ^^^ diff --git a/stl/src/ppltasks.cpp b/stl/src/ppltasks.cpp index c0bbdad466..48b9a5d576 100644 --- a/stl/src/ppltasks.cpp +++ b/stl/src/ppltasks.cpp @@ -81,130 +81,6 @@ namespace Concurrency { } // namespace platform -#if defined(_CRT_APP) - using namespace ABI::Windows::Foundation; - using namespace ABI::Windows::Foundation::Diagnostics; - using namespace Microsoft::WRL; - using namespace Microsoft::WRL::Wrappers; - - class AsyncCausalityTracer { - IAsyncCausalityTracerStatics* m_causalityAPIs; - std::once_flag m_stateFlag; - bool m_isSupported; - - public: - IAsyncCausalityTracerStatics* get() const { - return m_causalityAPIs; - } - - AsyncCausalityTracer() : m_causalityAPIs(nullptr), m_isSupported(false) {} - - void release() { - if (m_causalityAPIs) { - APTTYPE aptType; - APTTYPEQUALIFIER aptTypeQualifier; - if (CoGetApartmentType(&aptType, &aptTypeQualifier) == S_OK) { - // Release causality APIs only if current apartment is still RoInitialized - m_causalityAPIs->Release(); - m_causalityAPIs = nullptr; - m_isSupported = false; - } - } - } - - bool isCausalitySupported() { - // TRANSITION, ABI - _Execute_once( - m_stateFlag, - [](void*, void* _This_raw, void**) -> int { - const auto _This = static_cast(_This_raw); - ComPtr causalityAPIs; - if (SUCCEEDED(GetActivationFactory( - HStringReference(RuntimeClass_Windows_Foundation_Diagnostics_AsyncCausalityTracer) - .Get(), - &causalityAPIs))) { - _This->m_causalityAPIs = causalityAPIs.Detach(); - _This->m_isSupported = true; - } - - return 1; - }, - this); - return m_isSupported; - } - }; - AsyncCausalityTracer asyncCausalityTracer; - - // GUID used for identifying causality logs from PPLTask - const GUID PPLTaskCausalityPlatformID = { - 0x7A76B220, 0xA758, 0x4E6E, 0xB0, 0xE0, 0xD7, 0xC6, 0xD7, 0x4A, 0x88, 0xFE}; - - _CRTIMP2 void __thiscall _TaskEventLogger::_LogScheduleTask(bool _IsContinuation) { - if (asyncCausalityTracer.isCausalitySupported()) { - asyncCausalityTracer.get()->TraceOperationCreation(CausalityTraceLevel_Required, - CausalitySource_Library, PPLTaskCausalityPlatformID, reinterpret_cast(_M_task), - HStringReference(_IsContinuation ? L"Concurrency::PPLTask::ScheduleContinuationTask" - : L"Concurrency::PPLTask::ScheduleTask") - .Get(), - 0); - _M_scheduled = true; - } - } - _CRTIMP2 void __thiscall _TaskEventLogger::_LogTaskCompleted() { - if (_M_scheduled) { - AsyncStatus status; - if (_M_task->_IsCompleted()) { - status = AsyncStatus::Completed; - } else if (_M_task->_HasUserException()) { - status = AsyncStatus::Error; - } else { - status = AsyncStatus::Canceled; - } - - if (asyncCausalityTracer.isCausalitySupported()) { - asyncCausalityTracer.get()->TraceOperationCompletion(CausalityTraceLevel_Required, - CausalitySource_Library, PPLTaskCausalityPlatformID, - reinterpret_cast(_M_task), status); - } - } - } - - _CRTIMP2 void __thiscall _TaskEventLogger::_LogCancelTask() { - if (asyncCausalityTracer.isCausalitySupported()) { - asyncCausalityTracer.get()->TraceOperationRelation(CausalityTraceLevel_Important, - CausalitySource_Library, PPLTaskCausalityPlatformID, reinterpret_cast(_M_task), - CausalityRelation_Cancel); - } - } - - _CRTIMP2 void __thiscall _TaskEventLogger::_LogTaskExecutionCompleted() { - if (asyncCausalityTracer.isCausalitySupported()) { - asyncCausalityTracer.get()->TraceSynchronousWorkCompletion(CausalityTraceLevel_Required, - CausalitySource_Library, CausalitySynchronousWork_CompletionNotification); - } - } - - _CRTIMP2 void __thiscall _TaskEventLogger::_LogWorkItemStarted() { - if (asyncCausalityTracer.isCausalitySupported()) { - asyncCausalityTracer.get()->TraceSynchronousWorkStart(CausalityTraceLevel_Required, - CausalitySource_Library, PPLTaskCausalityPlatformID, reinterpret_cast(_M_task), - CausalitySynchronousWork_Execution); - } - } - - _CRTIMP2 void __thiscall _TaskEventLogger::_LogWorkItemCompleted() { - if (asyncCausalityTracer.isCausalitySupported()) { - asyncCausalityTracer.get()->TraceSynchronousWorkCompletion( - CausalityTraceLevel_Required, CausalitySource_Library, CausalitySynchronousWork_Execution); - - asyncCausalityTracer.get()->TraceSynchronousWorkStart(CausalityTraceLevel_Required, - CausalitySource_Library, PPLTaskCausalityPlatformID, reinterpret_cast(_M_task), - CausalitySynchronousWork_CompletionNotification); - _M_taskPostEventStarted = true; - } - } - -#else // ^^^ defined(_CRT_APP) / !defined(_CRT_APP) vvv _CRTIMP2 void __thiscall _TaskEventLogger::_LogScheduleTask(bool) {} _CRTIMP2 void __thiscall _TaskEventLogger::_LogTaskCompleted() {} @@ -216,7 +92,6 @@ namespace Concurrency { _CRTIMP2 void __thiscall _TaskEventLogger::_LogWorkItemStarted() {} _CRTIMP2 void __thiscall _TaskEventLogger::_LogWorkItemCompleted() {} -#endif // ^^^ !defined(_CRT_APP) ^^^ #if defined(_CRT_APP) || defined(UNDOCKED_WINDOWS_UCRT) using namespace ABI::Windows::Foundation; @@ -348,9 +223,3 @@ namespace Concurrency { #endif // ^^^ !defined(_CRT_APP) ^^^ } // namespace Concurrency - -#ifdef _CRT_APP -extern "C" void __cdecl __crtCleanupCausalityStaticFactories() { - Concurrency::details::asyncCausalityTracer.release(); -} -#endif diff --git a/stl/src/xonce.cpp b/stl/src/xonce.cpp index f63352c3c9..486c602bf9 100644 --- a/stl/src/xonce.cpp +++ b/stl/src/xonce.cpp @@ -1,39 +1,21 @@ // Copyright (c) Microsoft Corporation. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// _Execute_once function - #include #include -namespace { - struct _Xfg_trampoline_parameter { - void* _Pv; - _STD _Execute_once_fp_t _Callback; - }; -} // unnamed namespace - _STD_BEGIN +// Returns BOOL, nonzero to indicate success, zero for failure +using _Execute_once_fp_t = int(__stdcall*)(void*, void*, void**); -// TRANSITION, ABI +// TRANSITION, ABI: _Execute_once() is preserved for binary compatibility _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. - - _Xfg_trampoline_parameter _Trampoline_parameter = {_Pv, _Callback}; - - PINIT_ONCE_FN _Xfg_trampoline = [](PINIT_ONCE _InitOnce, PVOID _Parameter, PVOID* _Context) { - const auto _Trampoline_parameter = static_cast<_Xfg_trampoline_parameter*>(_Parameter); - return static_cast(_Trampoline_parameter->_Callback(_InitOnce, _Trampoline_parameter->_Pv, _Context)); - }; - return InitOnceExecuteOnce( - reinterpret_cast(&_Flag._Opaque), _Xfg_trampoline, &_Trampoline_parameter, nullptr); + reinterpret_cast(&_Flag._Opaque), reinterpret_cast(_Callback), _Pv, nullptr); } [[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL