[Lldb-commits] [lldb] f4568e1 - [lldb] Simplify HostThreadMacOSX
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Feb 23 05:26:19 PST 2022
Author: Pavel Labath
Date: 2022-02-23T14:25:59+01:00
New Revision: f4568e12219f3a6ada20035ea40223680e274203
URL: https://github.com/llvm/llvm-project/commit/f4568e12219f3a6ada20035ea40223680e274203
DIFF: https://github.com/llvm/llvm-project/commit/f4568e12219f3a6ada20035ea40223680e274203.diff
LOG: [lldb] Simplify HostThreadMacOSX
The class is using an incredibly elaborate setup to create and destroy
an NSAutoreleasePool object. We can do it in a much simpler way by
making those calls inside our thread startup function.
The only effect of this patch is that the pool gets released at the end
of the ThreadCreateTrampoline function, instead of slightly later, when
pthreads begin thread-specific cleanup. However, the key destruction
order is unspecified, so nothing should be relying on that.
I didn't find a specific reason for why this would have to be done that
way in git history. It seems that before D5198, this was thread-specific
keys were the only way an os implementation (in Host::ThreadCreated)
could attach some value to a thread.
Differential Revision: https://reviews.llvm.org/D120322
Added:
Modified:
lldb/include/lldb/Host/macosx/HostThreadMacOSX.h
lldb/source/Host/macosx/objcxx/HostThreadMacOSX.mm
Removed:
################################################################################
diff --git a/lldb/include/lldb/Host/macosx/HostThreadMacOSX.h b/lldb/include/lldb/Host/macosx/HostThreadMacOSX.h
index 4e41119d97c6a..0299be3874085 100644
--- a/lldb/include/lldb/Host/macosx/HostThreadMacOSX.h
+++ b/lldb/include/lldb/Host/macosx/HostThreadMacOSX.h
@@ -17,8 +17,7 @@ class HostThreadMacOSX : public HostThreadPosix {
friend class ThreadLauncher;
public:
- HostThreadMacOSX();
- HostThreadMacOSX(lldb::thread_t thread);
+ using HostThreadPosix::HostThreadPosix;
protected:
static lldb::thread_result_t ThreadCreateTrampoline(lldb::thread_arg_t arg);
diff --git a/lldb/source/Host/macosx/objcxx/HostThreadMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostThreadMacOSX.mm
index 4f7e7ab248ad6..b24fe187b1a55 100644
--- a/lldb/source/Host/macosx/objcxx/HostThreadMacOSX.mm
+++ b/lldb/source/Host/macosx/objcxx/HostThreadMacOSX.mm
@@ -7,62 +7,14 @@
//===----------------------------------------------------------------------===//
#include "lldb/Host/macosx/HostThreadMacOSX.h"
-#include "lldb/Host/Host.h"
-
#include <CoreFoundation/CoreFoundation.h>
#include <Foundation/Foundation.h>
-#include <pthread.h>
-
using namespace lldb_private;
-
-static pthread_once_t g_thread_create_once = PTHREAD_ONCE_INIT;
-static pthread_key_t g_thread_create_key = 0;
-
-namespace {
-class MacOSXDarwinThread {
-public:
- MacOSXDarwinThread() { m_pool = [[NSAutoreleasePool alloc] init]; }
-
- ~MacOSXDarwinThread() {
- if (m_pool) {
- [m_pool drain];
- m_pool = nil;
- }
- }
-
- static void PThreadDestructor(void *v) {
- if (v)
- delete static_cast<MacOSXDarwinThread *>(v);
- ::pthread_setspecific(g_thread_create_key, NULL);
- }
-
-protected:
- NSAutoreleasePool *m_pool = nil;
-
-private:
- MacOSXDarwinThread(const MacOSXDarwinThread &) = delete;
- const MacOSXDarwinThread &operator=(const MacOSXDarwinThread &) = delete;
-};
-} // namespace
-
-static void InitThreadCreated() {
- ::pthread_key_create(&g_thread_create_key,
- MacOSXDarwinThread::PThreadDestructor);
-}
-
-HostThreadMacOSX::HostThreadMacOSX() : HostThreadPosix() {}
-
-HostThreadMacOSX::HostThreadMacOSX(lldb::thread_t thread)
- : HostThreadPosix(thread) {}
-
lldb::thread_result_t
HostThreadMacOSX::ThreadCreateTrampoline(lldb::thread_arg_t arg) {
- ::pthread_once(&g_thread_create_once, InitThreadCreated);
- if (g_thread_create_key) {
- ::pthread_setspecific(g_thread_create_key, new MacOSXDarwinThread());
+ @autoreleasepool {
+ return HostThreadPosix::ThreadCreateTrampoline(arg);
}
-
- return HostThreadPosix::ThreadCreateTrampoline(arg);
}
More information about the lldb-commits
mailing list