Remove rust_cond_lock and sys::condition (rename to little_lock)
This commit is contained in:
parent
32e4fd62e9
commit
bdbad614ac
1
mk/rt.mk
1
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 \
|
||||
|
@ -83,11 +83,11 @@ fn clone<T: const send>(rc: &arc<T>) -> arc<T> {
|
||||
}
|
||||
|
||||
// An arc over mutable data that is protected by a lock.
|
||||
type ex_data<T: send> = {lock: sys::lock_and_signal, mut data: T};
|
||||
type ex_data<T: send> = {lock: sys::little_lock, mut data: T};
|
||||
type exclusive<T: send> = arc_destruct<ex_data<T>>;
|
||||
|
||||
fn exclusive<T:send >(-data: T) -> exclusive<T> {
|
||||
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<T: send> for exclusive<T> {
|
||||
* 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<U>(f: fn(sys::condition, x: &mut T) -> U) -> U {
|
||||
unsafe fn with<U>(f: fn(x: &mut T) -> U) -> U {
|
||||
let ptr: ~arc_data<ex_data<T>> =
|
||||
unsafe::reinterpret_cast(self.data);
|
||||
assert ptr.count > 0;
|
||||
let r = {
|
||||
let rec: &ex_data<T> = &(*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
|
||||
};
|
||||
}
|
||||
|
@ -1027,7 +1027,7 @@ type shared_chan<T: send> = arc::exclusive<chan<T>>;
|
||||
impl chan<T: send> of channel<T> for shared_chan<T> {
|
||||
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))
|
||||
|
@ -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: 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<T>(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<T>(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::<uint>() == 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:
|
||||
|
@ -740,12 +740,12 @@ enum ancestor_list = option<arc::exclusive<ancestor_node>>;
|
||||
// Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety.
|
||||
#[inline(always)]
|
||||
fn access_group<U>(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<U>(x: arc::exclusive<ancestor_node>,
|
||||
blk: fn(x: &mut ancestor_node) -> U) -> U {
|
||||
unsafe { x.with(|_c, nobe| blk(nobe)) }
|
||||
unsafe { x.with(blk) }
|
||||
}
|
||||
|
||||
// Iterates over an ancestor list.
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include "sync/timer.h"
|
||||
#include "rust_abi.h"
|
||||
#include "rust_port.h"
|
||||
#include "rust_cond_lock.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
@ -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.
|
||||
|
@ -1,6 +0,0 @@
|
||||
#include "rust_cond_lock.h"
|
||||
|
||||
rust_cond_lock::rust_cond_lock()
|
||||
: waiting(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;
|
||||
};
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user