[Lldb-commits] [lldb] [debugserver] Migrate MachThread away from PThreadMutex (NFC) (PR #137543)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Sun Apr 27 11:34:57 PDT 2025
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/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.
>From bf532b6d9095d58d66f74cd3d8adfff21ec541c4 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Sun, 27 Apr 2025 11:33:57 -0700
Subject: [PATCH] [debugserver] Migrate MachThread away from PThreadMutex (NFC)
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.
---
.../debugserver/source/MacOSX/MachThread.cpp | 15 +++++++--------
lldb/tools/debugserver/source/MacOSX/MachThread.h | 4 +---
2 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/lldb/tools/debugserver/source/MacOSX/MachThread.cpp b/lldb/tools/debugserver/source/MacOSX/MachThread.cpp
index 69e1c9bb0e252..e161b99998b5d 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachThread.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/MachThread.cpp
@@ -28,11 +28,11 @@ MachThread::MachThread(MachProcess *process, bool is_64_bit,
uint64_t unique_thread_id, thread_t mach_port_num)
: m_process(process), m_unique_id(unique_thread_id),
m_mach_port_number(mach_port_num), m_seq_id(GetSequenceID()),
- m_state(eStateUnloaded), m_state_mutex(PTHREAD_MUTEX_RECURSIVE),
- m_suspend_count(0), m_stop_exception(),
- m_arch_up(DNBArchProtocol::Create(this)), m_reg_sets(NULL),
- m_num_reg_sets(0), m_extended_info(), m_dispatch_queue_name(),
- m_is_64_bit(is_64_bit), m_pthread_qos_class_decode(nullptr) {
+ m_state(eStateUnloaded), m_state_mutex(), m_suspend_count(0),
+ m_stop_exception(), m_arch_up(DNBArchProtocol::Create(this)),
+ m_reg_sets(NULL), m_num_reg_sets(0), m_extended_info(),
+ m_dispatch_queue_name(), m_is_64_bit(is_64_bit),
+ m_pthread_qos_class_decode(nullptr) {
nub_size_t num_reg_sets = 0;
m_reg_sets = m_arch_up->GetRegisterSetInfo(&num_reg_sets);
m_num_reg_sets = num_reg_sets;
@@ -469,13 +469,12 @@ bool MachThread::NotifyException(MachException::Data &exc) {
}
nub_state_t MachThread::GetState() {
- // If any other threads access this we will need a mutex for it
- PTHREAD_MUTEX_LOCKER(locker, m_state_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_state_mutex);
return m_state;
}
void MachThread::SetState(nub_state_t state) {
- PTHREAD_MUTEX_LOCKER(locker, m_state_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_state_mutex);
m_state = state;
DNBLogThreadedIf(LOG_THREAD,
"MachThread::SetState ( %s ) for tid = 0x%8.8" PRIx64 "",
diff --git a/lldb/tools/debugserver/source/MacOSX/MachThread.h b/lldb/tools/debugserver/source/MacOSX/MachThread.h
index 0c78ef1a337ed..1086b7c986f11 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachThread.h
+++ b/lldb/tools/debugserver/source/MacOSX/MachThread.h
@@ -24,8 +24,6 @@
#include "DNBArch.h"
#include "DNBRegisterInfo.h"
#include "MachException.h"
-#include "PThreadCondition.h"
-#include "PThreadMutex.h"
#include "ThreadInfo.h"
@@ -139,7 +137,7 @@ class MachThread {
// namesp.
uint32_t m_seq_id; // A Sequential ID that increments with each new thread
nub_state_t m_state; // The state of our process
- PThreadMutex m_state_mutex; // Multithreaded protection for m_state
+ std::recursive_mutex m_state_mutex; // Multithreaded protection for m_state
struct thread_basic_info m_basic_info; // Basic information for a thread used
// to see if a thread is valid
int32_t m_suspend_count; // The current suspend count > 0 means we have
More information about the lldb-commits
mailing list