LLDB  mainline
HostThreadMacOSX.mm
Go to the documentation of this file.
1 //===-- HostThreadMacOSX.cpp ------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "lldb/Host/Host.h"
11 
12 #include <CoreFoundation/CoreFoundation.h>
13 #include <Foundation/Foundation.h>
14 
15 #include <pthread.h>
16 
17 using namespace lldb_private;
18 
19 
20 static pthread_once_t g_thread_create_once = PTHREAD_ONCE_INIT;
21 static pthread_key_t g_thread_create_key = 0;
22 
23 namespace {
24 class MacOSXDarwinThread {
25 public:
26  MacOSXDarwinThread() { m_pool = [[NSAutoreleasePool alloc] init]; }
27 
28  ~MacOSXDarwinThread() {
29  if (m_pool) {
30  [m_pool drain];
31  m_pool = nil;
32  }
33  }
34 
35  static void PThreadDestructor(void *v) {
36  if (v)
37  delete static_cast<MacOSXDarwinThread *>(v);
38  ::pthread_setspecific(g_thread_create_key, NULL);
39  }
40 
41 protected:
42  NSAutoreleasePool *m_pool = nil;
43 
44 private:
45  MacOSXDarwinThread(const MacOSXDarwinThread &) = delete;
46  const MacOSXDarwinThread &operator=(const MacOSXDarwinThread &) = delete;
47 };
48 } // namespace
49 
50 static void InitThreadCreated() {
51  ::pthread_key_create(&g_thread_create_key,
52  MacOSXDarwinThread::PThreadDestructor);
53 }
54 
56 
58  : HostThreadPosix(thread) {}
59 
62  ::pthread_once(&g_thread_create_once, InitThreadCreated);
63  if (g_thread_create_key) {
64  ::pthread_setspecific(g_thread_create_key, new MacOSXDarwinThread());
65  }
66 
68 }
lldb_private::HostNativeThreadBase::ThreadCreateTrampoline
static lldb::thread_result_t THREAD_ROUTINE ThreadCreateTrampoline(lldb::thread_arg_t arg)
Definition: HostNativeThreadBase.cpp:53
lldb_private::HostThreadPosix
Definition: HostThreadPosix.h:16
Host.h
lldb::thread_t
pthread_t thread_t
Definition: lldb-types.h:58
HostThreadMacOSX.h
InitThreadCreated
static void InitThreadCreated()
Definition: HostThreadMacOSX.mm:50
lldb::thread_arg_t
void * thread_arg_t
Definition: lldb-types.h:61
g_thread_create_key
static pthread_key_t g_thread_create_key
Definition: HostThreadMacOSX.mm:21
g_thread_create_once
static pthread_once_t g_thread_create_once
Definition: HostThreadMacOSX.mm:20
lldb::thread_result_t
void * thread_result_t
Definition: lldb-types.h:62
lldb_private::HostThreadMacOSX::ThreadCreateTrampoline
static lldb::thread_result_t ThreadCreateTrampoline(lldb::thread_arg_t arg)
Definition: HostThreadMacOSX.mm:61
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::HostThreadMacOSX::HostThreadMacOSX
HostThreadMacOSX()
Definition: HostThreadMacOSX.mm:55