Skip to content

Commit 33a0a78

Browse files
authored
[debugserver] Migrate MachThread away from PThreadMutex (NFC) (llvm#137543)
The debugserver code predates modern C++, but with C++11 and later there's no need to have something like PThreadMutex. This migrates MachThread away from PThreadMutex in preparation for removing it.
1 parent 503ebad commit 33a0a78

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

lldb/tools/debugserver/source/MacOSX/MachThread.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ MachThread::MachThread(MachProcess *process, bool is_64_bit,
2828
uint64_t unique_thread_id, thread_t mach_port_num)
2929
: m_process(process), m_unique_id(unique_thread_id),
3030
m_mach_port_number(mach_port_num), m_seq_id(GetSequenceID()),
31-
m_state(eStateUnloaded), m_state_mutex(PTHREAD_MUTEX_RECURSIVE),
32-
m_suspend_count(0), m_stop_exception(),
33-
m_arch_up(DNBArchProtocol::Create(this)), m_reg_sets(NULL),
34-
m_num_reg_sets(0), m_extended_info(), m_dispatch_queue_name(),
35-
m_is_64_bit(is_64_bit), m_pthread_qos_class_decode(nullptr) {
31+
m_state(eStateUnloaded), m_state_mutex(), m_suspend_count(0),
32+
m_stop_exception(), m_arch_up(DNBArchProtocol::Create(this)),
33+
m_reg_sets(NULL), m_num_reg_sets(0), m_extended_info(),
34+
m_dispatch_queue_name(), m_is_64_bit(is_64_bit),
35+
m_pthread_qos_class_decode(nullptr) {
3636
nub_size_t num_reg_sets = 0;
3737
m_reg_sets = m_arch_up->GetRegisterSetInfo(&num_reg_sets);
3838
m_num_reg_sets = num_reg_sets;
@@ -469,13 +469,12 @@ bool MachThread::NotifyException(MachException::Data &exc) {
469469
}
470470

471471
nub_state_t MachThread::GetState() {
472-
// If any other threads access this we will need a mutex for it
473-
PTHREAD_MUTEX_LOCKER(locker, m_state_mutex);
472+
std::lock_guard<std::recursive_mutex> guard(m_state_mutex);
474473
return m_state;
475474
}
476475

477476
void MachThread::SetState(nub_state_t state) {
478-
PTHREAD_MUTEX_LOCKER(locker, m_state_mutex);
477+
std::lock_guard<std::recursive_mutex> guard(m_state_mutex);
479478
m_state = state;
480479
DNBLogThreadedIf(LOG_THREAD,
481480
"MachThread::SetState ( %s ) for tid = 0x%8.8" PRIx64 "",

lldb/tools/debugserver/source/MacOSX/MachThread.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#include "DNBArch.h"
2525
#include "DNBRegisterInfo.h"
2626
#include "MachException.h"
27-
#include "PThreadCondition.h"
28-
#include "PThreadMutex.h"
2927

3028
#include "ThreadInfo.h"
3129

@@ -139,7 +137,7 @@ class MachThread {
139137
// namesp.
140138
uint32_t m_seq_id; // A Sequential ID that increments with each new thread
141139
nub_state_t m_state; // The state of our process
142-
PThreadMutex m_state_mutex; // Multithreaded protection for m_state
140+
std::recursive_mutex m_state_mutex; // Multithreaded protection for m_state
143141
struct thread_basic_info m_basic_info; // Basic information for a thread used
144142
// to see if a thread is valid
145143
int32_t m_suspend_count; // The current suspend count > 0 means we have

0 commit comments

Comments
 (0)