Explorar o código

LibThreading: Only set pthread name on Serenity

pthread_setname_np is a can of worms for portability. Linux, macOS,
and the BSDs all do it differently.

Also skip adding the tid as an inspectable Core::Object property on
systems where pthread_t is known to be a pointer.
Andrew Kaster %!s(int64=2) %!d(string=hai) anos
pai
achega
2f439327ac
Modificáronse 1 ficheiros con 5 adicións e 0 borrados
  1. 5 0
      Userland/Libraries/LibThreading/Thread.cpp

+ 5 - 0
Userland/Libraries/LibThreading/Thread.cpp

@@ -15,7 +15,10 @@ Threading::Thread::Thread(Function<intptr_t()> action, StringView thread_name)
     , m_thread_name(thread_name.is_null() ? ""sv : thread_name)
 {
     register_property("thread_name", [&] { return JsonValue { m_thread_name }; });
+#if defined(AK_OS_SERENITY) || defined(AK_OS_LINUX)
+    // FIXME: Print out a pretty TID for BSD and macOS platforms, too
     register_property("tid", [&] { return JsonValue { m_tid }; });
+#endif
 }
 
 Threading::Thread::~Thread()
@@ -40,10 +43,12 @@ void Threading::Thread::start()
         static_cast<void*>(this));
 
     VERIFY(rc == 0);
+#ifdef AK_OS_SERENITY
     if (!m_thread_name.is_empty()) {
         rc = pthread_setname_np(m_tid, m_thread_name.characters());
         VERIFY(rc == 0);
     }
+#endif
     dbgln("Started thread \"{}\", tid = {}", m_thread_name, m_tid);
     m_started = true;
 }