Skip to content

Commit bdbad61

Browse files
committed
Remove rust_cond_lock and sys::condition (rename to little_lock)
1 parent 32e4fd6 commit bdbad61

File tree

9 files changed

+39
-141
lines changed

9 files changed

+39
-141
lines changed

mk/rt.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ RUNTIME_CS_$(1) := \
7171
rt/rust_cc.cpp \
7272
rt/rust_debug.cpp \
7373
rt/rust_box_annihilator.cpp \
74-
rt/rust_cond_lock.cpp \
7574
rt/memory_region.cpp \
7675
rt/boxed_region.cpp \
7776
rt/arch/$$(HOST_$(1))/context.cpp \

src/libcore/arc.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ fn clone<T: const send>(rc: &arc<T>) -> arc<T> {
8383
}
8484

8585
// An arc over mutable data that is protected by a lock.
86-
type ex_data<T: send> = {lock: sys::lock_and_signal, mut data: T};
86+
type ex_data<T: send> = {lock: sys::little_lock, mut data: T};
8787
type exclusive<T: send> = arc_destruct<ex_data<T>>;
8888

8989
fn exclusive<T:send >(-data: T) -> exclusive<T> {
90-
let data = ~{mut count: 1, data: {lock: sys::lock_and_signal(),
90+
let data = ~{mut count: 1, data: {lock: sys::little_lock(),
9191
data: data}};
9292
unsafe {
9393
let ptr = unsafe::reinterpret_cast(data);
@@ -126,13 +126,13 @@ impl methods<T: send> for exclusive<T> {
126126
* will guarantee a memory leak of all involved ARCs. Using exclusive
127127
* ARCs inside of other ARCs is safe in absence of circular references.
128128
*/
129-
unsafe fn with<U>(f: fn(sys::condition, x: &mut T) -> U) -> U {
129+
unsafe fn with<U>(f: fn(x: &mut T) -> U) -> U {
130130
let ptr: ~arc_data<ex_data<T>> =
131131
unsafe::reinterpret_cast(self.data);
132132
assert ptr.count > 0;
133133
let r = {
134134
let rec: &ex_data<T> = &(*ptr).data;
135-
rec.lock.lock_cond(|c| f(c, &mut rec.data))
135+
do rec.lock.lock { f(&mut rec.data) }
136136
};
137137
unsafe::forget(ptr);
138138
r
@@ -184,7 +184,7 @@ mod tests {
184184
let total = total.clone();
185185
futures += ~[future::spawn(|| {
186186
for uint::range(0u, count) |_i| {
187-
do total.with |_cond, count| {
187+
do total.with |count| {
188188
**count += 1u;
189189
}
190190
}
@@ -193,7 +193,7 @@ mod tests {
193193

194194
for futures.each |f| { f.get() }
195195

196-
do total.with |_cond, total| {
196+
do total.with |total| {
197197
assert **total == num_tasks * count
198198
};
199199
}

src/libcore/pipes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ type shared_chan<T: send> = arc::exclusive<chan<T>>;
10271027
impl chan<T: send> of channel<T> for shared_chan<T> {
10281028
fn send(+x: T) {
10291029
let mut xx = some(x);
1030-
do self.with |_c, chan| {
1030+
do self.with |chan| {
10311031
let mut x = none;
10321032
x <-> xx;
10331033
chan.send(option::unwrap(x))

src/libcore/sys.rs

Lines changed: 18 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export min_align_of;
77
export pref_align_of;
88
export refcount;
99
export log_str;
10-
export lock_and_signal, condition, methods;
10+
export little_lock, methods;
1111
export shape_eq, shape_lt, shape_le;
1212

1313
import task::atomically;
@@ -18,18 +18,16 @@ enum type_desc = {
1818
// Remaining fields not listed
1919
};
2020

21-
type rust_cond_lock = *libc::c_void;
21+
type rust_little_lock = *libc::c_void;
2222

2323
#[abi = "cdecl"]
2424
extern mod rustrt {
2525
pure fn shape_log_str(t: *sys::type_desc, data: *()) -> ~str;
2626

27-
fn rust_create_cond_lock() -> rust_cond_lock;
28-
fn rust_destroy_cond_lock(lock: rust_cond_lock);
29-
fn rust_lock_cond_lock(lock: rust_cond_lock);
30-
fn rust_unlock_cond_lock(lock: rust_cond_lock);
31-
fn rust_wait_cond_lock(lock: rust_cond_lock);
32-
fn rust_signal_cond_lock(lock: rust_cond_lock) -> bool;
27+
fn rust_create_little_lock() -> rust_little_lock;
28+
fn rust_destroy_little_lock(lock: rust_little_lock);
29+
fn rust_lock_little_lock(lock: rust_little_lock);
30+
fn rust_unlock_little_lock(lock: rust_little_lock);
3331
}
3432

3533
#[abi = "rust-intrinsic"]
@@ -100,52 +98,30 @@ pure fn log_str<T>(t: T) -> ~str {
10098
}
10199
}
102100

103-
class lock_and_signal {
104-
let lock: rust_cond_lock;
101+
class little_lock {
102+
let l: rust_little_lock;
105103
new() {
106-
self.lock = rustrt::rust_create_cond_lock();
104+
self.l = rustrt::rust_create_little_lock();
107105
}
108-
drop { rustrt::rust_destroy_cond_lock(self.lock); }
106+
drop { rustrt::rust_destroy_little_lock(self.l); }
109107
}
110108

111-
enum condition {
112-
condition_(rust_cond_lock)
113-
}
114-
115-
class unlock {
116-
let lock: rust_cond_lock;
117-
new(lock: rust_cond_lock) { self.lock = lock; }
118-
drop { rustrt::rust_unlock_cond_lock(self.lock); }
119-
}
120-
121-
impl methods for lock_and_signal {
109+
impl methods for little_lock {
122110
unsafe fn lock<T>(f: fn() -> T) -> T {
123-
do atomically {
124-
rustrt::rust_lock_cond_lock(self.lock);
125-
let _r = unlock(self.lock);
126-
f()
111+
class unlock {
112+
let l: rust_little_lock;
113+
new(l: rust_little_lock) { self.l = l; }
114+
drop { rustrt::rust_unlock_little_lock(self.l); }
127115
}
128-
}
129116

130-
unsafe fn lock_cond<T>(f: fn(condition) -> T) -> T {
131117
do atomically {
132-
rustrt::rust_lock_cond_lock(self.lock);
133-
let _r = unlock(self.lock);
134-
f(condition_(self.lock))
118+
rustrt::rust_lock_little_lock(self.l);
119+
let _r = unlock(self.l);
120+
f()
135121
}
136122
}
137123
}
138124

139-
impl methods for condition {
140-
fn wait() {
141-
rustrt::rust_wait_cond_lock(*self);
142-
}
143-
144-
fn signal() -> bool {
145-
rustrt::rust_signal_cond_lock(*self)
146-
}
147-
}
148-
149125
#[cfg(test)]
150126
mod tests {
151127

@@ -193,27 +169,6 @@ mod tests {
193169
assert pref_align_of::<uint>() == 8u;
194170
assert pref_align_of::<*uint>() == 8u;
195171
}
196-
197-
#[test]
198-
#[ignore] // this can go into infinite loops
199-
fn condition_variable() {
200-
let lock = arc::arc(lock_and_signal());
201-
let lock2 = arc::clone(&lock);
202-
203-
do task::spawn |move lock2| {
204-
let lock = arc::get(&lock2);
205-
do (*lock).lock_cond |c| {
206-
c.wait();
207-
}
208-
}
209-
210-
let mut signaled = false;
211-
while !signaled {
212-
do (*arc::get(&lock)).lock_cond |c| {
213-
signaled = c.signal()
214-
}
215-
}
216-
}
217172
}
218173

219174
// Local Variables:

src/libcore/task.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,12 +740,12 @@ enum ancestor_list = option<arc::exclusive<ancestor_node>>;
740740
// Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety.
741741
#[inline(always)]
742742
fn access_group<U>(x: taskgroup_arc, blk: fn(taskgroup_inner) -> U) -> U {
743-
unsafe { x.with(|_c, tg| blk(tg)) }
743+
unsafe { x.with(blk) }
744744
}
745745
#[inline(always)]
746746
fn access_ancestors<U>(x: arc::exclusive<ancestor_node>,
747747
blk: fn(x: &mut ancestor_node) -> U) -> U {
748-
unsafe { x.with(|_c, nobe| blk(nobe)) }
748+
unsafe { x.with(blk) }
749749
}
750750

751751
// Iterates over an ancestor list.

src/rt/rust_builtin.cpp

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "sync/timer.h"
88
#include "rust_abi.h"
99
#include "rust_port.h"
10-
#include "rust_cond_lock.h"
1110

1211
#include <time.h>
1312

@@ -882,56 +881,24 @@ bool rust_task_is_unwinding(rust_task *rt) {
882881
return rt->unwinding;
883882
}
884883

885-
extern "C" rust_cond_lock*
886-
rust_create_cond_lock() {
887-
return new rust_cond_lock();
884+
extern "C" lock_and_signal*
885+
rust_create_little_lock() {
886+
return new lock_and_signal();
888887
}
889888

890889
extern "C" void
891-
rust_destroy_cond_lock(rust_cond_lock *lock) {
890+
rust_destroy_little_lock(lock_and_signal *lock) {
892891
delete lock;
893892
}
894893

895894
extern "C" void
896-
rust_lock_cond_lock(rust_cond_lock *lock) {
897-
lock->lock.lock();
895+
rust_lock_little_lock(lock_and_signal *lock) {
896+
lock->lock();
898897
}
899898

900899
extern "C" void
901-
rust_unlock_cond_lock(rust_cond_lock *lock) {
902-
lock->lock.unlock();
903-
}
904-
905-
// The next two functions do not use the built in condition variable features
906-
// because the Rust schedule is not aware of them, and they can block the
907-
// scheduler thread.
908-
909-
extern "C" void
910-
rust_wait_cond_lock(rust_cond_lock *lock) {
911-
assert(false && "condition->wait() is totally broken! Don't use it!");
912-
rust_task *task = rust_get_current_task();
913-
lock->lock.must_have_lock();
914-
assert(NULL == lock->waiting);
915-
lock->waiting = task;
916-
task->block(lock, "waiting for signal");
917-
lock->lock.unlock();
918-
bool killed = task->yield();
919-
assert(!killed && "unimplemented");
920-
lock->lock.lock();
921-
}
922-
923-
extern "C" bool
924-
rust_signal_cond_lock(rust_cond_lock *lock) {
925-
assert(false && "condition->signal() is totally broken! Don't use it!");
926-
lock->lock.must_have_lock();
927-
if(NULL == lock->waiting) {
928-
return false;
929-
}
930-
else {
931-
lock->waiting->wakeup(lock);
932-
lock->waiting = NULL;
933-
return true;
934-
}
900+
rust_unlock_little_lock(lock_and_signal *lock) {
901+
lock->unlock();
935902
}
936903

937904
// set/get/atexit task_local_data can run on the rust stack for speed.

src/rt/rust_cond_lock.cpp

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/rt/rust_cond_lock.h

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/rt/rustrt.def.in

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,10 @@ rust_task_inhibit_yield
185185
rust_task_allow_yield
186186
rust_task_kill_other
187187
rust_task_kill_all
188-
rust_create_cond_lock
189-
rust_destroy_cond_lock
190-
rust_lock_cond_lock
191-
rust_unlock_cond_lock
192-
rust_wait_cond_lock
193-
rust_signal_cond_lock
188+
rust_create_little_lock
189+
rust_destroy_little_lock
190+
rust_lock_little_lock
191+
rust_unlock_little_lock
194192
rust_get_task_local_data
195193
rust_set_task_local_data
196194
rust_task_local_data_atexit

0 commit comments

Comments
 (0)