From: Helge Norberg Date: Fri, 14 Aug 2015 13:37:59 +0000 (+0200) Subject: Enabled Linux support for native thread id in INFO THREADS. Also sets the Linux threa... X-Git-Tag: 2.1.0_Beta1~309 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=08a43704fa057c30e5711b815b59637d326e0282;p=casparcg Enabled Linux support for native thread id in INFO THREADS. Also sets the Linux thread name that can be viewed in system utilities like ps. --- diff --git a/common/os/linux/signal_handlers.cpp b/common/os/linux/signal_handlers.cpp index e87cc69e7..3ab4a7332 100644 --- a/common/os/linux/signal_handlers.cpp +++ b/common/os/linux/signal_handlers.cpp @@ -5,6 +5,7 @@ #include "../../thread_info.h" #include +#include namespace caspar { @@ -51,10 +52,23 @@ void install_gpf_handler() void ensure_gpf_handler_installed_for_thread( const char* thread_description) { + static const int MAX_LINUX_THREAD_NAME_LEN = 15; static auto install = []() { do_install_handlers(); return 0; } (); if (thread_description) + { get_thread_info().name = thread_description; + + if (std::strlen(thread_description) > MAX_LINUX_THREAD_NAME_LEN) + { + char truncated[MAX_LINUX_THREAD_NAME_LEN + 1]; + std::memcpy(truncated, thread_description, MAX_LINUX_THREAD_NAME_LEN); + truncated[MAX_LINUX_THREAD_NAME_LEN] = 0; + pthread_setname_np(pthread_self(), truncated); + } + else + pthread_setname_np(pthread_self(), thread_description); + } } } diff --git a/common/os/linux/threading.cpp b/common/os/linux/threading.cpp index bab082b73..b5735edc8 100644 --- a/common/os/linux/threading.cpp +++ b/common/os/linux/threading.cpp @@ -23,6 +23,10 @@ #include "../threading.h" +#include +#include +#include + namespace caspar { void set_priority_of_current_thread(thread_priority priority) @@ -32,8 +36,7 @@ void set_priority_of_current_thread(thread_priority priority) std::int64_t get_current_thread_id() { - // TODO: implement - return 0; + return syscall(__NR_gettid); } } diff --git a/protocol/amcp/AMCPCommandsImpl.cpp b/protocol/amcp/AMCPCommandsImpl.cpp index 21e389136..b4d063d75 100644 --- a/protocol/amcp/AMCPCommandsImpl.cpp +++ b/protocol/amcp/AMCPCommandsImpl.cpp @@ -2416,7 +2416,7 @@ std::wstring info_threads_command(command_context& ctx) for (auto& thread : get_thread_infos()) { - replyString << thread->native_id << L"\t" << u16(thread->name) << L"\r\n"; + replyString << thread->native_id << L" " << u16(thread->name) << L"\r\n"; } replyString << L"\r\n";