diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-01-29 19:06:17 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-02-01 20:22:33 +0100 |
commit | 393c19660510f3cd1ac3f9445747ec4c32ec224f (patch) | |
tree | 1c9e57d2917170f1f3bb0e46608f915c46a44544 /src/env.h | |
parent | bcf2886a84407028572fd1084242a1c789c056f8 (diff) | |
download | android-node-v8-393c19660510f3cd1ac3f9445747ec4c32ec224f.tar.gz android-node-v8-393c19660510f3cd1ac3f9445747ec4c32ec224f.tar.bz2 android-node-v8-393c19660510f3cd1ac3f9445747ec4c32ec224f.zip |
worker: refactor thread id management
- Assign thread IDs to `Environment` instances, rather than Workers.
This is more embedder-friendly than the current system, in which
all “main threads” (if there are multiple ones) would get the
id `0`.
- Because that means that `isMainThread === (threadId === 0)` no longer
holds, refactor `isMainThread` into a separate entity. Implement it
in a way that allows for future extensibility, because we use
`isMainThread` in multiple different ways (determining whether there
is a parent thread; determining whether the current thread has control
of the current process; etc.).
PR-URL: https://github.com/nodejs/node/pull/25796
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Diffstat (limited to 'src/env.h')
-rw-r--r-- | src/env.h | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -595,6 +595,11 @@ class Environment { DISALLOW_COPY_AND_ASSIGN(TickInfo); }; + enum Flags { + kNoFlags = 0, + kIsMainThread = 1 + }; + static inline Environment* GetCurrent(v8::Isolate* isolate); static inline Environment* GetCurrent(v8::Local<v8::Context> context); static inline Environment* GetCurrent( @@ -608,7 +613,8 @@ class Environment { static inline Environment* GetThreadLocalEnv(); Environment(IsolateData* isolate_data, - v8::Local<v8::Context> context); + v8::Local<v8::Context> context, + Flags flags = Flags()); ~Environment(); void Start(bool start_profiler_idle_notifier); @@ -761,7 +767,6 @@ class Environment { inline bool is_main_thread() const; inline uint64_t thread_id() const; - inline void set_thread_id(uint64_t id); inline worker::Worker* worker_context() const; inline void set_worker_context(worker::Worker* context); inline void add_sub_worker_context(worker::Worker* context); @@ -1005,7 +1010,8 @@ class Environment { bool has_run_bootstrapping_code_ = false; bool can_call_into_js_ = true; - uint64_t thread_id_ = 0; + Flags flags_; + uint64_t thread_id_; std::unordered_set<worker::Worker*> sub_worker_contexts_; static void* const kNodeContextTagPtr; |