]> git.sesse.net Git - casparcg/commitdiff
Enabled Linux support for native thread id in INFO THREADS. Also sets the Linux threa...
authorHelge Norberg <helge.norberg@svt.se>
Fri, 14 Aug 2015 13:37:59 +0000 (15:37 +0200)
committerHelge Norberg <helge.norberg@svt.se>
Fri, 14 Aug 2015 13:37:59 +0000 (15:37 +0200)
common/os/linux/signal_handlers.cpp
common/os/linux/threading.cpp
protocol/amcp/AMCPCommandsImpl.cpp

index e87cc69e7c4d535582c90f3178927c4bdeb3b914..3ab4a7332266fa792ea095041ec9e45f193b779a 100644 (file)
@@ -5,6 +5,7 @@
 #include "../../thread_info.h"
 
 #include <signal.h>
+#include <pthread.h>
 
 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);
+       }
 }
 
 }
index bab082b73ff678f639a58b59fcc3db8b0188c758..b5735edc83ead3884e1898949f8b564776ddeb18 100644 (file)
 
 #include "../threading.h"
 
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+
 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);
 }
 
 }
index 21e389136e0bbe1d374927f7ac4fd0cc8b342c8c..b4d063d7593b1c2ff06b1b5b64f0ae3b71ca9f1f 100644 (file)
@@ -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";