Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1b584eb

Browse files
committedMay 4, 2012
Don't expose the pthread_mutex_t underlying the Mutex & Mutex::Locker classes.
No one was using it and Locker(pthread_mutex_t *) immediately asserts for pthread_mutex_t's that don't come from a Mutex anyway. Rather than try to make that work, we should maintain the Mutex abstraction and not pass around the platform implementation... Make Mutex::Locker::Lock take a Mutex & or a Mutex *, and remove the constructor taking a pthread_mutex_t *. You no longer need to call Mutex::GetMutex to pass your mutex to a Locker (you can't in fact, since I made it private.) git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@156221 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 9d01042 commit 1b584eb

File tree

17 files changed

+74
-72
lines changed

17 files changed

+74
-72
lines changed
 

‎include/lldb/Host/Condition.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414

1515
#include <pthread.h>
16+
#include "lldb/Host/Mutex.h"
1617

1718
namespace lldb_private {
1819

@@ -55,15 +56,6 @@ class Condition
5556
int
5657
Broadcast ();
5758

58-
//------------------------------------------------------------------
59-
/// Get accessor to the pthread condition object.
60-
///
61-
/// @return
62-
/// A pointer to the condition variable owned by this object.
63-
//------------------------------------------------------------------
64-
pthread_cond_t *
65-
GetCondition ();
66-
6759
//------------------------------------------------------------------
6860
/// Unblocks one thread waiting for the condition variable
6961
///
@@ -107,13 +99,22 @@ class Condition
10799
/// @see Condition::Signal()
108100
//------------------------------------------------------------------
109101
int
110-
Wait (pthread_mutex_t *mutex, const TimeValue *abstime = NULL, bool *timed_out = NULL);
102+
Wait (Mutex &mutex, const TimeValue *abstime = NULL, bool *timed_out = NULL);
111103

112104
protected:
113105
//------------------------------------------------------------------
114106
// Member variables
115107
//------------------------------------------------------------------
116108
pthread_cond_t m_condition; ///< The condition variable.
109+
110+
//------------------------------------------------------------------
111+
/// Get accessor to the pthread condition object.
112+
///
113+
/// @return
114+
/// A pointer to the condition variable owned by this object.
115+
//------------------------------------------------------------------
116+
pthread_cond_t *
117+
GetCondition ();
117118
};
118119

119120
} // namespace lldb_private

‎include/lldb/Host/Mutex.h

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ namespace lldb_private {
2323
class Mutex
2424
{
2525
public:
26+
friend class Locker;
27+
friend class Condition;
28+
2629
enum Type
2730
{
2831
eMutexTypeNormal, ///< Mutex that can't recursively entered by the same thread
@@ -77,18 +80,6 @@ class Mutex
7780
//--------------------------------------------------------------
7881
Locker(Mutex* m);
7982

80-
//--------------------------------------------------------------
81-
/// Constructor with a raw pthread mutex object pointer.
82-
///
83-
/// This will create a scoped mutex locking object that locks
84-
/// \a mutex.
85-
///
86-
/// @param[in] mutex
87-
/// A pointer to a pthread_mutex_t that will get locked if
88-
/// non-NULL.
89-
//--------------------------------------------------------------
90-
Locker(pthread_mutex_t *mutex);
91-
9283
//--------------------------------------------------------------
9384
/// Desstructor
9485
///
@@ -105,7 +96,14 @@ class Mutex
10596
/// non-NULL.
10697
//--------------------------------------------------------------
10798
void
108-
Lock (pthread_mutex_t *mutex);
99+
Lock (Mutex &mutex);
100+
101+
void
102+
Lock (Mutex *mutex)
103+
{
104+
if (mutex)
105+
Lock(*mutex);
106+
}
109107

110108
//--------------------------------------------------------------
111109
/// Change the contained mutex only if the mutex can be locked.
@@ -123,7 +121,16 @@ class Mutex
123121
/// returns \b false otherwise.
124122
//--------------------------------------------------------------
125123
bool
126-
TryLock (pthread_mutex_t *mutex);
124+
TryLock (Mutex &mutex);
125+
126+
bool
127+
TryLock (Mutex *mutex)
128+
{
129+
if (mutex)
130+
return TryLock(*mutex);
131+
else
132+
return false;
133+
}
127134

128135
void
129136
Unlock ();
@@ -171,15 +178,6 @@ class Mutex
171178
//------------------------------------------------------------------
172179
~Mutex();
173180

174-
//------------------------------------------------------------------
175-
/// Mutex get accessor.
176-
///
177-
/// @return
178-
/// A pointer to the pthread mutex object owned by this object.
179-
//------------------------------------------------------------------
180-
pthread_mutex_t *
181-
GetMutex();
182-
183181
//------------------------------------------------------------------
184182
/// Lock the mutex.
185183
///
@@ -234,7 +232,17 @@ class Mutex
234232
// Member variables
235233
//------------------------------------------------------------------
236234
pthread_mutex_t m_mutex; ///< The pthread mutex object.
235+
237236
private:
237+
//------------------------------------------------------------------
238+
/// Mutex get accessor.
239+
///
240+
/// @return
241+
/// A pointer to the pthread mutex object owned by this object.
242+
//------------------------------------------------------------------
243+
pthread_mutex_t *
244+
GetMutex();
245+
238246
Mutex(const Mutex&);
239247
const Mutex& operator=(const Mutex&);
240248
};

‎include/lldb/Host/Predicate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class Predicate
314314

315315
while (err == 0 && m_value != value)
316316
{
317-
err = m_condition.Wait (m_mutex.GetMutex(), abstime, timed_out);
317+
err = m_condition.Wait (m_mutex, abstime, timed_out);
318318
}
319319

320320
return m_value == value;
@@ -339,7 +339,7 @@ class Predicate
339339

340340
while (err == 0 && m_value != wait_value)
341341
{
342-
err = m_condition.Wait (m_mutex.GetMutex(), abstime, timed_out);
342+
err = m_condition.Wait (m_mutex, abstime, timed_out);
343343
}
344344

345345
if (m_value == wait_value)

‎source/API/SBCommandInterpreter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnOb
9393
TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
9494
Mutex::Locker api_locker;
9595
if (target_sp)
96-
api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
96+
api_locker.Lock(target_sp->GetAPIMutex());
9797
m_opaque_ptr->HandleCommand (command_line, add_to_history, result.ref());
9898
}
9999
else
@@ -238,7 +238,7 @@ SBCommandInterpreter::SourceInitFileInHomeDirectory (SBCommandReturnObject &resu
238238
TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
239239
Mutex::Locker api_locker;
240240
if (target_sp)
241-
api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
241+
api_locker.Lock(target_sp->GetAPIMutex());
242242
m_opaque_ptr->SourceInitFile (false, result.ref());
243243
}
244244
else
@@ -263,7 +263,7 @@ SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory (SBCommandReturnOb
263263
TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
264264
Mutex::Locker api_locker;
265265
if (target_sp)
266-
api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
266+
api_locker.Lock(target_sp->GetAPIMutex());
267267
m_opaque_ptr->SourceInitFile (true, result.ref());
268268
}
269269
else

‎source/API/SBDebugger.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ SBDebugger::HandleCommand (const char *command)
308308
TargetSP target_sp (m_opaque_sp->GetSelectedTarget());
309309
Mutex::Locker api_locker;
310310
if (target_sp)
311-
api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
311+
api_locker.Lock(target_sp->GetAPIMutex());
312312

313313
SBCommandInterpreter sb_interpreter(GetCommandInterpreter ());
314314
SBCommandReturnObject result;
@@ -830,7 +830,7 @@ SBDebugger::PushInputReader (SBInputReader &reader)
830830
TargetSP target_sp (m_opaque_sp->GetSelectedTarget());
831831
Mutex::Locker api_locker;
832832
if (target_sp)
833-
api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
833+
api_locker.Lock(target_sp->GetAPIMutex());
834834
InputReaderSP reader_sp(*reader);
835835
m_opaque_sp->PushInputReader (reader_sp);
836836
}

‎source/API/SBFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ SBFunction::GetInstructions (SBTarget target)
130130
TargetSP target_sp (target.GetSP());
131131
if (target_sp)
132132
{
133-
api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
133+
api_locker.Lock (target_sp->GetAPIMutex());
134134
target_sp->CalculateExecutionContext (exe_ctx);
135135
exe_ctx.SetProcessSP(target_sp->GetProcessSP());
136136
}

‎source/API/SBInstruction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ SBInstruction::GetMnemonic(SBTarget target)
7878
TargetSP target_sp (target.GetSP());
7979
if (target_sp)
8080
{
81-
api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
81+
api_locker.Lock (target_sp->GetAPIMutex());
8282
target_sp->CalculateExecutionContext (exe_ctx);
8383
exe_ctx.SetProcessSP(target_sp->GetProcessSP());
8484
}
@@ -97,7 +97,7 @@ SBInstruction::GetOperands(SBTarget target)
9797
TargetSP target_sp (target.GetSP());
9898
if (target_sp)
9999
{
100-
api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
100+
api_locker.Lock (target_sp->GetAPIMutex());
101101
target_sp->CalculateExecutionContext (exe_ctx);
102102
exe_ctx.SetProcessSP(target_sp->GetProcessSP());
103103
}
@@ -116,7 +116,7 @@ SBInstruction::GetComment(SBTarget target)
116116
TargetSP target_sp (target.GetSP());
117117
if (target_sp)
118118
{
119-
api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
119+
api_locker.Lock (target_sp->GetAPIMutex());
120120
target_sp->CalculateExecutionContext (exe_ctx);
121121
exe_ctx.SetProcessSP(target_sp->GetProcessSP());
122122
}

‎source/API/SBSymbol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ SBSymbol::GetInstructions (SBTarget target)
126126
TargetSP target_sp (target.GetSP());
127127
if (target_sp)
128128
{
129-
api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
129+
api_locker.Lock (target_sp->GetAPIMutex());
130130
target_sp->CalculateExecutionContext (exe_ctx);
131131
}
132132
if (m_opaque_ptr->ValueIsAddress())

‎source/Breakpoint/BreakpointList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,5 +223,5 @@ BreakpointList::ClearAllBreakpointSites ()
223223
void
224224
BreakpointList::GetListMutex (Mutex::Locker &locker)
225225
{
226-
return locker.Lock (m_mutex.GetMutex());
226+
return locker.Lock (m_mutex);
227227
}

‎source/Breakpoint/WatchpointList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,5 +273,5 @@ WatchpointList::RemoveAll ()
273273
void
274274
WatchpointList::GetListMutex (Mutex::Locker &locker)
275275
{
276-
return locker.Lock (m_mutex.GetMutex());
276+
return locker.Lock (m_mutex);
277277
}

‎source/Commands/CommandObjectTarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2839,7 +2839,7 @@ class CommandObjectTargetModulesList : public CommandObject
28392839

28402840
if (use_global_module_list)
28412841
{
2842-
locker.Lock (Module::GetAllocationModuleCollectionMutex()->GetMutex());
2842+
locker.Lock (Module::GetAllocationModuleCollectionMutex());
28432843
num_modules = Module::GetNumberAllocatedModules();
28442844
}
28452845
else

‎source/Core/ModuleList.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ ModuleList::RemoveOrphans (bool mandatory)
118118

119119
if (mandatory)
120120
{
121-
locker.Lock (m_modules_mutex.GetMutex());
121+
locker.Lock (m_modules_mutex);
122122
}
123123
else
124124
{
125125
// Not mandatory, remove orphans if we can get the mutex
126-
if (!locker.TryLock(m_modules_mutex.GetMutex()))
126+
if (!locker.TryLock(m_modules_mutex))
127127
return 0;
128128
}
129129
collection::iterator pos = m_modules.begin();

‎source/Host/common/Condition.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@ Condition::Signal ()
7878
// The current thread re-acquires the lock on "mutex".
7979
//----------------------------------------------------------------------
8080
int
81-
Condition::Wait (pthread_mutex_t *mutex, const TimeValue *abstime, bool *timed_out)
81+
Condition::Wait (Mutex &mutex, const TimeValue *abstime, bool *timed_out)
8282
{
8383
int err = 0;
8484
do
8585
{
8686
if (abstime && abstime->IsValid())
8787
{
8888
struct timespec abstime_ts = abstime->GetAsTimeSpec();
89-
err = ::pthread_cond_timedwait (&m_condition, mutex, &abstime_ts);
89+
err = ::pthread_cond_timedwait (&m_condition, mutex.GetMutex(), &abstime_ts);
9090
}
9191
else
92-
err = ::pthread_cond_wait (&m_condition, mutex);
92+
err = ::pthread_cond_wait (&m_condition, mutex.GetMutex());
9393
} while (err == EINTR);
9494

9595
if (timed_out != NULL)

‎source/Host/common/Mutex.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Mutex::Locker::Locker () :
108108
Mutex::Locker::Locker (Mutex& m) :
109109
m_mutex_ptr(NULL)
110110
{
111-
Lock (m.GetMutex());
111+
Lock (m);
112112
}
113113

114114
//----------------------------------------------------------------------
@@ -121,18 +121,7 @@ Mutex::Locker::Locker (Mutex* m) :
121121
m_mutex_ptr(NULL)
122122
{
123123
if (m)
124-
Lock (m->GetMutex());
125-
}
126-
127-
//----------------------------------------------------------------------
128-
// Constructor with a raw pthread mutex object pointer.
129-
//
130-
// This will create a scoped mutex locking object that locks "mutex"
131-
//----------------------------------------------------------------------
132-
Mutex::Locker::Locker (pthread_mutex_t *mutex_ptr) :
133-
m_mutex_ptr (NULL)
134-
{
135-
Lock (mutex_ptr);
124+
Lock (m);
136125
}
137126

138127
//----------------------------------------------------------------------
@@ -150,8 +139,10 @@ Mutex::Locker::~Locker ()
150139
// mutex) and lock the new "mutex" object if it is non-NULL.
151140
//----------------------------------------------------------------------
152141
void
153-
Mutex::Locker::Lock (pthread_mutex_t *mutex_ptr)
142+
Mutex::Locker::Lock (Mutex &mutex)
154143
{
144+
pthread_mutex_t *mutex_ptr = mutex.GetMutex();
145+
155146
// We already have this mutex locked or both are NULL...
156147
if (m_mutex_ptr == mutex_ptr)
157148
return;
@@ -176,8 +167,10 @@ Mutex::Locker::Unlock ()
176167
}
177168

178169
bool
179-
Mutex::Locker::TryLock (pthread_mutex_t *mutex_ptr)
170+
Mutex::Locker::TryLock (Mutex &mutex)
180171
{
172+
pthread_mutex_t *mutex_ptr = mutex.GetMutex();
173+
181174
// We already have this mutex locked!
182175
if (m_mutex_ptr == mutex_ptr)
183176
return m_mutex_ptr != NULL;

‎source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ CommunicationKDP::SendRequestPacketNoLock (const PacketStreamType &request_packe
153153
bool
154154
CommunicationKDP::GetSequenceMutex (Mutex::Locker& locker)
155155
{
156-
return locker.TryLock (m_sequence_mutex.GetMutex());
156+
return locker.TryLock (m_sequence_mutex);
157157
}
158158

159159

‎source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ GDBRemoteCommunication::GetAck ()
264264
bool
265265
GDBRemoteCommunication::GetSequenceMutex (Mutex::Locker& locker)
266266
{
267-
return locker.TryLock (m_sequence_mutex.GetMutex());
267+
return locker.TryLock (m_sequence_mutex);
268268
}
269269

270270

‎source/Target/StackFrameList.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ StackFrameList::InvalidateFrames (uint32_t start_idx)
466466
void
467467
StackFrameList::Merge (std::auto_ptr<StackFrameList>& curr_ap, lldb::StackFrameListSP& prev_sp)
468468
{
469-
Mutex::Locker curr_locker (curr_ap.get() ? curr_ap->m_mutex.GetMutex() : NULL);
470-
Mutex::Locker prev_locker (prev_sp.get() ? prev_sp->m_mutex.GetMutex() : NULL);
469+
Mutex::Locker curr_locker (curr_ap.get() ? &curr_ap->m_mutex : NULL);
470+
Mutex::Locker prev_locker (prev_sp.get() ? &prev_sp->m_mutex : NULL);
471471

472472
#if defined (DEBUG_STACK_FRAMES)
473473
StreamFile s(stdout, false);

0 commit comments

Comments
 (0)
This repository has been archived.