mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
embedding: make Stop() stop Workers
This makes sense given that terminating execution of the parent thread this way likely also is supposed to stop all running Worker threads spawned by it. PR-URL: https://github.com/nodejs/node/pull/32531 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
@@ -725,8 +725,7 @@ ThreadId AllocateEnvironmentThreadId() {
|
||||
}
|
||||
|
||||
void DefaultProcessExitHandler(Environment* env, int exit_code) {
|
||||
env->set_can_call_into_js(false);
|
||||
env->stop_sub_worker_contexts();
|
||||
Stop(env);
|
||||
DisposePlatform();
|
||||
exit(exit_code);
|
||||
}
|
||||
|
||||
@@ -501,9 +501,10 @@ void Environment::InitializeLibuv(bool start_profiler_idle_notifier) {
|
||||
}
|
||||
}
|
||||
|
||||
void Environment::ExitEnv() {
|
||||
void Environment::Stop() {
|
||||
set_can_call_into_js(false);
|
||||
set_stopping(true);
|
||||
stop_sub_worker_contexts();
|
||||
isolate_->TerminateExecution();
|
||||
SetImmediateThreadsafe([](Environment* env) { uv_stop(env->event_loop()); });
|
||||
}
|
||||
|
||||
@@ -897,7 +897,7 @@ class Environment : public MemoryRetainer {
|
||||
void RegisterHandleCleanups();
|
||||
void CleanupHandles();
|
||||
void Exit(int code);
|
||||
void ExitEnv();
|
||||
void Stop();
|
||||
|
||||
// Register clean-up cb to be called on environment destruction.
|
||||
inline void RegisterHandleCleanup(uv_handle_t* handle,
|
||||
|
||||
@@ -1059,7 +1059,7 @@ int Start(int argc, char** argv) {
|
||||
}
|
||||
|
||||
int Stop(Environment* env) {
|
||||
env->ExitEnv();
|
||||
env->Stop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -224,7 +224,8 @@ class Environment;
|
||||
NODE_EXTERN int Start(int argc, char* argv[]);
|
||||
|
||||
// Tear down Node.js while it is running (there are active handles
|
||||
// in the loop and / or actively executing JavaScript code).
|
||||
// in the loop and / or actively executing JavaScript code). This also stops
|
||||
// all Workers that may have been started earlier.
|
||||
NODE_EXTERN int Stop(Environment* env);
|
||||
|
||||
// TODO(addaleax): Officially deprecate this and replace it with something
|
||||
@@ -478,8 +479,8 @@ NODE_EXTERN void FreeEnvironment(Environment* env);
|
||||
// It receives the Environment* instance and the exit code as arguments.
|
||||
// This could e.g. call Stop(env); in order to terminate execution and stop
|
||||
// the event loop.
|
||||
// The default handler disposes of the global V8 platform instance, if one is
|
||||
// being used, and calls exit().
|
||||
// The default handler calls Stop(), disposes of the global V8 platform
|
||||
// instance, if one is being used, and calls exit().
|
||||
NODE_EXTERN void SetProcessExitHandler(
|
||||
Environment* env,
|
||||
std::function<void(Environment*, int)>&& handler);
|
||||
|
||||
Reference in New Issue
Block a user