@@ -159,6 +159,7 @@ class AgentImpl {
159
159
160
160
static void ThreadCbIO (void * agent);
161
161
static void WriteCbIO (uv_async_t * async);
162
+ static void MainThreadAsyncCb (uv_async_t * req);
162
163
163
164
void InstallInspectorOnProcess ();
164
165
@@ -190,6 +191,7 @@ class AgentImpl {
190
191
node::Environment* parent_env_;
191
192
192
193
uv_async_t io_thread_req_;
194
+ uv_async_t main_thread_req_;
193
195
V8NodeInspector* inspector_;
194
196
v8::Platform* platform_;
195
197
MessageQueue<InspectorAction> incoming_message_queue_;
@@ -334,6 +336,9 @@ AgentImpl::AgentImpl(Environment* env) : delegate_(nullptr),
334
336
dispatching_messages_(false ),
335
337
session_id_(0 ),
336
338
server_(nullptr ) {
339
+ CHECK_EQ (0 , uv_async_init (env->event_loop (), &main_thread_req_,
340
+ AgentImpl::MainThreadAsyncCb));
341
+ uv_unref (reinterpret_cast <uv_handle_t *>(&main_thread_req_));
337
342
CHECK_EQ (0 , uv_sem_init (&start_sem_, 0 ));
338
343
memset (&io_thread_req_, 0 , sizeof (io_thread_req_));
339
344
}
@@ -416,10 +421,7 @@ bool AgentImpl::Start(v8::Platform* platform, const char* path,
416
421
417
422
InstallInspectorOnProcess ();
418
423
419
- int err = uv_loop_init (&child_loop_);
420
- CHECK_EQ (err, 0 );
421
-
422
- err = uv_thread_create (&thread_, AgentImpl::ThreadCbIO, this );
424
+ int err = uv_thread_create (&thread_, AgentImpl::ThreadCbIO, this );
423
425
CHECK_EQ (err, 0 );
424
426
uv_sem_wait (&start_sem_);
425
427
@@ -606,6 +608,7 @@ void AgentImpl::PostIncomingMessage(InspectorAction action, int session_id,
606
608
platform_->CallOnForegroundThread (isolate,
607
609
new DispatchOnInspectorBackendTask (this ));
608
610
isolate->RequestInterrupt (InterruptCallback, this );
611
+ CHECK_EQ (0 , uv_async_send (&main_thread_req_));
609
612
}
610
613
NotifyMessageReceived ();
611
614
}
@@ -662,6 +665,12 @@ void AgentImpl::DispatchMessages() {
662
665
dispatching_messages_ = false ;
663
666
}
664
667
668
+ // static
669
+ void AgentImpl::MainThreadAsyncCb (uv_async_t * req) {
670
+ AgentImpl* agent = node::ContainerOf (&AgentImpl::main_thread_req_, req);
671
+ agent->DispatchMessages ();
672
+ }
673
+
665
674
void AgentImpl::Write (TransportAction action, int session_id,
666
675
const StringView& inspector_message) {
667
676
AppendMessage (&outgoing_message_queue_, action, session_id,
0 commit comments