diff options
| author | bors <bors@rust-lang.org> | 2013-11-18 21:51:31 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-11-18 21:51:31 -0800 |
| commit | f5f5d5aac762a554850d291165536ba752260303 (patch) | |
| tree | 56afc4b9b834d4496c175a3ab701823dbba72e15 /src/libstd/task | |
| parent | ab7fe9dd06e93986f6b11512031c891059474653 (diff) | |
| parent | 508b7b996e5d557ec1c49e1d11563ecf4fc9d287 (diff) | |
| download | rust-f5f5d5aac762a554850d291165536ba752260303.tar.gz rust-f5f5d5aac762a554850d291165536ba752260303.zip | |
auto merge of #10479 : alexcrichton/rust/native-mutex.rs, r=cmr
This adds a new `std::unstable::mutex` module which contains bindings to the platform-provided mutexes. This module is pretty much entirely unsafe to use, but is critical for the runtime and dropping our C++ dependency. The actual implementation is to do a compare-and-swap on an initially uninitialized pointer. Pthreads does allow for static initialization, so this wouldn't be necessary if we had all the proper headers and whatnot, but windows it looks like will always require some sort of compare-and-swap operation. For now, I didn't want to have to define all the pthreads headers, so I continue to just malloc the pthreads lock/cvar. After this, there's only one remaining C++ component of rust, and that's unwinding.
Diffstat (limited to 'src/libstd/task')
| -rw-r--r-- | src/libstd/task/mod.rs | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index 51c11b69972..5a2251eaa46 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -1141,22 +1141,10 @@ fn test_spawn_sched_childs_on_default_sched() { po.recv(); } -#[cfg(test)] -mod testrt { - use libc; - - extern { - pub fn rust_dbg_lock_create() -> *libc::c_void; - pub fn rust_dbg_lock_destroy(lock: *libc::c_void); - pub fn rust_dbg_lock_lock(lock: *libc::c_void); - pub fn rust_dbg_lock_unlock(lock: *libc::c_void); - pub fn rust_dbg_lock_wait(lock: *libc::c_void); - pub fn rust_dbg_lock_signal(lock: *libc::c_void); - } -} - #[test] fn test_spawn_sched_blocking() { + use unstable::mutex::Mutex; + unsafe { // Testing that a task in one scheduler can block in foreign code @@ -1165,16 +1153,18 @@ fn test_spawn_sched_blocking() { let (start_po, start_ch) = stream(); let (fin_po, fin_ch) = stream(); - let lock = testrt::rust_dbg_lock_create(); + let mut lock = Mutex::new(); + let lock2 = Cell::new(lock.clone()); do spawn_sched(SingleThreaded) { - testrt::rust_dbg_lock_lock(lock); + let mut lock = lock2.take(); + lock.lock(); start_ch.send(()); // Block the scheduler thread - testrt::rust_dbg_lock_wait(lock); - testrt::rust_dbg_lock_unlock(lock); + lock.wait(); + lock.unlock(); fin_ch.send(()); }; @@ -1201,11 +1191,11 @@ fn test_spawn_sched_blocking() { let child_ch = setup_po.recv(); child_ch.send(20); pingpong(&parent_po, &child_ch); - testrt::rust_dbg_lock_lock(lock); - testrt::rust_dbg_lock_signal(lock); - testrt::rust_dbg_lock_unlock(lock); + lock.lock(); + lock.signal(); + lock.unlock(); fin_po.recv(); - testrt::rust_dbg_lock_destroy(lock); + lock.destroy(); } } } |
