From bb5c355df9d93d103f1a008fba485d03c56465b5 Mon Sep 17 00:00:00 2001 From: Sebastien Hertz Date: Mon, 14 Apr 2014 14:38:24 +0200 Subject: [PATCH] Deduplicate code starting JDWP thread Also waits for thread_start_cond_ in a loop and removes needless mutex lock in JdwpState::Run when checking thread state. Change-Id: I6fca2151b5343b2906e9fa3b439029e6ad5b086d --- runtime/jdwp/jdwp_main.cc | 51 ++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/runtime/jdwp/jdwp_main.cc b/runtime/jdwp/jdwp_main.cc index 5fc0228f3..8e22c1df6 100644 --- a/runtime/jdwp/jdwp_main.cc +++ b/runtime/jdwp/jdwp_main.cc @@ -237,55 +237,41 @@ JdwpState* JdwpState::Create(const JdwpOptions* options) { Locks::mutator_lock_->AssertNotHeld(self); UniquePtr state(new JdwpState(options)); switch (options->transport) { - case kJdwpTransportSocket: - InitSocketTransport(state.get(), options); - break; + case kJdwpTransportSocket: + InitSocketTransport(state.get(), options); + break; #ifdef HAVE_ANDROID_OS - case kJdwpTransportAndroidAdb: - InitAdbTransport(state.get(), options); - break; + case kJdwpTransportAndroidAdb: + InitAdbTransport(state.get(), options); + break; #endif - default: - LOG(FATAL) << "Unknown transport: " << options->transport; + default: + LOG(FATAL) << "Unknown transport: " << options->transport; } - if (!options->suspend) { + { /* * Grab a mutex before starting the thread. This ensures they * won't signal the cond var before we're waiting. */ MutexLock thread_start_locker(self, state->thread_start_lock_); + /* * We have bound to a port, or are trying to connect outbound to a * debugger. Create the JDWP thread and let it continue the mission. */ - CHECK_PTHREAD_CALL(pthread_create, (&state->pthread_, NULL, StartJdwpThread, state.get()), "JDWP thread"); + CHECK_PTHREAD_CALL(pthread_create, (&state->pthread_, nullptr, StartJdwpThread, state.get()), + "JDWP thread"); /* * Wait until the thread finishes basic initialization. - * TODO: cond vars should be waited upon in a loop */ - state->thread_start_cond_.Wait(self); - } else { - { - /* - * Grab a mutex before starting the thread. This ensures they - * won't signal the cond var before we're waiting. - */ - MutexLock thread_start_locker(self, state->thread_start_lock_); - /* - * We have bound to a port, or are trying to connect outbound to a - * debugger. Create the JDWP thread and let it continue the mission. - */ - CHECK_PTHREAD_CALL(pthread_create, (&state->pthread_, NULL, StartJdwpThread, state.get()), "JDWP thread"); - - /* - * Wait until the thread finishes basic initialization. - * TODO: cond vars should be waited upon in a loop - */ + while (!state->debug_thread_started_) { state->thread_start_cond_.Wait(self); } + } + if (options->suspend) { /* * For suspend=y, wait for the debugger to connect to us or for us to * connect to the debugger. @@ -481,11 +467,8 @@ void JdwpState::Run() { /* process requests until the debugger drops */ bool first = true; while (!Dbg::IsDisposed()) { - { - // sanity check -- shouldn't happen? - MutexLock mu(thread_, *Locks::thread_suspend_count_lock_); - CHECK_EQ(thread_->GetState(), kWaitingInMainDebuggerLoop); - } + // sanity check -- shouldn't happen? + CHECK_EQ(thread_->GetState(), kWaitingInMainDebuggerLoop); if (!netState->ProcessIncoming()) { /* blocking read */ -- 2.11.0