mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
src: move worker_context from Environment to IsolateData
Workers are fully in control of their Isolates, and this helps avoid a problem with later changes to `CreateEnvironment()` because now we can run the boostrapping code inside the latter. PR-URL: https://github.com/nodejs/node/pull/30467 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This commit is contained in:
parent
288382a4ce
commit
64c01222d9
@ -64,6 +64,15 @@ inline MultiIsolatePlatform* IsolateData::platform() const {
|
||||
return platform_;
|
||||
}
|
||||
|
||||
inline void IsolateData::set_worker_context(worker::Worker* context) {
|
||||
CHECK_NULL(worker_context_); // Should be set only once.
|
||||
worker_context_ = context;
|
||||
}
|
||||
|
||||
inline worker::Worker* IsolateData::worker_context() const {
|
||||
return worker_context_;
|
||||
}
|
||||
|
||||
inline AsyncHooks::AsyncHooks()
|
||||
: async_ids_stack_(env()->isolate(), 16 * 2),
|
||||
fields_(env()->isolate(), kFieldsCount),
|
||||
@ -904,12 +913,7 @@ inline uint64_t Environment::thread_id() const {
|
||||
}
|
||||
|
||||
inline worker::Worker* Environment::worker_context() const {
|
||||
return worker_context_;
|
||||
}
|
||||
|
||||
inline void Environment::set_worker_context(worker::Worker* context) {
|
||||
CHECK_NULL(worker_context_); // Should be set only once.
|
||||
worker_context_ = context;
|
||||
return isolate_data()->worker_context();
|
||||
}
|
||||
|
||||
inline void Environment::add_sub_worker_context(worker::Worker* context) {
|
||||
|
@ -970,7 +970,7 @@ void Environment::Exit(int exit_code) {
|
||||
DisposePlatform();
|
||||
exit(exit_code);
|
||||
} else {
|
||||
worker_context_->Exit(exit_code);
|
||||
worker_context()->Exit(exit_code);
|
||||
}
|
||||
}
|
||||
|
||||
@ -984,8 +984,8 @@ void Environment::stop_sub_worker_contexts() {
|
||||
}
|
||||
|
||||
Environment* Environment::worker_parent_env() const {
|
||||
if (worker_context_ == nullptr) return nullptr;
|
||||
return worker_context_->env();
|
||||
if (worker_context() == nullptr) return nullptr;
|
||||
return worker_context()->env();
|
||||
}
|
||||
|
||||
void MemoryTracker::TrackField(const char* edge_name,
|
||||
|
@ -496,6 +496,9 @@ class IsolateData : public MemoryRetainer {
|
||||
inline v8::ArrayBuffer::Allocator* allocator() const;
|
||||
inline NodeArrayBufferAllocator* node_allocator() const;
|
||||
|
||||
inline worker::Worker* worker_context() const;
|
||||
inline void set_worker_context(worker::Worker* context);
|
||||
|
||||
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
|
||||
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName)
|
||||
#define VS(PropertyName, StringValue) V(v8::String, PropertyName)
|
||||
@ -540,6 +543,7 @@ class IsolateData : public MemoryRetainer {
|
||||
const bool uses_node_allocator_;
|
||||
MultiIsolatePlatform* platform_;
|
||||
std::shared_ptr<PerIsolateOptions> options_;
|
||||
worker::Worker* worker_context_ = nullptr;
|
||||
};
|
||||
|
||||
struct ContextInfo {
|
||||
@ -1057,7 +1061,6 @@ class Environment : public MemoryRetainer {
|
||||
inline uint64_t thread_id() const;
|
||||
inline worker::Worker* worker_context() const;
|
||||
Environment* worker_parent_env() const;
|
||||
inline void set_worker_context(worker::Worker* context);
|
||||
inline void add_sub_worker_context(worker::Worker* context);
|
||||
inline void remove_sub_worker_context(worker::Worker* context);
|
||||
void stop_sub_worker_contexts();
|
||||
@ -1378,8 +1381,6 @@ class Environment : public MemoryRetainer {
|
||||
std::vector<std::unique_ptr<fs::FileHandleReadWrap>>
|
||||
file_handle_read_wrap_freelist_;
|
||||
|
||||
worker::Worker* worker_context_ = nullptr;
|
||||
|
||||
std::list<node_module> extra_linked_bindings_;
|
||||
Mutex extra_linked_bindings_mutex_;
|
||||
|
||||
|
@ -183,6 +183,7 @@ class WorkerThreadData {
|
||||
CHECK(isolate_data_);
|
||||
if (w_->per_isolate_opts_)
|
||||
isolate_data_->set_options(std::move(w_->per_isolate_opts_));
|
||||
isolate_data_->set_worker_context(w_);
|
||||
}
|
||||
|
||||
Mutex::ScopedLock lock(w_->mutex_);
|
||||
@ -317,7 +318,6 @@ void Worker::Run() {
|
||||
CHECK_NOT_NULL(env_);
|
||||
env_->set_env_vars(std::move(env_vars_));
|
||||
env_->set_abort_on_uncaught_exception(false);
|
||||
env_->set_worker_context(this);
|
||||
|
||||
env_->InitializeLibuv(start_profiler_idle_notifier_);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user