Coverage Report

Created: 2022-01-15 10:30

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Host/macosx/objcxx/HostThreadMacOSX.mm
Line
Count
Source
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
9
#include "lldb/Host/macosx/HostThreadMacOSX.h"
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
8.59k
  MacOSXDarwinThread() { m_pool = [[NSAutoreleasePool alloc] init]; }
27
28
8.59k
  ~MacOSXDarwinThread() {
29
8.59k
    if (m_pool) {
30
8.59k
      [m_pool drain];
31
8.59k
      m_pool = nil;
32
8.59k
    }
33
8.59k
  }
34
35
8.59k
  static void PThreadDestructor(void *v) {
36
8.59k
    if (v)
37
8.59k
      delete static_cast<MacOSXDarwinThread *>(v);
38
8.59k
    ::pthread_setspecific(g_thread_create_key, NULL);
39
8.59k
  }
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
1.05k
static void InitThreadCreated() {
51
1.05k
  ::pthread_key_create(&g_thread_create_key,
52
1.05k
                       MacOSXDarwinThread::PThreadDestructor);
53
1.05k
}
54
55
42.9k
HostThreadMacOSX::HostThreadMacOSX() : HostThreadPosix() {}
56
57
HostThreadMacOSX::HostThreadMacOSX(lldb::thread_t thread)
58
8.59k
    : HostThreadPosix(thread) {}
59
60
lldb::thread_result_t
61
8.59k
HostThreadMacOSX::ThreadCreateTrampoline(lldb::thread_arg_t arg) {
62
8.59k
  ::pthread_once(&g_thread_create_once, InitThreadCreated);
63
8.59k
  if (g_thread_create_key) {
64
8.59k
    ::pthread_setspecific(g_thread_create_key, new MacOSXDarwinThread());
65
8.59k
  }
66
67
8.59k
  return HostThreadPosix::ThreadCreateTrampoline(arg);
68
8.59k
}