diff --git a/mk/rt.mk b/mk/rt.mk index afd5bc530ab3..f51c7b1caefd 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -71,7 +71,6 @@ RUNTIME_CS_$(1) := \ rt/rust_cc.cpp \ rt/rust_debug.cpp \ rt/rust_box_annihilator.cpp \ - rt/rust_cond_lock.cpp \ rt/memory_region.cpp \ rt/boxed_region.cpp \ rt/arch/$$(HOST_$(1))/context.cpp \ diff --git a/src/libcore/arc.rs b/src/libcore/arc.rs index d382ca55e0b3..c84db57bd399 100644 --- a/src/libcore/arc.rs +++ b/src/libcore/arc.rs @@ -83,11 +83,11 @@ fn clone(rc: &arc) -> arc { } // An arc over mutable data that is protected by a lock. -type ex_data = {lock: sys::lock_and_signal, mut data: T}; +type ex_data = {lock: sys::little_lock, mut data: T}; type exclusive = arc_destruct>; fn exclusive(-data: T) -> exclusive { - let data = ~{mut count: 1, data: {lock: sys::lock_and_signal(), + let data = ~{mut count: 1, data: {lock: sys::little_lock(), data: data}}; unsafe { let ptr = unsafe::reinterpret_cast(data); @@ -126,13 +126,13 @@ impl methods for exclusive { * will guarantee a memory leak of all involved ARCs. Using exclusive * ARCs inside of other ARCs is safe in absence of circular references. */ - unsafe fn with(f: fn(sys::condition, x: &mut T) -> U) -> U { + unsafe fn with(f: fn(x: &mut T) -> U) -> U { let ptr: ~arc_data> = unsafe::reinterpret_cast(self.data); assert ptr.count > 0; let r = { let rec: &ex_data = &(*ptr).data; - rec.lock.lock_cond(|c| f(c, &mut rec.data)) + do rec.lock.lock { f(&mut rec.data) } }; unsafe::forget(ptr); r @@ -184,7 +184,7 @@ mod tests { let total = total.clone(); futures += ~[future::spawn(|| { for uint::range(0u, count) |_i| { - do total.with |_cond, count| { + do total.with |count| { **count += 1u; } } @@ -193,7 +193,7 @@ mod tests { for futures.each |f| { f.get() } - do total.with |_cond, total| { + do total.with |total| { assert **total == num_tasks * count }; } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 9bdff8292640..0d684a99cbaa 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -1027,7 +1027,7 @@ type shared_chan = arc::exclusive>; impl chan of channel for shared_chan { fn send(+x: T) { let mut xx = some(x); - do self.with |_c, chan| { + do self.with |chan| { let mut x = none; x <-> xx; chan.send(option::unwrap(x)) diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index f0075d841898..879865a988a1 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -7,7 +7,7 @@ export min_align_of; export pref_align_of; export refcount; export log_str; -export lock_and_signal, condition, methods; +export little_lock, methods; export shape_eq, shape_lt, shape_le; import task::atomically; @@ -18,18 +18,16 @@ enum type_desc = { // Remaining fields not listed }; -type rust_cond_lock = *libc::c_void; +type rust_little_lock = *libc::c_void; #[abi = "cdecl"] extern mod rustrt { pure fn shape_log_str(t: *sys::type_desc, data: *()) -> ~str; - fn rust_create_cond_lock() -> rust_cond_lock; - fn rust_destroy_cond_lock(lock: rust_cond_lock); - fn rust_lock_cond_lock(lock: rust_cond_lock); - fn rust_unlock_cond_lock(lock: rust_cond_lock); - fn rust_wait_cond_lock(lock: rust_cond_lock); - fn rust_signal_cond_lock(lock: rust_cond_lock) -> bool; + fn rust_create_little_lock() -> rust_little_lock; + fn rust_destroy_little_lock(lock: rust_little_lock); + fn rust_lock_little_lock(lock: rust_little_lock); + fn rust_unlock_little_lock(lock: rust_little_lock); } #[abi = "rust-intrinsic"] @@ -100,50 +98,28 @@ pure fn log_str(t: T) -> ~str { } } -class lock_and_signal { - let lock: rust_cond_lock; +class little_lock { + let l: rust_little_lock; new() { - self.lock = rustrt::rust_create_cond_lock(); + self.l = rustrt::rust_create_little_lock(); } - drop { rustrt::rust_destroy_cond_lock(self.lock); } + drop { rustrt::rust_destroy_little_lock(self.l); } } -enum condition { - condition_(rust_cond_lock) -} - -class unlock { - let lock: rust_cond_lock; - new(lock: rust_cond_lock) { self.lock = lock; } - drop { rustrt::rust_unlock_cond_lock(self.lock); } -} - -impl methods for lock_and_signal { +impl methods for little_lock { unsafe fn lock(f: fn() -> T) -> T { + class unlock { + let l: rust_little_lock; + new(l: rust_little_lock) { self.l = l; } + drop { rustrt::rust_unlock_little_lock(self.l); } + } + do atomically { - rustrt::rust_lock_cond_lock(self.lock); - let _r = unlock(self.lock); + rustrt::rust_lock_little_lock(self.l); + let _r = unlock(self.l); f() } } - - unsafe fn lock_cond(f: fn(condition) -> T) -> T { - do atomically { - rustrt::rust_lock_cond_lock(self.lock); - let _r = unlock(self.lock); - f(condition_(self.lock)) - } - } -} - -impl methods for condition { - fn wait() { - rustrt::rust_wait_cond_lock(*self); - } - - fn signal() -> bool { - rustrt::rust_signal_cond_lock(*self) - } } #[cfg(test)] @@ -193,27 +169,6 @@ mod tests { assert pref_align_of::() == 8u; assert pref_align_of::<*uint>() == 8u; } - - #[test] - #[ignore] // this can go into infinite loops - fn condition_variable() { - let lock = arc::arc(lock_and_signal()); - let lock2 = arc::clone(&lock); - - do task::spawn |move lock2| { - let lock = arc::get(&lock2); - do (*lock).lock_cond |c| { - c.wait(); - } - } - - let mut signaled = false; - while !signaled { - do (*arc::get(&lock)).lock_cond |c| { - signaled = c.signal() - } - } - } } // Local Variables: diff --git a/src/libcore/task.rs b/src/libcore/task.rs index c066e7d6f511..04882373b372 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -740,12 +740,12 @@ enum ancestor_list = option>; // Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety. #[inline(always)] fn access_group(x: taskgroup_arc, blk: fn(taskgroup_inner) -> U) -> U { - unsafe { x.with(|_c, tg| blk(tg)) } + unsafe { x.with(blk) } } #[inline(always)] fn access_ancestors(x: arc::exclusive, blk: fn(x: &mut ancestor_node) -> U) -> U { - unsafe { x.with(|_c, nobe| blk(nobe)) } + unsafe { x.with(blk) } } // Iterates over an ancestor list. diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 1ba941c233ca..465eb6efe384 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -7,7 +7,6 @@ #include "sync/timer.h" #include "rust_abi.h" #include "rust_port.h" -#include "rust_cond_lock.h" #include @@ -882,56 +881,24 @@ bool rust_task_is_unwinding(rust_task *rt) { return rt->unwinding; } -extern "C" rust_cond_lock* -rust_create_cond_lock() { - return new rust_cond_lock(); +extern "C" lock_and_signal* +rust_create_little_lock() { + return new lock_and_signal(); } extern "C" void -rust_destroy_cond_lock(rust_cond_lock *lock) { +rust_destroy_little_lock(lock_and_signal *lock) { delete lock; } extern "C" void -rust_lock_cond_lock(rust_cond_lock *lock) { - lock->lock.lock(); +rust_lock_little_lock(lock_and_signal *lock) { + lock->lock(); } extern "C" void -rust_unlock_cond_lock(rust_cond_lock *lock) { - lock->lock.unlock(); -} - -// The next two functions do not use the built in condition variable features -// because the Rust schedule is not aware of them, and they can block the -// scheduler thread. - -extern "C" void -rust_wait_cond_lock(rust_cond_lock *lock) { - assert(false && "condition->wait() is totally broken! Don't use it!"); - rust_task *task = rust_get_current_task(); - lock->lock.must_have_lock(); - assert(NULL == lock->waiting); - lock->waiting = task; - task->block(lock, "waiting for signal"); - lock->lock.unlock(); - bool killed = task->yield(); - assert(!killed && "unimplemented"); - lock->lock.lock(); -} - -extern "C" bool -rust_signal_cond_lock(rust_cond_lock *lock) { - assert(false && "condition->signal() is totally broken! Don't use it!"); - lock->lock.must_have_lock(); - if(NULL == lock->waiting) { - return false; - } - else { - lock->waiting->wakeup(lock); - lock->waiting = NULL; - return true; - } +rust_unlock_little_lock(lock_and_signal *lock) { + lock->unlock(); } // set/get/atexit task_local_data can run on the rust stack for speed. diff --git a/src/rt/rust_cond_lock.cpp b/src/rt/rust_cond_lock.cpp deleted file mode 100644 index cdeccfdc26ca..000000000000 --- a/src/rt/rust_cond_lock.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "rust_cond_lock.h" - -rust_cond_lock::rust_cond_lock() - : waiting(NULL) -{ -} diff --git a/src/rt/rust_cond_lock.h b/src/rt/rust_cond_lock.h deleted file mode 100644 index 0adafd59678e..000000000000 --- a/src/rt/rust_cond_lock.h +++ /dev/null @@ -1,15 +0,0 @@ -// -*- c++ -*- -// A lock and condition variable pair that is useable from Rust. - -#pragma once - -#include "sync/lock_and_signal.h" -#include "rust_globals.h" -#include "rust_task.h" - -struct rust_cond_lock : public rust_cond { - rust_cond_lock(); - - lock_and_signal lock; - rust_task *waiting; -}; diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index 997dcf0e668c..9710d4acb279 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -185,12 +185,10 @@ rust_task_inhibit_yield rust_task_allow_yield rust_task_kill_other rust_task_kill_all -rust_create_cond_lock -rust_destroy_cond_lock -rust_lock_cond_lock -rust_unlock_cond_lock -rust_wait_cond_lock -rust_signal_cond_lock +rust_create_little_lock +rust_destroy_little_lock +rust_lock_little_lock +rust_unlock_little_lock rust_get_task_local_data rust_set_task_local_data rust_task_local_data_atexit