Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various cleanups: ppltasks.cpp #4445

Merged
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
34 changes: 7 additions & 27 deletions stl/src/ppltasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,11 @@
#pragma warning(pop)
#endif
#include <ctxtcall.h>
#include <mutex>
#include <functional>
#include <stdexcept>
#include <windows.foundation.diagnostics.h>
#endif

// This IID is exported by ole32.dll; we cannot depend on ole32.dll.
static GUID const Local_IID_ICallbackWithNoReentrancyToApplicationSTA = {
0x0A299774, 0x3E4E, 0xFC42, {0x1D, 0x9D, 0x72, 0xCE, 0xE1, 0x05, 0xCA, 0x57}};

// Introduce stacktrace API for Debug CRT_APP
#if defined(_CRT_APP) && defined(_DEBUG)
extern "C" NTSYSAPI _Success_(return != 0) WORD NTAPI
RtlCaptureStackBackTrace(_In_ DWORD FramesToSkip, _In_ DWORD FramesToCapture,
_Out_writes_to_(FramesToCapture, return) PVOID* BackTrace, _Out_opt_ PDWORD BackTraceHash);
#endif

namespace Concurrency {

namespace details {
Expand All @@ -55,27 +45,13 @@ namespace Concurrency {
/// CRT CaptureStackBackTrace API wrapper
/// </summary>
_CRTIMP2 size_t __cdecl CaptureCallstack(void** stackData, size_t skipFrames, size_t captureFrames) {
size_t capturedFrames = 0;
// RtlCaptureStackBackTrace is not available in MSDK, so we only call it under Desktop or _DEBUG MSDK.
// For MSDK unsupported version, we will return zero frame number.
#if !defined(_CRT_APP) || defined(_DEBUG)
capturedFrames = RtlCaptureStackBackTrace(
return RtlCaptureStackBackTrace(
static_cast<DWORD>(skipFrames + 1), static_cast<DWORD>(captureFrames), stackData, nullptr);
#else
(stackData);
(skipFrames);
(captureFrames);
#endif
return capturedFrames;
}

static unsigned int s_asyncId = 0;

_CRTIMP2 unsigned int __cdecl GetNextAsyncId() {
//
// ASYNC TODO: Determine the requirements on the domain uniqueness of this value. C++ / C# / WRL are
// all supposed to produce "unique" IDs and there is no common broker.
//
return static_cast<unsigned int>(::_InterlockedIncrement(reinterpret_cast<volatile LONG*>(&s_asyncId)));
}

Expand All @@ -99,6 +75,10 @@ namespace Concurrency {
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;

// This IID is exported by ole32.dll; we cannot depend on ole32.dll.
static GUID const Local_IID_ICallbackWithNoReentrancyToApplicationSTA = {
0x0A299774, 0x3E4E, 0xFC42, {0x1D, 0x9D, 0x72, 0xCE, 0xE1, 0x05, 0xCA, 0x57}};

static HRESULT __stdcall _PPLTaskContextCallbackBridge(ComCallData* _PParam) {
auto pFunc = static_cast<std::function<void()>*>(_PParam->pUserDefined);
(*pFunc)();
Expand Down