2323#include < memory>
2424
2525MachThreadList::MachThreadList ()
26- : m_threads(), m_threads_mutex(PTHREAD_MUTEX_RECURSIVE),
27- m_is_64_bit(false ) {}
26+ : m_threads(), m_threads_mutex(), m_is_64_bit(false ) {}
2827
2928MachThreadList::~MachThreadList () = default ;
3029
@@ -116,7 +115,7 @@ const char *MachThreadList::GetThreadInfo(nub_thread_t tid) const {
116115}
117116
118117MachThreadSP MachThreadList::GetThreadByID (nub_thread_t tid) const {
119- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
118+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
120119 MachThreadSP thread_sp;
121120 const size_t num_threads = m_threads.size ();
122121 for (size_t idx = 0 ; idx < num_threads; ++idx) {
@@ -130,7 +129,7 @@ MachThreadSP MachThreadList::GetThreadByID(nub_thread_t tid) const {
130129
131130MachThreadSP
132131MachThreadList::GetThreadByMachPortNumber (thread_t mach_port_number) const {
133- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
132+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
134133 MachThreadSP thread_sp;
135134 const size_t num_threads = m_threads.size ();
136135 for (size_t idx = 0 ; idx < num_threads; ++idx) {
@@ -144,7 +143,7 @@ MachThreadList::GetThreadByMachPortNumber(thread_t mach_port_number) const {
144143
145144nub_thread_t
146145MachThreadList::GetThreadIDByMachPortNumber (thread_t mach_port_number) const {
147- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
146+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
148147 MachThreadSP thread_sp;
149148 const size_t num_threads = m_threads.size ();
150149 for (size_t idx = 0 ; idx < num_threads; ++idx) {
@@ -157,7 +156,7 @@ MachThreadList::GetThreadIDByMachPortNumber(thread_t mach_port_number) const {
157156
158157thread_t MachThreadList::GetMachPortNumberByThreadID (
159158 nub_thread_t globally_unique_id) const {
160- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
159+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
161160 MachThreadSP thread_sp;
162161 const size_t num_threads = m_threads.size ();
163162 for (size_t idx = 0 ; idx < num_threads; ++idx) {
@@ -219,12 +218,12 @@ bool MachThreadList::RestoreRegisterState(nub_thread_t tid, uint32_t save_id) {
219218}
220219
221220nub_size_t MachThreadList::NumThreads () const {
222- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
221+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
223222 return m_threads.size ();
224223}
225224
226225nub_thread_t MachThreadList::ThreadIDAtIndex (nub_size_t idx) const {
227- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
226+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
228227 if (idx < m_threads.size ())
229228 return m_threads[idx]->ThreadID ();
230229 return INVALID_NUB_THREAD;
@@ -248,7 +247,7 @@ bool MachThreadList::NotifyException(MachException::Data &exc) {
248247}
249248
250249void MachThreadList::Clear () {
251- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
250+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
252251 m_threads.clear ();
253252}
254253
@@ -259,7 +258,7 @@ MachThreadList::UpdateThreadList(MachProcess *process, bool update,
259258 DNBLogThreadedIf (LOG_THREAD, " MachThreadList::UpdateThreadList (pid = %4.4x, "
260259 " update = %u) process stop count = %u" ,
261260 process->ProcessID (), update, process->StopCount ());
262- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
261+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
263262
264263 if (process->StopCount () == 0 ) {
265264 int mib[4 ] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, process->ProcessID ()};
@@ -346,8 +345,7 @@ MachThreadList::UpdateThreadList(MachProcess *process, bool update,
346345}
347346
348347void MachThreadList::CurrentThread (MachThreadSP &thread_sp) {
349- // locker will keep a mutex locked until it goes out of scope
350- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
348+ std::lock_guard<std::recursive_mutex> guard (m_threads_mutex);
351349 if (m_current_thread.get () == NULL ) {
352350 // Figure out which thread is going to be our current thread.
353351 // This is currently done by finding the first thread in the list
@@ -364,7 +362,7 @@ void MachThreadList::CurrentThread(MachThreadSP &thread_sp) {
364362}
365363
366364void MachThreadList::Dump () const {
367- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
365+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
368366 const size_t num_threads = m_threads.size ();
369367 for (uint32_t idx = 0 ; idx < num_threads; ++idx) {
370368 m_threads[idx]->Dump (idx);
@@ -373,7 +371,7 @@ void MachThreadList::Dump() const {
373371
374372void MachThreadList::ProcessWillResume (
375373 MachProcess *process, const DNBThreadResumeActions &thread_actions) {
376- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
374+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
377375
378376 // Update our thread list, because sometimes libdispatch or the kernel
379377 // will spawn threads while a task is suspended.
@@ -447,7 +445,7 @@ void MachThreadList::ProcessWillResume(
447445}
448446
449447uint32_t MachThreadList::ProcessDidStop (MachProcess *process) {
450- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
448+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
451449 // Update our thread list
452450 const uint32_t num_threads = UpdateThreadList (process, true );
453451 for (uint32_t idx = 0 ; idx < num_threads; ++idx) {
@@ -466,7 +464,7 @@ uint32_t MachThreadList::ProcessDidStop(MachProcess *process) {
466464// true if we should stop and notify our clients
467465// false if we should resume our child process and skip notification
468466bool MachThreadList::ShouldStop (bool &step_more) {
469- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
467+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
470468 uint32_t should_stop = false ;
471469 const size_t num_threads = m_threads.size ();
472470 for (uint32_t idx = 0 ; !should_stop && idx < num_threads; ++idx) {
@@ -476,7 +474,7 @@ bool MachThreadList::ShouldStop(bool &step_more) {
476474}
477475
478476void MachThreadList::NotifyBreakpointChanged (const DNBBreakpoint *bp) {
479- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
477+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
480478 const size_t num_threads = m_threads.size ();
481479 for (uint32_t idx = 0 ; idx < num_threads; ++idx) {
482480 m_threads[idx]->NotifyBreakpointChanged (bp);
@@ -489,7 +487,7 @@ uint32_t MachThreadList::DoHardwareBreakpointAction(
489487 return INVALID_NUB_HW_INDEX;
490488
491489 uint32_t hw_index = INVALID_NUB_HW_INDEX;
492- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
490+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
493491 const size_t num_threads = m_threads.size ();
494492 // On Mac OS X we have to prime the control registers for new threads. We do
495493 // this using the control register data for the first thread, for lack of a
@@ -555,7 +553,7 @@ bool MachThreadList::DisableHardwareBreakpoint(const DNBBreakpoint *bp) const {
555553}
556554
557555uint32_t MachThreadList::NumSupportedHardwareWatchpoints () const {
558- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
556+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
559557 const size_t num_threads = m_threads.size ();
560558 // Use an arbitrary thread to retrieve the number of supported hardware
561559 // watchpoints.
@@ -566,7 +564,7 @@ uint32_t MachThreadList::NumSupportedHardwareWatchpoints() const {
566564
567565uint32_t MachThreadList::GetThreadIndexForThreadStoppedWithSignal (
568566 const int signo) const {
569- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
567+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
570568 uint32_t should_stop = false ;
571569 const size_t num_threads = m_threads.size ();
572570 for (uint32_t idx = 0 ; !should_stop && idx < num_threads; ++idx) {
0 commit comments