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