1#include <xrpl/beast/core/CurrentThreadName.h>
15setCurrentThreadNameImpl(std::string_view name)
17#if DEBUG && BOOST_COMP_MSVC
24 struct THREADNAME_INFO
36 ni.szName = name.
data();
37 ni.dwThreadID = GetCurrentThreadId();
41#pragma warning(disable : 6320 6322)
44 RaiseException(0x406d1388, 0,
sizeof(ni) /
sizeof(ULONG_PTR), (ULONG_PTR*)&ni);
46 __except (EXCEPTION_CONTINUE_EXECUTION)
62setCurrentThreadNameImpl(std::string_view name)
65 pthread_setname_np(name.
data());
79setCurrentThreadNameImpl(std::string_view name)
82 char boundedName[kMaxThreadNameLength + 1];
83 auto const boundedSize =
84 name.
size() < kMaxThreadNameLength ? name.
size() : kMaxThreadNameLength;
85 name.
copy(boundedName, boundedSize);
86 boundedName[boundedSize] =
'\0';
88 pthread_setname_np(pthread_self(), boundedName);
90#ifdef TRUNCATED_THREAD_NAME_LOGS
91 if (name.
size() > kMaxThreadNameLength)
93 std::cerr <<
"WARNING: Thread name \"" << name <<
"\" (length " << name.
size()
94 <<
") exceeds maximum of " << kMaxThreadNameLength <<
" characters on Linux.\n";
118 detail::setCurrentThreadNameImpl(name);
void setCurrentThreadName(std::string_view newThreadName)
Changes the name of the caller thread.
std::string getCurrentThreadName()
Returns the name of the caller thread.