Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion rts/System/MemPoolTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ inline size_t StablePosAllocator<T>::Allocate(size_t numElems)
if (positionToSize.empty()) {
size_t returnPos = data.size();
data.resize(data.size() + numElems);
myLog("StablePosAllocator<T>::Allocate(%u) = %u [thread_id = %u]", uint32_t(numElems), uint32_t(returnPos), static_cast<uint32_t>(Threading::GetCurrentThreadId()));
myLog("StablePosAllocator<T>::Allocate(%u) = %u [thread_id = %u]", uint32_t(numElems), uint32_t(returnPos), Threading::GetCurrentThreadIdAsU32());
return returnPos;
}

Expand Down
14 changes: 14 additions & 0 deletions rts/System/Platform/Threading.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <atomic>
#include <functional>
#include <type_traits>

#include <cinttypes>
#include <cstring>
Expand Down Expand Up @@ -55,6 +56,19 @@ namespace Threading {
NativeThreadHandle GetCurrentThread();
NativeThreadId GetCurrentThreadId();

// Convert a NativeThreadId to a 32-bit value for logging. NativeThreadId is a
// pointer (pthread_t) on macOS/BSD and an integer elsewhere; the template lets
// `if constexpr` select a cast that is valid for the actual type on each target
// (it would not be discarded in a non-template function).
template<class TId>
inline std::uint32_t ThreadIdAsU32(TId id) {
if constexpr (std::is_pointer_v<TId>)
return static_cast<std::uint32_t>(reinterpret_cast<std::uintptr_t>(id));
else
return static_cast<std::uint32_t>(id);
}
inline std::uint32_t GetCurrentThreadIdAsU32() { return ThreadIdAsU32(GetCurrentThreadId()); }

#ifndef _WIN32
extern thread_local std::shared_ptr<ThreadControls> localThreadControls;
#endif
Expand Down
Loading