@@ -265,12 +265,13 @@ class AgentImpl {
265265 const String16& message);
266266 void SwapBehindLock (MessageQueue* vector1, MessageQueue* vector2);
267267 void PostIncomingMessage (const String16& message);
268+ void WaitForFrontendMessage ();
269+ void NotifyMessageReceived ();
268270 State ToState (State state);
269271
270272 uv_sem_t start_sem_;
271- ConditionVariable pause_cond_;
272- Mutex pause_lock_;
273- Mutex queue_lock_;
273+ ConditionVariable incoming_message_cond_;
274+ Mutex state_lock_;
274275 uv_thread_t thread_;
275276 uv_loop_t child_loop_;
276277
@@ -370,15 +371,11 @@ class V8NodeInspector : public v8_inspector::V8InspectorClient {
370371 return ;
371372 terminated_ = false ;
372373 running_nested_loop_ = true ;
373- agent_->DispatchMessages ();
374- do {
375- {
376- Mutex::ScopedLock scoped_lock (agent_->pause_lock_ );
377- agent_->pause_cond_ .Wait (scoped_lock);
378- }
374+ while (!terminated_) {
375+ agent_->WaitForFrontendMessage ();
379376 while (v8::platform::PumpMessageLoop (platform_, env_->isolate ()))
380377 {}
381- } while (!terminated_);
378+ }
382379 terminated_ = false ;
383380 running_nested_loop_ = false ;
384381 }
@@ -661,7 +658,6 @@ bool AgentImpl::OnInspectorHandshakeIO(InspectorSocket* socket,
661658void AgentImpl::OnRemoteDataIO (InspectorSocket* socket,
662659 ssize_t read,
663660 const uv_buf_t * buf) {
664- Mutex::ScopedLock scoped_lock (pause_lock_);
665661 if (read > 0 ) {
666662 String16 str = String16::fromUTF8 (buf->base , read);
667663 // TODO(pfeldman): Instead of blocking execution while debugger
@@ -686,7 +682,6 @@ void AgentImpl::OnRemoteDataIO(InspectorSocket* socket,
686682 if (buf) {
687683 delete[] buf->base ;
688684 }
689- pause_cond_.Broadcast (scoped_lock);
690685}
691686
692687// static
@@ -752,14 +747,14 @@ void AgentImpl::WorkerRunIO() {
752747
753748bool AgentImpl::AppendMessage (MessageQueue* queue, int session_id,
754749 const String16& message) {
755- Mutex::ScopedLock scoped_lock (queue_lock_ );
750+ Mutex::ScopedLock scoped_lock (state_lock_ );
756751 bool trigger_pumping = queue->empty ();
757752 queue->push_back (std::make_pair (session_id, message));
758753 return trigger_pumping;
759754}
760755
761756void AgentImpl::SwapBehindLock (MessageQueue* vector1, MessageQueue* vector2) {
762- Mutex::ScopedLock scoped_lock (queue_lock_ );
757+ Mutex::ScopedLock scoped_lock (state_lock_ );
763758 vector1->swap (*vector2);
764759}
765760
@@ -771,6 +766,18 @@ void AgentImpl::PostIncomingMessage(const String16& message) {
771766 isolate->RequestInterrupt (InterruptCallback, this );
772767 uv_async_send (data_written_);
773768 }
769+ NotifyMessageReceived ();
770+ }
771+
772+ void AgentImpl::WaitForFrontendMessage () {
773+ Mutex::ScopedLock scoped_lock (state_lock_);
774+ if (incoming_message_queue_.empty ())
775+ incoming_message_cond_.Wait (scoped_lock);
776+ }
777+
778+ void AgentImpl::NotifyMessageReceived () {
779+ Mutex::ScopedLock scoped_lock (state_lock_);
780+ incoming_message_cond_.Broadcast (scoped_lock);
774781}
775782
776783void AgentImpl::OnInspectorConnectionIO (InspectorSocket* socket) {
0 commit comments