summaryrefslogtreecommitdiff
path: root/src/node_binding.cc
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2019-06-27 12:52:28 -0700
committerGabriel Schulhof <gabriel.schulhof@intel.com>2019-07-02 16:14:59 -0700
commitd3b10f66bd4943f7da9aa25415ea6900d7f48086 (patch)
tree540403c27b7c2146ef12ffaca5e8dfa90965584b /src/node_binding.cc
parent3ab457ec15a1aa54c8563f0416358c16fc32dce4 (diff)
downloadandroid-node-v8-d3b10f66bd4943f7da9aa25415ea6900d7f48086.tar.gz
android-node-v8-d3b10f66bd4943f7da9aa25415ea6900d7f48086.tar.bz2
android-node-v8-d3b10f66bd4943f7da9aa25415ea6900d7f48086.zip
src: use thread_local to declare modpending
The pointer used to hold an incoming dynamically loaded module's `node::node_module` structure needs to be thread-local. So far this was done with `uv_key_set()` and `uv_key_get()`. The language now supports the `thread_local` keyword which makes implementing this a lot cleaner. PR-URL: https://github.com/nodejs/node/pull/28456 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/node_binding.cc')
-rw-r--r--src/node_binding.cc17
1 files changed, 5 insertions, 12 deletions
diff --git a/src/node_binding.cc b/src/node_binding.cc
index 99c2406036..c51a892e1b 100644
--- a/src/node_binding.cc
+++ b/src/node_binding.cc
@@ -243,8 +243,7 @@ using v8::Value;
// Globals per process
static node_module* modlist_internal;
static node_module* modlist_linked;
-static uv_once_t init_modpending_once = UV_ONCE_INIT;
-static uv_key_t thread_local_modpending;
+static thread_local node_module* thread_local_modpending;
// This is set by node::Init() which is used by embedders
bool node_is_initialized = false;
@@ -262,7 +261,7 @@ extern "C" void node_module_register(void* m) {
mp->nm_link = modlist_linked;
modlist_linked = mp;
} else {
- uv_key_set(&thread_local_modpending, mp);
+ thread_local_modpending = mp;
}
}
@@ -406,10 +405,6 @@ inline napi_addon_register_func GetNapiInitializerCallback(DLib* dlib) {
dlib->GetSymbolAddress(name));
}
-void InitModpendingOnce() {
- CHECK_EQ(0, uv_key_create(&thread_local_modpending));
-}
-
// DLOpen is process.dlopen(module, filename, flags).
// Used to load 'module.node' dynamically shared objects.
//
@@ -420,8 +415,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
auto context = env->context();
- uv_once(&init_modpending_once, InitModpendingOnce);
- CHECK_NULL(uv_key_get(&thread_local_modpending));
+ CHECK_NULL(thread_local_modpending);
if (args.Length() < 2) {
env->ThrowError("process.dlopen needs at least 2 arguments.");
@@ -452,9 +446,8 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
// Objects containing v14 or later modules will have registered themselves
// on the pending list. Activate all of them now. At present, only one
// module per object is supported.
- node_module* mp =
- static_cast<node_module*>(uv_key_get(&thread_local_modpending));
- uv_key_set(&thread_local_modpending, nullptr);
+ node_module* mp = thread_local_modpending;
+ thread_local_modpending = nullptr;
if (!is_opened) {
Local<String> errmsg =