core: Use a global lock instead of runtime lock for os::getenv, etc. #4726

This commit is contained in:
Brian Anderson
2013-05-08 15:26:07 -07:00
parent 36ad366519
commit f6401bad24
4 changed files with 35 additions and 14 deletions

View File

@@ -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);
}