@@ -265,12 +265,13 @@ class AgentImpl {
265
265
const String16& message);
266
266
void SwapBehindLock (MessageQueue* vector1, MessageQueue* vector2);
267
267
void PostIncomingMessage (const String16& message);
268
+ void WaitForFrontendMessage ();
269
+ void NotifyMessageReceived ();
268
270
State ToState (State state);
269
271
270
272
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_;
274
275
uv_thread_t thread_;
275
276
uv_loop_t child_loop_;
276
277
@@ -370,15 +371,11 @@ class V8NodeInspector : public v8_inspector::V8InspectorClient {
370
371
return ;
371
372
terminated_ = false ;
372
373
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 ();
379
376
while (v8::platform::PumpMessageLoop (platform_, env_->isolate ()))
380
377
{}
381
- } while (!terminated_);
378
+ }
382
379
terminated_ = false ;
383
380
running_nested_loop_ = false ;
384
381
}
@@ -661,7 +658,6 @@ bool AgentImpl::OnInspectorHandshakeIO(InspectorSocket* socket,
661
658
void AgentImpl::OnRemoteDataIO (InspectorSocket* socket,
662
659
ssize_t read,
663
660
const uv_buf_t * buf) {
664
- Mutex::ScopedLock scoped_lock (pause_lock_);
665
661
if (read > 0 ) {
666
662
String16 str = String16::fromUTF8 (buf->base , read);
667
663
// TODO(pfeldman): Instead of blocking execution while debugger
@@ -686,7 +682,6 @@ void AgentImpl::OnRemoteDataIO(InspectorSocket* socket,
686
682
if (buf) {
687
683
delete[] buf->base ;
688
684
}
689
- pause_cond_.Broadcast (scoped_lock);
690
685
}
691
686
692
687
// static
@@ -752,14 +747,14 @@ void AgentImpl::WorkerRunIO() {
752
747
753
748
bool AgentImpl::AppendMessage (MessageQueue* queue, int session_id,
754
749
const String16& message) {
755
- Mutex::ScopedLock scoped_lock (queue_lock_ );
750
+ Mutex::ScopedLock scoped_lock (state_lock_ );
756
751
bool trigger_pumping = queue->empty ();
757
752
queue->push_back (std::make_pair (session_id, message));
758
753
return trigger_pumping;
759
754
}
760
755
761
756
void AgentImpl::SwapBehindLock (MessageQueue* vector1, MessageQueue* vector2) {
762
- Mutex::ScopedLock scoped_lock (queue_lock_ );
757
+ Mutex::ScopedLock scoped_lock (state_lock_ );
763
758
vector1->swap (*vector2);
764
759
}
765
760
@@ -771,6 +766,18 @@ void AgentImpl::PostIncomingMessage(const String16& message) {
771
766
isolate->RequestInterrupt (InterruptCallback, this );
772
767
uv_async_send (data_written_);
773
768
}
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);
774
781
}
775
782
776
783
void AgentImpl::OnInspectorConnectionIO (InspectorSocket* socket) {
0 commit comments