Compare commits

...

1 commit

Author SHA1 Message Date
Leonard Hecker 2c947a0cd2 wip 2021-08-17 04:17:41 +02:00
4 changed files with 47 additions and 2 deletions

View file

@ -15,8 +15,9 @@
<!-- ========================= Headers ======================== -->
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="inc\ScopedResourceLoader.h" />
<ClInclude Include="inc\LibraryResources.h" />
<ClInclude Include="inc\ScopedResourceLoader.h" />
<ClInclude Include="inc\thread_assert.h" />
<ClInclude Include="inc\ThrottledFunc.h" />
<ClInclude Include="inc\Utils.h" />
<ClInclude Include="inc\WtExeUtils.h" />
@ -28,6 +29,7 @@
</ClCompile>
<ClCompile Include="LibraryResources.cpp" />
<ClCompile Include="ScopedResourceLoader.cpp" />
<ClCompile Include="thread_assert.cpp" />
</ItemGroup>
<!-- ========================= idl Files ======================== -->
<ItemGroup>

View file

@ -7,11 +7,13 @@
<ClCompile Include="pch.cpp" />
<ClCompile Include="LibraryResources.cpp" />
<ClCompile Include="ScopedResourceLoader.cpp" />
<ClCompile Include="thread_assert.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="ScopedResourceLoader.h" />
<ClInclude Include="inc\LibraryResources.h" />
<ClInclude Include="inc\ScopedResourceLoader.h" />
<ClInclude Include="inc\thread_assert.h" />
<ClInclude Include="inc\ThrottledFunc.h" />
<ClInclude Include="inc\Utils.h" />
<ClInclude Include="inc\WtExeUtils.h" />

View file

@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#pragma once
#ifdef NDEBUG
constexpr void mark_as_foreground_thread() {}
constexpr void assert_foreground_thread() {}
constexpr void assert_background_thread() {}
#else
void mark_as_foreground_thread();
void assert_foreground_thread();
void assert_background_thread();
#endif

View file

@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"
#include "thread_assert.h"
#ifndef NDEBUG
static const DWORD foreground_thread_id = []() -> DWORD {
const auto id = GetCurrentThreadId();
OutputDebugStringW((std::wstring(L"#### ") + std::to_wstring(id) + L" ####").c_str());
return id;
}();
void assert_foreground_thread() {
if (foreground_thread_id != GetCurrentThreadId()) {
//throw std::exception("expected to be called from a foreground thread");
}
}
void assert_background_thread() {
if (foreground_thread_id != GetCurrentThreadId()) {
throw std::exception("expected to be called from a background thread");
}
}
#endif // NDEBUG