@@ -350,13 +350,13 @@ void Environment::InitializeLibuv(bool start_profiler_idle_notifier) {
350350 uv_unref (reinterpret_cast <uv_handle_t *>(&idle_prepare_handle_));
351351 uv_unref (reinterpret_cast <uv_handle_t *>(&idle_check_handle_));
352352
353- GetAsyncRequest ()->Install (
353+ thread_stopper ()->Install (
354354 this , static_cast <void *>(this ), [](uv_async_t * handle) {
355355 Environment* env = static_cast <Environment*>(handle->data );
356356 uv_stop (env->event_loop ());
357357 });
358- GetAsyncRequest ()->SetStopped (false );
359- uv_unref (reinterpret_cast <uv_handle_t *>(GetAsyncRequest ()->GetHandle ()));
358+ thread_stopper ()->set_stopped (false );
359+ uv_unref (reinterpret_cast <uv_handle_t *>(thread_stopper ()->GetHandle ()));
360360
361361 // Register clean-up cb to be called to clean up the handles
362362 // when the environment is freed, note that they are not cleaned in
@@ -375,7 +375,7 @@ void Environment::InitializeLibuv(bool start_profiler_idle_notifier) {
375375
376376void Environment::ExitEnv () {
377377 set_can_call_into_js (false );
378- GetAsyncRequest ()->Stop ();
378+ thread_stopper ()->Stop ();
379379 isolate_->TerminateExecution ();
380380}
381381
@@ -543,7 +543,7 @@ void Environment::RunCleanup() {
543543 started_cleanup_ = true ;
544544 TraceEventScope trace_scope (TRACING_CATEGORY_NODE1 (environment),
545545 " RunCleanup" , this );
546- GetAsyncRequest ()->Uninstall ();
546+ thread_stopper ()->Uninstall ();
547547 CleanupHandles ();
548548
549549 while (!cleanup_hooks_.empty ()) {
@@ -977,49 +977,34 @@ char* Environment::Reallocate(char* data, size_t old_size, size_t size) {
977977}
978978
979979void AsyncRequest::Install (Environment* env, void * data, uv_async_cb target) {
980- Mutex::ScopedLock lock (mutex_ );
980+ CHECK_NULL (async_ );
981981 env_ = env;
982982 async_ = new uv_async_t ;
983983 async_->data = data;
984984 CHECK_EQ (uv_async_init (env_->event_loop (), async_, target), 0 );
985985}
986986
987987void AsyncRequest::Uninstall () {
988- Mutex::ScopedLock lock (mutex_);
989988 if (async_ != nullptr ) {
990989 env_->CloseHandle (async_, [](uv_async_t * async) { delete async; });
991990 async_ = nullptr ;
992991 }
993992}
994993
995994void AsyncRequest::Stop () {
996- Mutex::ScopedLock lock (mutex_);
997- stop_ = true ;
995+ set_stopped (true );
998996 if (async_ != nullptr ) uv_async_send (async_);
999997}
1000998
1001- void AsyncRequest::SetStopped (bool flag) {
1002- Mutex::ScopedLock lock (mutex_);
1003- stop_ = flag;
1004- }
1005-
1006- bool AsyncRequest::IsStopped () const {
1007- Mutex::ScopedLock lock (mutex_);
1008- return stop_;
1009- }
1010-
1011999uv_async_t * AsyncRequest::GetHandle () {
1012- Mutex::ScopedLock lock (mutex_);
10131000 return async_;
10141001}
10151002
10161003void AsyncRequest::MemoryInfo (MemoryTracker* tracker) const {
1017- Mutex::ScopedLock lock (mutex_);
10181004 if (async_ != nullptr ) tracker->TrackField (" async_request" , *async_);
10191005}
10201006
10211007AsyncRequest::~AsyncRequest () {
1022- Mutex::ScopedLock lock (mutex_);
10231008 CHECK_NULL (async_);
10241009}
10251010
0 commit comments