diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-01-01 13:56:53 +0800 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-01-08 00:28:16 +0100 |
commit | 9db9e7e541c1ff9a30b7f1b61c6d3a7b6d30fab3 (patch) | |
tree | f16cfd671dd32467ae0cc221335118733c09030a /src/node_env_var.cc | |
parent | ae2d1f0e05449221ee770a393e5c967b359d9b1b (diff) | |
download | node-new-9db9e7e541c1ff9a30b7f1b61c6d3a7b6d30fab3.tar.gz |
src: move per-process global variables into node::per_process
So that it's easier to tell whether we are manipulating per-process
global states that may need to be treated with care to avoid races.
Also added comments about these variables and moved some of them
to a more suitable compilation unit:
- Move `v8_initialized` to `util.h` since it's only used in
`util.cc` and `node.cc`
- Rename `process_mutex` to `tty_mutex` and move it into
`node_errors.cc` since that's the only place it's used
to guard the tty.
- Move `per_process_opts_mutex` and `per_process_opts`
into `node_options.h` and rename them to
`per_process::cli_options[_mutex]`
- Rename `node_isolate[_mutex]` to `per_process::main_isolate[_mutex]`
PR-URL: https://github.com/nodejs/node/pull/25302
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/node_env_var.cc')
-rw-r--r-- | src/node_env_var.cc | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/node_env_var.cc b/src/node_env_var.cc index de0991bcab..8cbfa22973 100644 --- a/src/node_env_var.cc +++ b/src/node_env_var.cc @@ -25,13 +25,17 @@ using v8::PropertyCallbackInfo; using v8::String; using v8::Value; +namespace per_process { +Mutex env_var_mutex; +} // namespace per_process + static void EnvGetter(Local<Name> property, const PropertyCallbackInfo<Value>& info) { Isolate* isolate = info.GetIsolate(); if (property->IsSymbol()) { return info.GetReturnValue().SetUndefined(); } - Mutex::ScopedLock lock(environ_mutex); + Mutex::ScopedLock lock(per_process::env_var_mutex); #ifdef __POSIX__ node::Utf8Value key(isolate, property); const char* val = getenv(*key); @@ -80,7 +84,7 @@ static void EnvSetter(Local<Name> property, return; } - Mutex::ScopedLock lock(environ_mutex); + Mutex::ScopedLock lock(per_process::env_var_mutex); #ifdef __POSIX__ node::Utf8Value key(info.GetIsolate(), property); node::Utf8Value val(info.GetIsolate(), value); @@ -100,7 +104,7 @@ static void EnvSetter(Local<Name> property, static void EnvQuery(Local<Name> property, const PropertyCallbackInfo<Integer>& info) { - Mutex::ScopedLock lock(environ_mutex); + Mutex::ScopedLock lock(per_process::env_var_mutex); int32_t rc = -1; // Not found unless proven otherwise. if (property->IsString()) { #ifdef __POSIX__ @@ -127,7 +131,7 @@ static void EnvQuery(Local<Name> property, static void EnvDeleter(Local<Name> property, const PropertyCallbackInfo<Boolean>& info) { - Mutex::ScopedLock lock(environ_mutex); + Mutex::ScopedLock lock(per_process::env_var_mutex); if (property->IsString()) { #ifdef __POSIX__ node::Utf8Value key(info.GetIsolate(), property); @@ -148,7 +152,7 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) { Environment* env = Environment::GetCurrent(info); Isolate* isolate = env->isolate(); - Mutex::ScopedLock lock(environ_mutex); + Mutex::ScopedLock lock(per_process::env_var_mutex); Local<Array> envarr; int env_size = 0; #ifdef __POSIX__ |