Skip to content

Commit 3df252e

Browse files
committed
Addendum to 81c457c
1 parent 36c50b8 commit 3df252e

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

Shared/sdk/CrashTelemetry.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include <cstdint>
1616
#include <string>
1717

18+
#if defined(_WIN32) && defined(__cplusplus)
19+
extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId(void);
20+
#endif
21+
1822
#ifdef __cplusplus
1923
namespace CrashTelemetry
2024
{
@@ -31,9 +35,10 @@ namespace CrashTelemetry
3135

3236
#if defined(MTA_CLIENT)
3337
# include <algorithm>
34-
# include <windows.h>
3538
# include <cstring>
3639
# include <cstdio>
40+
# include <functional>
41+
# include <thread>
3742

3843
namespace detail
3944
{
@@ -64,6 +69,16 @@ namespace detail
6469
}
6570
}
6671

72+
inline std::uint32_t GetThreadIdentifier() noexcept
73+
{
74+
# if defined(_WIN32)
75+
return static_cast<std::uint32_t>(::GetCurrentThreadId());
76+
# else
77+
const auto hashed = std::hash<std::thread::id>{}(std::this_thread::get_id());
78+
return static_cast<std::uint32_t>(hashed & 0xFFFFFFFFu);
79+
# endif
80+
}
81+
6782
struct ThreadState
6883
{
6984
Context current{};
@@ -140,7 +155,7 @@ namespace detail
140155
current.requestedSize = sizeBytes;
141156
current.resourcePointer = resourcePtr;
142157
current.timestamp = std::chrono::system_clock::now();
143-
current.threadId = GetCurrentThreadId();
158+
current.threadId = detail::GetThreadIdentifier();
144159
detail::CopyInto(current.resourceTag, resourceTag);
145160
detail::CopyInto(current.detail, detail);
146161
current.hasData = true;
@@ -203,7 +218,7 @@ namespace detail
203218

204219
const char* resourceTag = (entry.resourceTag[0] != '\0') ? entry.resourceTag.data() : "<unset>";
205220
const char* detailText = (entry.detail[0] != '\0') ? entry.detail.data() : "<none>";
206-
const auto threadId = entry.threadId != 0 ? entry.threadId : GetCurrentThreadId();
221+
const auto threadId = entry.threadId != 0 ? entry.threadId : detail::GetThreadIdentifier();
207222

208223
long long ageMs = -1;
209224
if (entry.timestamp.time_since_epoch().count() != 0)

0 commit comments

Comments
 (0)