@@ -187,7 +187,8 @@ static int v8_thread_pool_size = v8_default_thread_pool_size;
187
187
static bool prof_process = false ;
188
188
static bool v8_is_profiling = false ;
189
189
static bool node_is_initialized = false ;
190
- static node_module* modpending;
190
+ static uv_once_t init_modpending_once = UV_ONCE_INIT;
191
+ static uv_key_t thread_local_modpending;
191
192
static node_module* modlist_builtin;
192
193
static node_module* modlist_internal;
193
194
static node_module* modlist_linked;
@@ -1253,7 +1254,7 @@ extern "C" void node_module_register(void* m) {
1253
1254
mp->nm_link = modlist_linked;
1254
1255
modlist_linked = mp;
1255
1256
} else {
1256
- modpending = mp ;
1257
+ uv_key_set (&thread_local_modpending, mp) ;
1257
1258
}
1258
1259
}
1259
1260
@@ -1367,6 +1368,10 @@ inline napi_addon_register_func GetNapiInitializerCallback(DLib* dlib) {
1367
1368
reinterpret_cast <napi_addon_register_func>(dlib->GetSymbolAddress (name));
1368
1369
}
1369
1370
1371
+ void InitModpendingOnce () {
1372
+ CHECK_EQ (0 , uv_key_create (&thread_local_modpending));
1373
+ }
1374
+
1370
1375
// DLOpen is process.dlopen(module, filename, flags).
1371
1376
// Used to load 'module.node' dynamically shared objects.
1372
1377
//
@@ -1377,7 +1382,8 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) {
1377
1382
Environment* env = Environment::GetCurrent (args);
1378
1383
auto context = env->context ();
1379
1384
1380
- CHECK_NULL (modpending);
1385
+ uv_once (&init_modpending_once, InitModpendingOnce);
1386
+ CHECK_NULL (uv_key_get (&thread_local_modpending));
1381
1387
1382
1388
if (args.Length () < 2 ) {
1383
1389
env->ThrowError (" process.dlopen needs at least 2 arguments." );
@@ -1405,8 +1411,9 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) {
1405
1411
// Objects containing v14 or later modules will have registered themselves
1406
1412
// on the pending list. Activate all of them now. At present, only one
1407
1413
// module per object is supported.
1408
- node_module* const mp = modpending;
1409
- modpending = nullptr ;
1414
+ node_module* const mp = static_cast <node_module*>(
1415
+ uv_key_get (&thread_local_modpending));
1416
+ uv_key_set (&thread_local_modpending, nullptr );
1410
1417
1411
1418
if (!is_opened) {
1412
1419
Local<String> errmsg = OneByteString (env->isolate (), dlib.errmsg_ .c_str ());
0 commit comments