summaryrefslogtreecommitdiff
path: root/src/env.h
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-03-18 13:30:49 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-22 00:44:25 +0100
commitd812dbb495a2471f7835c330b49c1d8f3fa8e5c2 (patch)
tree27150b3d5fcb8ee843994d5f3a9f34e19a1438f2 /src/env.h
parentde3b164f4fd069ecfcf496609466fdc85838c08f (diff)
downloadandroid-node-v8-d812dbb495a2471f7835c330b49c1d8f3fa8e5c2.tar.gz
android-node-v8-d812dbb495a2471f7835c330b49c1d8f3fa8e5c2.tar.bz2
android-node-v8-d812dbb495a2471f7835c330b49c1d8f3fa8e5c2.zip
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.h')
-rw-r--r--src/env.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/env.h b/src/env.h
index 4e928e6f31..1b7022704f 100644
--- a/src/env.h
+++ b/src/env.h
@@ -38,6 +38,7 @@
#include "uv.h"
#include "v8.h"
+#include <atomic>
#include <cstdint>
#include <functional>
#include <list>
@@ -518,18 +519,19 @@ class AsyncRequest : public MemoryRetainer {
void Install(Environment* env, void* data, uv_async_cb target);
void Uninstall();
void Stop();
- void SetStopped(bool flag);
- bool IsStopped() const;
+ inline void set_stopped(bool flag);
+ inline bool is_stopped() const;
uv_async_t* GetHandle();
void MemoryInfo(MemoryTracker* tracker) const override;
+
+
SET_MEMORY_INFO_NAME(AsyncRequest)
SET_SELF_SIZE(AsyncRequest)
private:
Environment* env_;
uv_async_t* async_ = nullptr;
- mutable Mutex mutex_;
- bool stop_ = true;
+ std::atomic_bool stopped_ {true};
};
class Environment {
@@ -1049,7 +1051,7 @@ class Environment {
inline ExecutionMode execution_mode() { return execution_mode_; }
inline void set_execution_mode(ExecutionMode mode) { execution_mode_ = mode; }
- inline AsyncRequest* GetAsyncRequest() { return &thread_stopper_; }
+ inline AsyncRequest* thread_stopper() { return &thread_stopper_; }
private:
inline void CreateImmediate(native_immediate_callback cb,