about summary refs log tree commit diff
path: root/src/rt/rust_builtin.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-10-05 15:41:35 -0700
committerbors <bors@rust-lang.org>2013-10-05 15:41:35 -0700
commitbf416e7daf533fd4eb6f270da3ab965ac7422f05 (patch)
tree34399950e063772b48aa29ea18ff7f61e38bcf08 /src/rt/rust_builtin.cpp
parent2733b189ac60cea541fbf80e5839e5027ffc9fbf (diff)
parent1d19ad97871d22fb26a6ba0856d106546da8612d (diff)
downloadrust-bf416e7daf533fd4eb6f270da3ab965ac7422f05.tar.gz
rust-bf416e7daf533fd4eb6f270da3ab965ac7422f05.zip
auto merge of #9713 : sfackler/rust/dynamic_lib, r=alexcrichton
The root issue is that dlerror isn't reentrant or even thread safe.

The solution implemented here is to make a yielding spin lock over an
AtomicFlag. This is pretty hacky, but the best we can do at this point.
As far as I can tell, it isn't possible to create a global mutex without
having to initialize it in a single threaded context.

The Windows code isn't affected since errno is thread-local on Windows
and it's running in an atomically block to ensure there isn't a green
thread context switch.

Closes #8156
Diffstat (limited to 'src/rt/rust_builtin.cpp')
-rw-r--r--src/rt/rust_builtin.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index eeb0c95337a..34d1efd577d 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -609,6 +609,18 @@ rust_drop_linenoise_lock() {
     linenoise_lock.unlock();
 }
 
+static lock_and_signal dlerror_lock;
+
+extern "C" CDECL void
+rust_take_dlerror_lock() {
+    dlerror_lock.lock();
+}
+
+extern "C" CDECL void
+rust_drop_dlerror_lock() {
+    dlerror_lock.unlock();
+}
+
 extern "C" CDECL unsigned int
 rust_valgrind_stack_register(void *start, void *end) {
   return VALGRIND_STACK_REGISTER(start, end);