File tree Expand file tree Collapse file tree 3 files changed +32
-12
lines changed Expand file tree Collapse file tree 3 files changed +32
-12
lines changed Original file line number Diff line number Diff line change @@ -148,23 +148,25 @@ pub mod win32 {
148
148
149
149
/*
150
150
Accessing environment variables is not generally threadsafe.
151
- This uses a per-runtime lock to serialize access.
152
- FIXME #4726: It would probably be appropriate to make this a real global
151
+ Serialize access through a global lock.
153
152
*/
154
153
fn with_env_lock < T > ( f : & fn ( ) -> T ) -> T {
155
- use unstable:: global:: global_data_clone_create;
156
- use unstable:: { Exclusive , exclusive} ;
157
-
158
- struct SharedValue ( ( ) ) ;
159
- type ValueMutex = Exclusive < SharedValue > ;
160
- fn key ( _: ValueMutex ) { }
154
+ use unstable:: finally:: Finally ;
161
155
162
156
unsafe {
163
- let lock: ValueMutex = global_data_clone_create ( key, || {
164
- ~exclusive ( SharedValue ( ( ) ) )
165
- } ) ;
157
+ return do ( || {
158
+ rust_take_env_lock ( ) ;
159
+ f ( )
160
+ } ) . finally {
161
+ rust_drop_env_lock ( ) ;
162
+ } ;
163
+ }
166
164
167
- lock. with_imm ( |_| f ( ) )
165
+ extern {
166
+ #[ fast_ffi]
167
+ fn rust_take_env_lock ( ) ;
168
+ #[ fast_ffi]
169
+ fn rust_drop_env_lock ( ) ;
168
170
}
169
171
}
170
172
Original file line number Diff line number Diff line change 13
13
// that might come from the environment is loaded here, once, during
14
14
// init.
15
15
16
+ #include " sync/lock_and_signal.h"
16
17
#include " rust_env.h"
17
18
18
19
// The environment variables that the runtime knows about
26
27
#define RUST_DEBUG_MEM " RUST_DEBUG_MEM"
27
28
#define RUST_DEBUG_BORROW " RUST_DEBUG_BORROW"
28
29
30
+ static lock_and_signal env_lock;
31
+
32
+ extern " C" CDECL void
33
+ rust_take_env_lock () {
34
+ env_lock.lock ();
35
+ }
36
+
37
+ extern " C" CDECL void
38
+ rust_drop_env_lock () {
39
+ env_lock.unlock ();
40
+ }
41
+
29
42
#if defined(__WIN32__)
30
43
static int
31
44
get_num_cpus () {
@@ -119,6 +132,8 @@ copyenv(const char* name) {
119
132
120
133
rust_env*
121
134
load_env (int argc, char **argv) {
135
+ scoped_lock with (env_lock);
136
+
122
137
rust_env *env = (rust_env*)malloc (sizeof (rust_env));
123
138
124
139
env->num_sched_threads = (size_t )get_num_threads ();
@@ -141,3 +156,4 @@ free_env(rust_env *env) {
141
156
free (env->rust_seed );
142
157
free (env);
143
158
}
159
+
Original file line number Diff line number Diff line change @@ -234,3 +234,5 @@ rust_try
234
234
rust_begin_unwind
235
235
rust_take_task_borrow_list
236
236
rust_set_task_borrow_list
237
+ rust_take_env_lock
238
+ rust_drop_env_lock
You can’t perform that action at this time.
0 commit comments