diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-03-18 13:30:49 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-22 00:44:25 +0100 |
commit | d812dbb495a2471f7835c330b49c1d8f3fa8e5c2 (patch) | |
tree | 27150b3d5fcb8ee843994d5f3a9f34e19a1438f2 /src/env.cc | |
parent | de3b164f4fd069ecfcf496609466fdc85838c08f (diff) | |
download | node-new-d812dbb495a2471f7835c330b49c1d8f3fa8e5c2.tar.gz |
src: refactor thread stopping mechanism
- Follow style guide for naming, e.g. use lower_snake_case
for simple setters/getters.
- For performance, use atomics instead of a mutex, and inline
the corresponding getter/setter pair.
PR-URL: https://github.com/nodejs/node/pull/26757
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'src/env.cc')
-rw-r--r-- | src/env.cc | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/src/env.cc b/src/env.cc index f0dd9abeb6..292b8ae8de 100644 --- a/src/env.cc +++ b/src/env.cc @@ -319,13 +319,13 @@ void Environment::InitializeLibuv(bool start_profiler_idle_notifier) { uv_unref(reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_)); uv_unref(reinterpret_cast<uv_handle_t*>(&idle_check_handle_)); - GetAsyncRequest()->Install( + thread_stopper()->Install( this, static_cast<void*>(this), [](uv_async_t* handle) { Environment* env = static_cast<Environment*>(handle->data); uv_stop(env->event_loop()); }); - GetAsyncRequest()->SetStopped(false); - uv_unref(reinterpret_cast<uv_handle_t*>(GetAsyncRequest()->GetHandle())); + thread_stopper()->set_stopped(false); + uv_unref(reinterpret_cast<uv_handle_t*>(thread_stopper()->GetHandle())); // Register clean-up cb to be called to clean up the handles // when the environment is freed, note that they are not cleaned in @@ -344,7 +344,7 @@ void Environment::InitializeLibuv(bool start_profiler_idle_notifier) { void Environment::ExitEnv() { set_can_call_into_js(false); - GetAsyncRequest()->Stop(); + thread_stopper()->Stop(); isolate_->TerminateExecution(); } @@ -512,7 +512,7 @@ void Environment::RunCleanup() { started_cleanup_ = true; TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment), "RunCleanup", this); - GetAsyncRequest()->Uninstall(); + thread_stopper()->Uninstall(); CleanupHandles(); while (!cleanup_hooks_.empty()) { @@ -877,7 +877,7 @@ char* Environment::Reallocate(char* data, size_t old_size, size_t size) { } void AsyncRequest::Install(Environment* env, void* data, uv_async_cb target) { - Mutex::ScopedLock lock(mutex_); + CHECK_NULL(async_); env_ = env; async_ = new uv_async_t; async_->data = data; @@ -885,7 +885,6 @@ void AsyncRequest::Install(Environment* env, void* data, uv_async_cb target) { } void AsyncRequest::Uninstall() { - Mutex::ScopedLock lock(mutex_); if (async_ != nullptr) { env_->CloseHandle(async_, [](uv_async_t* async) { delete async; }); async_ = nullptr; @@ -893,33 +892,19 @@ void AsyncRequest::Uninstall() { } void AsyncRequest::Stop() { - Mutex::ScopedLock lock(mutex_); - stop_ = true; + set_stopped(true); if (async_ != nullptr) uv_async_send(async_); } -void AsyncRequest::SetStopped(bool flag) { - Mutex::ScopedLock lock(mutex_); - stop_ = flag; -} - -bool AsyncRequest::IsStopped() const { - Mutex::ScopedLock lock(mutex_); - return stop_; -} - uv_async_t* AsyncRequest::GetHandle() { - Mutex::ScopedLock lock(mutex_); return async_; } void AsyncRequest::MemoryInfo(MemoryTracker* tracker) const { - Mutex::ScopedLock lock(mutex_); if (async_ != nullptr) tracker->TrackField("async_request", *async_); } AsyncRequest::~AsyncRequest() { - Mutex::ScopedLock lock(mutex_); CHECK_NULL(async_); } |