Pass self to lock methods.
This avoids frequent recomputation of
Thread::Current/pthread_getspecific.
Also add a futex based reader/writer mutex that is disabled.
Change-Id: I118fdb99ef1d1c4bfda6446ba3a0d8b6ab31eaee
diff --git a/src/jdwp/jdwp_main.cc b/src/jdwp/jdwp_main.cc
index 4fec005..a09c488 100644
--- a/src/jdwp/jdwp_main.cc
+++ b/src/jdwp/jdwp_main.cc
@@ -118,7 +118,8 @@
* the thread is accepting network connections.
*/
JdwpState* JdwpState::Create(const JdwpOptions* options) {
- Locks::mutator_lock_->AssertNotHeld();
+ Thread* self = Thread::Current();
+ Locks::mutator_lock_->AssertNotHeld(self);
UniquePtr<JdwpState> state(new JdwpState(options));
switch (options->transport) {
case kJdwpTransportSocket:
@@ -157,7 +158,7 @@
* Wait until the thread finishes basic initialization.
* TODO: cond vars should be waited upon in a loop
*/
- state->thread_start_cond_.Wait(state->thread_start_lock_);
+ state->thread_start_cond_.Wait(self, state->thread_start_lock_);
} else {
{
MutexLock attach_locker(state->attach_lock_);
@@ -171,7 +172,7 @@
* Wait until the thread finishes basic initialization.
* TODO: cond vars should be waited upon in a loop
*/
- state->thread_start_cond_.Wait(state->thread_start_lock_);
+ state->thread_start_cond_.Wait(self, state->thread_start_lock_);
/*
* For suspend=y, wait for the debugger to connect to us or for us to
@@ -182,8 +183,8 @@
* when we wake up.
*/
{
- ScopedThreadStateChange tsc(Thread::Current(), kWaitingForDebuggerToAttach);
- state->attach_cond_.Wait(state->attach_lock_);
+ ScopedThreadStateChange tsc(self, kWaitingForDebuggerToAttach);
+ state->attach_cond_.Wait(self, state->attach_lock_);
}
}
if (!state->IsActive()) {
@@ -294,14 +295,15 @@
thread_ = Thread::Current();
run = true;
- thread_start_lock_.Lock();
- debug_thread_started_ = true;
- thread_start_cond_.Broadcast();
- thread_start_lock_.Unlock();
+ {
+ MutexLock locker(thread_, thread_start_lock_);
+ debug_thread_started_ = true;
+ thread_start_cond_.Broadcast();
+ }
/* set the thread state to kWaitingInMainDebuggerLoop so GCs don't wait for us */
{
- MutexLock mu(*Locks::thread_suspend_count_lock_);
+ MutexLock mu(thread_, *Locks::thread_suspend_count_lock_);
CHECK_EQ(thread_->GetState(), kNative);
thread_->SetState(kWaitingInMainDebuggerLoop);
}
@@ -346,7 +348,7 @@
while (!Dbg::IsDisposed()) {
{
// sanity check -- shouldn't happen?
- MutexLock mu(*Locks::thread_suspend_count_lock_);
+ MutexLock mu(thread_, *Locks::thread_suspend_count_lock_);
CHECK_EQ(thread_->GetState(), kWaitingInMainDebuggerLoop);
}
@@ -366,7 +368,7 @@
}
/* wake anybody who's waiting for us */
- MutexLock mu(attach_lock_);
+ MutexLock mu(thread_, attach_lock_);
attach_cond_.Broadcast();
}
}
@@ -400,11 +402,8 @@
}
/* back to native, for thread shutdown */
- {
- MutexLock mu(*Locks::thread_suspend_count_lock_);
- CHECK_EQ(thread_->GetState(), kWaitingInMainDebuggerLoop);
- thread_->SetState(kNative);
- }
+ CHECK_EQ(thread_->GetState(), kWaitingInMainDebuggerLoop);
+ thread_->SetState(kNative);
VLOG(jdwp) << "JDWP: thread detaching and exiting...";
runtime->DetachCurrentThread();