23
23
#include < memory>
24
24
25
25
MachThreadList::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 ) {}
28
27
29
28
MachThreadList::~MachThreadList () = default ;
30
29
@@ -116,7 +115,7 @@ const char *MachThreadList::GetThreadInfo(nub_thread_t tid) const {
116
115
}
117
116
118
117
MachThreadSP 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);
120
119
MachThreadSP thread_sp;
121
120
const size_t num_threads = m_threads.size ();
122
121
for (size_t idx = 0 ; idx < num_threads; ++idx) {
@@ -130,7 +129,7 @@ MachThreadSP MachThreadList::GetThreadByID(nub_thread_t tid) const {
130
129
131
130
MachThreadSP
132
131
MachThreadList::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);
134
133
MachThreadSP thread_sp;
135
134
const size_t num_threads = m_threads.size ();
136
135
for (size_t idx = 0 ; idx < num_threads; ++idx) {
@@ -144,7 +143,7 @@ MachThreadList::GetThreadByMachPortNumber(thread_t mach_port_number) const {
144
143
145
144
nub_thread_t
146
145
MachThreadList::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);
148
147
MachThreadSP thread_sp;
149
148
const size_t num_threads = m_threads.size ();
150
149
for (size_t idx = 0 ; idx < num_threads; ++idx) {
@@ -157,7 +156,7 @@ MachThreadList::GetThreadIDByMachPortNumber(thread_t mach_port_number) const {
157
156
158
157
thread_t MachThreadList::GetMachPortNumberByThreadID (
159
158
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);
161
160
MachThreadSP thread_sp;
162
161
const size_t num_threads = m_threads.size ();
163
162
for (size_t idx = 0 ; idx < num_threads; ++idx) {
@@ -219,12 +218,12 @@ bool MachThreadList::RestoreRegisterState(nub_thread_t tid, uint32_t save_id) {
219
218
}
220
219
221
220
nub_size_t MachThreadList::NumThreads () const {
222
- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
221
+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
223
222
return m_threads.size ();
224
223
}
225
224
226
225
nub_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);
228
227
if (idx < m_threads.size ())
229
228
return m_threads[idx]->ThreadID ();
230
229
return INVALID_NUB_THREAD;
@@ -248,7 +247,7 @@ bool MachThreadList::NotifyException(MachException::Data &exc) {
248
247
}
249
248
250
249
void MachThreadList::Clear () {
251
- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
250
+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
252
251
m_threads.clear ();
253
252
}
254
253
@@ -259,7 +258,7 @@ MachThreadList::UpdateThreadList(MachProcess *process, bool update,
259
258
DNBLogThreadedIf (LOG_THREAD, " MachThreadList::UpdateThreadList (pid = %4.4x, "
260
259
" update = %u) process stop count = %u" ,
261
260
process->ProcessID (), update, process->StopCount ());
262
- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
261
+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
263
262
264
263
if (process->StopCount () == 0 ) {
265
264
int mib[4 ] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, process->ProcessID ()};
@@ -346,8 +345,7 @@ MachThreadList::UpdateThreadList(MachProcess *process, bool update,
346
345
}
347
346
348
347
void 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);
351
349
if (m_current_thread.get () == NULL ) {
352
350
// Figure out which thread is going to be our current thread.
353
351
// This is currently done by finding the first thread in the list
@@ -364,7 +362,7 @@ void MachThreadList::CurrentThread(MachThreadSP &thread_sp) {
364
362
}
365
363
366
364
void MachThreadList::Dump () const {
367
- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
365
+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
368
366
const size_t num_threads = m_threads.size ();
369
367
for (uint32_t idx = 0 ; idx < num_threads; ++idx) {
370
368
m_threads[idx]->Dump (idx);
@@ -373,7 +371,7 @@ void MachThreadList::Dump() const {
373
371
374
372
void MachThreadList::ProcessWillResume (
375
373
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);
377
375
378
376
// Update our thread list, because sometimes libdispatch or the kernel
379
377
// will spawn threads while a task is suspended.
@@ -447,7 +445,7 @@ void MachThreadList::ProcessWillResume(
447
445
}
448
446
449
447
uint32_t MachThreadList::ProcessDidStop (MachProcess *process) {
450
- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
448
+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
451
449
// Update our thread list
452
450
const uint32_t num_threads = UpdateThreadList (process, true );
453
451
for (uint32_t idx = 0 ; idx < num_threads; ++idx) {
@@ -466,7 +464,7 @@ uint32_t MachThreadList::ProcessDidStop(MachProcess *process) {
466
464
// true if we should stop and notify our clients
467
465
// false if we should resume our child process and skip notification
468
466
bool MachThreadList::ShouldStop (bool &step_more) {
469
- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
467
+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
470
468
uint32_t should_stop = false ;
471
469
const size_t num_threads = m_threads.size ();
472
470
for (uint32_t idx = 0 ; !should_stop && idx < num_threads; ++idx) {
@@ -476,7 +474,7 @@ bool MachThreadList::ShouldStop(bool &step_more) {
476
474
}
477
475
478
476
void MachThreadList::NotifyBreakpointChanged (const DNBBreakpoint *bp) {
479
- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
477
+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
480
478
const size_t num_threads = m_threads.size ();
481
479
for (uint32_t idx = 0 ; idx < num_threads; ++idx) {
482
480
m_threads[idx]->NotifyBreakpointChanged (bp);
@@ -489,7 +487,7 @@ uint32_t MachThreadList::DoHardwareBreakpointAction(
489
487
return INVALID_NUB_HW_INDEX;
490
488
491
489
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);
493
491
const size_t num_threads = m_threads.size ();
494
492
// On Mac OS X we have to prime the control registers for new threads. We do
495
493
// 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 {
555
553
}
556
554
557
555
uint32_t MachThreadList::NumSupportedHardwareWatchpoints () const {
558
- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
556
+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
559
557
const size_t num_threads = m_threads.size ();
560
558
// Use an arbitrary thread to retrieve the number of supported hardware
561
559
// watchpoints.
@@ -566,7 +564,7 @@ uint32_t MachThreadList::NumSupportedHardwareWatchpoints() const {
566
564
567
565
uint32_t MachThreadList::GetThreadIndexForThreadStoppedWithSignal (
568
566
const int signo) const {
569
- PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
567
+ std::lock_guard<std::recursive_mutex> guard ( m_threads_mutex);
570
568
uint32_t should_stop = false ;
571
569
const size_t num_threads = m_threads.size ();
572
570
for (uint32_t idx = 0 ; !should_stop && idx < num_threads; ++idx) {
0 commit comments