core: Use a global lock instead of runtime lock for os::getenv, etc. #4726
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
// that might come from the environment is loaded here, once, during
|
||||
// init.
|
||||
|
||||
#include "sync/lock_and_signal.h"
|
||||
#include "rust_env.h"
|
||||
|
||||
// The environment variables that the runtime knows about
|
||||
@@ -26,6 +27,18 @@
|
||||
#define RUST_DEBUG_MEM "RUST_DEBUG_MEM"
|
||||
#define RUST_DEBUG_BORROW "RUST_DEBUG_BORROW"
|
||||
|
||||
static lock_and_signal env_lock;
|
||||
|
||||
extern "C" CDECL void
|
||||
rust_take_env_lock() {
|
||||
env_lock.lock();
|
||||
}
|
||||
|
||||
extern "C" CDECL void
|
||||
rust_drop_env_lock() {
|
||||
env_lock.unlock();
|
||||
}
|
||||
|
||||
#if defined(__WIN32__)
|
||||
static int
|
||||
get_num_cpus() {
|
||||
@@ -119,6 +132,8 @@ copyenv(const char* name) {
|
||||
|
||||
rust_env*
|
||||
load_env(int argc, char **argv) {
|
||||
scoped_lock with(env_lock);
|
||||
|
||||
rust_env *env = (rust_env*)malloc(sizeof(rust_env));
|
||||
|
||||
env->num_sched_threads = (size_t)get_num_threads();
|
||||
@@ -141,3 +156,4 @@ free_env(rust_env *env) {
|
||||
free(env->rust_seed);
|
||||
free(env);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user