File tree Expand file tree Collapse file tree 4 files changed +35
-14
lines changed Expand file tree Collapse file tree 4 files changed +35
-14
lines changed Original file line number Diff line number Diff line change @@ -147,23 +147,25 @@ pub mod win32 {
147
147
148
148
/*
149
149
Accessing environment variables is not generally threadsafe.
150
- This uses a per-runtime lock to serialize access.
151
- FIXME #4726: It would probably be appropriate to make this a real global
150
+ Serialize access through a global lock.
152
151
*/
153
152
fn with_env_lock < T > ( f : & fn ( ) -> T ) -> T {
154
- use unstable:: global:: global_data_clone_create;
155
- use unstable:: sync:: { Exclusive , exclusive} ;
156
-
157
- struct SharedValue ( ( ) ) ;
158
- type ValueMutex = Exclusive < SharedValue > ;
159
- fn key ( _: ValueMutex ) { }
153
+ use unstable:: finally:: Finally ;
160
154
161
155
unsafe {
162
- let lock: ValueMutex = global_data_clone_create ( key, || {
163
- ~exclusive ( SharedValue ( ( ) ) )
164
- } ) ;
156
+ return do ( || {
157
+ rust_take_env_lock ( ) ;
158
+ f ( )
159
+ } ) . finally {
160
+ rust_drop_env_lock ( ) ;
161
+ } ;
162
+ }
165
163
166
- lock. with_imm ( |_| f ( ) )
164
+ extern {
165
+ #[ fast_ffi]
166
+ fn rust_take_env_lock ( ) ;
167
+ #[ fast_ffi]
168
+ fn rust_drop_env_lock ( ) ;
167
169
}
168
170
}
169
171
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 @@ -235,4 +235,7 @@ rust_begin_unwind
235
235
rust_take_task_borrow_list
236
236
rust_set_task_borrow_list
237
237
rust_valgrind_stack_register
238
- rust_valgrind_stack_deregister
238
+ rust_valgrind_stack_deregister
239
+ rust_take_env_lock
240
+ rust_drop_env_lock
241
+
You can’t perform that action at this time.
0 commit comments