Skip to content

Commit 35bf99c

Browse files
committed
---
yaml --- r: 69501 b: refs/heads/auto c: 0144c83 h: refs/heads/master i: 69499: be9cc99 v: v3
1 parent 3550824 commit 35bf99c

File tree

12 files changed

+70
-46
lines changed

12 files changed

+70
-46
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: 7265cc6530b242f9590a3207f2bfdf9a5425a32c
17+
refs/heads/auto: 0144c83213cb5ce43df61f149274379f49b6d7cb
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/src/libstd/rt/comm.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,11 @@ mod test {
674674
do run_in_newsched_task {
675675
let (port, chan) = oneshot::<int>();
676676
let port_cell = Cell::new(port);
677-
let _thread = do spawntask_thread {
677+
let thread = do spawntask_thread {
678678
let _p = port_cell.take();
679679
};
680680
let _chan = chan;
681+
thread.join();
681682
}
682683
}
683684
}
@@ -689,13 +690,15 @@ mod test {
689690
let (port, chan) = oneshot::<int>();
690691
let chan_cell = Cell::new(chan);
691692
let port_cell = Cell::new(port);
692-
let _thread1 = do spawntask_thread {
693+
let thread1 = do spawntask_thread {
693694
let _p = port_cell.take();
694695
};
695-
let _thread2 = do spawntask_thread {
696+
let thread2 = do spawntask_thread {
696697
let c = chan_cell.take();
697698
c.send(1);
698699
};
700+
thread1.join();
701+
thread2.join();
699702
}
700703
}
701704
}
@@ -707,19 +710,21 @@ mod test {
707710
let (port, chan) = oneshot::<int>();
708711
let chan_cell = Cell::new(chan);
709712
let port_cell = Cell::new(port);
710-
let _thread1 = do spawntask_thread {
713+
let thread1 = do spawntask_thread {
711714
let port_cell = Cell::new(port_cell.take());
712715
let res = do spawntask_try {
713716
port_cell.take().recv();
714717
};
715718
assert!(res.is_err());
716719
};
717-
let _thread2 = do spawntask_thread {
720+
let thread2 = do spawntask_thread {
718721
let chan_cell = Cell::new(chan_cell.take());
719722
do spawntask {
720723
chan_cell.take();
721724
}
722725
};
726+
thread1.join();
727+
thread2.join();
723728
}
724729
}
725730
}
@@ -731,12 +736,14 @@ mod test {
731736
let (port, chan) = oneshot::<~int>();
732737
let chan_cell = Cell::new(chan);
733738
let port_cell = Cell::new(port);
734-
let _thread1 = do spawntask_thread {
739+
let thread1 = do spawntask_thread {
735740
chan_cell.take().send(~10);
736741
};
737-
let _thread2 = do spawntask_thread {
742+
let thread2 = do spawntask_thread {
738743
assert!(port_cell.take().recv() == ~10);
739744
};
745+
thread1.join();
746+
thread2.join();
740747
}
741748
}
742749
}

branches/auto/src/libstd/rt/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
343343
}
344344

345345
// Wait for schedulers
346-
{ let _threads = threads; }
346+
for threads.consume_iter().advance() |thread| {
347+
thread.join();
348+
}
347349

348350
// Return the exit code
349351
unsafe {

branches/auto/src/libstd/rt/sched.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -901,10 +901,8 @@ mod test {
901901
sched.run();
902902
};
903903

904-
// wait for the end
905-
let _thread1 = normal_thread;
906-
let _thread2 = special_thread;
907-
904+
normal_thread.join();
905+
special_thread.join();
908906
}
909907
}
910908

@@ -1074,16 +1072,19 @@ mod test {
10741072
sched2.enqueue_task(task2);
10751073

10761074
let sched1_cell = Cell::new(sched1);
1077-
let _thread1 = do Thread::start {
1075+
let thread1 = do Thread::start {
10781076
let sched1 = sched1_cell.take();
10791077
sched1.run();
10801078
};
10811079

10821080
let sched2_cell = Cell::new(sched2);
1083-
let _thread2 = do Thread::start {
1081+
let thread2 = do Thread::start {
10841082
let sched2 = sched2_cell.take();
10851083
sched2.run();
10861084
};
1085+
1086+
thread1.join();
1087+
thread2.join();
10871088
}
10881089
}
10891090

branches/auto/src/libstd/rt/test.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
125125
}
126126

127127
// Wait for schedulers
128-
let _threads = threads;
128+
for threads.consume_iter().advance() |thread| {
129+
thread.join();
130+
}
129131
}
130132

131133
}

branches/auto/src/libstd/rt/thread.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ type raw_thread = libc::c_void;
1616

1717
pub struct Thread {
1818
main: ~fn(),
19-
raw_thread: *raw_thread
19+
raw_thread: *raw_thread,
20+
joined: bool
2021
}
2122

2223
impl Thread {
@@ -27,18 +28,28 @@ impl Thread {
2728
let raw = substart(&main);
2829
Thread {
2930
main: main,
30-
raw_thread: raw
31+
raw_thread: raw,
32+
joined: false
3133
}
3234
}
35+
36+
pub fn join(self) {
37+
assert!(!self.joined);
38+
let mut this = self;
39+
unsafe { rust_raw_thread_join(this.raw_thread); }
40+
this.joined = true;
41+
}
3342
}
3443

3544
impl Drop for Thread {
3645
fn drop(&self) {
37-
unsafe { rust_raw_thread_join_delete(self.raw_thread) }
46+
assert!(self.joined);
47+
unsafe { rust_raw_thread_delete(self.raw_thread) }
3848
}
3949
}
4050

4151
extern {
4252
pub unsafe fn rust_raw_thread_start(f: &(~fn())) -> *raw_thread;
43-
pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
53+
pub unsafe fn rust_raw_thread_join(thread: *raw_thread);
54+
pub unsafe fn rust_raw_thread_delete(thread: *raw_thread);
4455
}

branches/auto/src/libstd/rt/uv/async.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,13 @@ mod test {
9494
let mut loop_ = Loop::new();
9595
let watcher = AsyncWatcher::new(&mut loop_, |w, _| w.close(||()) );
9696
let watcher_cell = Cell::new(watcher);
97-
let _thread = do Thread::start {
97+
let thread = do Thread::start {
9898
let mut watcher = watcher_cell.take();
9999
watcher.send();
100100
};
101101
loop_.run();
102102
loop_.close();
103+
thread.join();
103104
}
104105
}
105106
}

branches/auto/src/libstd/rt/uv/net.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ mod test {
715715
}
716716
}
717717
718-
let _client_thread = do Thread::start {
718+
let client_thread = do Thread::start {
719719
rtdebug!("starting client thread");
720720
let mut loop_ = Loop::new();
721721
let mut tcp_watcher = { TcpWatcher::new(&mut loop_) };
@@ -739,6 +739,7 @@ mod test {
739739
let mut loop_ = loop_;
740740
loop_.run();
741741
loop_.close();
742+
client_thread.join();
742743
}
743744
}
744745
@@ -790,7 +791,7 @@ mod test {
790791
}
791792
}
792793
793-
let _client_thread = do Thread::start {
794+
let client_thread = do Thread::start {
794795
rtdebug!("starting client thread");
795796
let mut loop_ = Loop::new();
796797
let mut tcp_watcher = { TcpWatcher::new(&mut loop_) };
@@ -814,6 +815,7 @@ mod test {
814815
let mut loop_ = loop_;
815816
loop_.run();
816817
loop_.close();
818+
client_thread.join();
817819
}
818820
}
819821
@@ -855,7 +857,7 @@ mod test {
855857
server.close(||{});
856858
}
857859
858-
do Thread::start {
860+
let thread = do Thread::start {
859861
let mut loop_ = Loop::new();
860862
let mut client = UdpWatcher::new(&loop_);
861863
assert!(client.bind(client_addr).is_ok());
@@ -873,6 +875,7 @@ mod test {
873875
874876
loop_.run();
875877
loop_.close();
878+
thread.join();
876879
}
877880
}
878881
@@ -914,7 +917,7 @@ mod test {
914917
server.close(||{});
915918
}
916919
917-
do Thread::start {
920+
let thread = do Thread::start {
918921
let mut loop_ = Loop::new();
919922
let mut client = UdpWatcher::new(&loop_);
920923
assert!(client.bind(client_addr).is_ok());
@@ -932,6 +935,7 @@ mod test {
932935

933936
loop_.run();
934937
loop_.close();
938+
thread.join();
935939
}
936940
}
937941
}

branches/auto/src/libstd/rt/uv/uvio.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,12 @@ mod test_remote {
222222
};
223223
remote_cell.put_back(remote);
224224
}
225-
let _thread = do Thread::start {
225+
let thread = do Thread::start {
226226
remote_cell.take().fire();
227227
};
228228

229229
assert!(tube.recv() == 1);
230+
thread.join();
230231
}
231232
}
232233
}

branches/auto/src/libstd/unstable/mod.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
use comm::{GenericChan, GenericPort};
1414
use comm;
15-
use libc;
1615
use prelude::*;
1716
use task;
1817

@@ -37,18 +36,16 @@ The executing thread has no access to a task pointer and will be using
3736
a normal large stack.
3837
*/
3938
pub fn run_in_bare_thread(f: ~fn()) {
39+
use cell::Cell;
40+
use rt::thread::Thread;
41+
42+
let f_cell = Cell::new(f);
4043
let (port, chan) = comm::stream();
4144
// FIXME #4525: Unfortunate that this creates an extra scheduler but it's
42-
// necessary since rust_raw_thread_join_delete is blocking
45+
// necessary since rust_raw_thread_join is blocking
4346
do task::spawn_sched(task::SingleThreaded) {
44-
unsafe {
45-
let closure: &fn() = || {
46-
f()
47-
};
48-
let thread = rust_raw_thread_start(&closure);
49-
rust_raw_thread_join_delete(thread);
50-
chan.send(());
51-
}
47+
Thread::start(f_cell.take()).join();
48+
chan.send(());
5249
}
5350
port.recv();
5451
}
@@ -70,14 +67,6 @@ fn test_run_in_bare_thread_exchange() {
7067
}
7168
}
7269

73-
#[allow(non_camel_case_types)] // runtime type
74-
pub type raw_thread = libc::c_void;
75-
76-
extern {
77-
fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread;
78-
fn rust_raw_thread_join_delete(thread: *raw_thread);
79-
}
80-
8170

8271
/// Changes the current working directory to the specified
8372
/// path while acquiring a global lock, then calls `action`.

branches/auto/src/rt/rust_builtin.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,14 @@ rust_raw_thread_start(fn_env_pair *fn) {
751751
}
752752

753753
extern "C" void
754-
rust_raw_thread_join_delete(raw_thread *thread) {
754+
rust_raw_thread_join(raw_thread *thread) {
755755
assert(thread);
756756
thread->join();
757+
}
758+
759+
extern "C" void
760+
rust_raw_thread_delete(raw_thread *thread) {
761+
assert(thread);
757762
delete thread;
758763
}
759764

branches/auto/src/rt/rustrt.def.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ linenoiseHistorySetMaxLen
211211
linenoiseHistorySave
212212
linenoiseHistoryLoad
213213
rust_raw_thread_start
214-
rust_raw_thread_join_delete
214+
rust_raw_thread_join
215+
rust_raw_thread_delete
215216
rust_get_rt_tls_key
216217
swap_registers
217218
rust_readdir

0 commit comments

Comments
 (0)