Skip to content

Commit 88a6f99

Browse files
committed
---
yaml --- r: 77693 b: refs/heads/master c: 5fc4045 h: refs/heads/master i: 77691: fe0e7ba v: v3
1 parent f40b8d0 commit 88a6f99

File tree

7 files changed

+95
-62
lines changed

7 files changed

+95
-62
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: f3d017cbab8ebdcb08d30be36601910824ea416f
2+
refs/heads/master: 5fc4045d789ed752c49b9368a2cc9a1cd8c341d5
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 60fba4d7d677ec098e6a43014132fe99f7547363
55
refs/heads/try: ebfe63cd1c0b5d23f7ea60c69b4fde2e30cfd42a

trunk/src/libextra/sync.rs

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ impl<Q:Send> Sem<Q> {
135135
do task::unkillable {
136136
do (|| {
137137
self.acquire();
138-
unsafe {
139-
do task::rekillable { blk() }
140-
}
138+
do task::rekillable { blk() }
141139
}).finally {
142140
self.release();
143141
}
@@ -234,10 +232,8 @@ impl<'self> Condvar<'self> {
234232
// signaller already sent -- I mean 'unconditionally' in contrast
235233
// with acquire().)
236234
do (|| {
237-
unsafe {
238-
do task::rekillable {
239-
let _ = WaitEnd.take_unwrap().recv();
240-
}
235+
do task::rekillable {
236+
let _ = WaitEnd.take_unwrap().recv();
241237
}
242238
}).finally {
243239
// Reacquire the condvar. Note this is back in the unkillable
@@ -516,14 +512,12 @@ impl RWLock {
516512
* 'write' from other tasks will run concurrently with this one.
517513
*/
518514
pub fn write<U>(&self, blk: &fn() -> U) -> U {
519-
unsafe {
520-
do task::unkillable {
521-
(&self.order_lock).acquire();
522-
do (&self.access_lock).access {
523-
(&self.order_lock).release();
524-
do task::rekillable {
525-
blk()
526-
}
515+
do task::unkillable {
516+
(&self.order_lock).acquire();
517+
do (&self.access_lock).access {
518+
(&self.order_lock).release();
519+
do task::rekillable {
520+
blk()
527521
}
528522
}
529523
}
@@ -562,16 +556,14 @@ impl RWLock {
562556
// which can't happen until T2 finishes the downgrade-read entirely.
563557
// The astute reader will also note that making waking writers use the
564558
// order_lock is better for not starving readers.
565-
unsafe {
566-
do task::unkillable {
567-
(&self.order_lock).acquire();
568-
do (&self.access_lock).access_cond |cond| {
569-
(&self.order_lock).release();
570-
do task::rekillable {
571-
let opt_lock = Just(&self.order_lock);
572-
blk(&Condvar { sem: cond.sem, order: opt_lock,
573-
token: NonCopyable::new() })
574-
}
559+
do task::unkillable {
560+
(&self.order_lock).acquire();
561+
do (&self.access_lock).access_cond |cond| {
562+
(&self.order_lock).release();
563+
do task::rekillable {
564+
let opt_lock = Just(&self.order_lock);
565+
blk(&Condvar { sem: cond.sem, order: opt_lock,
566+
token: NonCopyable::new() })
575567
}
576568
}
577569
}
@@ -606,10 +598,8 @@ impl RWLock {
606598
(&self.access_lock).acquire();
607599
(&self.order_lock).release();
608600
do (|| {
609-
unsafe {
610-
do task::rekillable {
611-
blk(RWLockWriteMode { lock: self, token: NonCopyable::new() })
612-
}
601+
do task::rekillable {
602+
blk(RWLockWriteMode { lock: self, token: NonCopyable::new() })
613603
}
614604
}).finally {
615605
let writer_or_last_reader;

trunk/src/librustpkg/rustpkg.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,7 @@ pub fn main() {
473473
pub fn main_args(args: &[~str]) {
474474
let opts = ~[getopts::optflag("h"), getopts::optflag("help"),
475475
getopts::optflag("j"), getopts::optflag("json"),
476-
getopts::optmulti("c"), getopts::optmulti("cfg"),
477-
getopts::optflag("v"), getopts::optflag("version")];
476+
getopts::optmulti("c"), getopts::optmulti("cfg")];
478477
let matches = &match getopts::getopts(args, opts) {
479478
result::Ok(m) => m,
480479
result::Err(f) => {
@@ -487,13 +486,6 @@ pub fn main_args(args: &[~str]) {
487486
getopts::opt_present(matches, "help");
488487
let json = getopts::opt_present(matches, "j") ||
489488
getopts::opt_present(matches, "json");
490-
491-
if getopts::opt_present(matches, "v") ||
492-
getopts::opt_present(matches, "version") {
493-
rustc::version(args[0]);
494-
return;
495-
}
496-
497489
let mut args = matches.free.clone();
498490

499491
args.shift();

trunk/src/libstd/rt/kill.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,9 @@ impl Death {
647647
/// All calls must be paired with a preceding call to inhibit_kill.
648648
#[inline]
649649
pub fn allow_kill(&mut self, already_failing: bool) {
650-
rtassert!(self.unkillable != 0);
650+
if self.unkillable == 0 {
651+
fail!("illegal call of rekillable");
652+
}
651653
self.unkillable -= 1;
652654
if self.unkillable == 0 {
653655
rtassert!(self.kill_handle.is_some());

trunk/src/libstd/task/mod.rs

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -597,21 +597,36 @@ pub fn unkillable<U>(f: &fn() -> U) -> U {
597597
}
598598
}
599599

600-
/// The inverse of unkillable. Only ever to be used nested in unkillable().
601-
pub unsafe fn rekillable<U>(f: &fn() -> U) -> U {
600+
/**
601+
* Makes killable a task marked as unkillable. This
602+
* is meant to be used only nested in unkillable.
603+
*
604+
* # Example
605+
*
606+
* ~~~
607+
* do task::unkillable {
608+
* do task::rekillable {
609+
* // Task is killable
610+
* }
611+
* // Task is unkillable again
612+
* }
613+
*/
614+
pub fn rekillable<U>(f: &fn() -> U) -> U {
602615
use rt::task::Task;
603616

604-
if in_green_task_context() {
605-
let t = Local::unsafe_borrow::<Task>();
606-
do (|| {
607-
(*t).death.allow_kill((*t).unwinder.unwinding);
617+
unsafe {
618+
if in_green_task_context() {
619+
let t = Local::unsafe_borrow::<Task>();
620+
do (|| {
621+
(*t).death.allow_kill((*t).unwinder.unwinding);
622+
f()
623+
}).finally {
624+
(*t).death.inhibit_kill((*t).unwinder.unwinding);
625+
}
626+
} else {
627+
// FIXME(#3095): As in unkillable().
608628
f()
609-
}).finally {
610-
(*t).death.inhibit_kill((*t).unwinder.unwinding);
611629
}
612-
} else {
613-
// FIXME(#3095): As in unkillable().
614-
f()
615630
}
616631
}
617632

@@ -646,19 +661,49 @@ fn test_kill_rekillable_task() {
646661
do run_in_newsched_task {
647662
do task::try {
648663
do task::unkillable {
649-
unsafe {
650-
do task::rekillable {
651-
do task::spawn {
652-
fail!();
653-
}
664+
do task::rekillable {
665+
do task::spawn {
666+
fail!();
654667
}
655668
}
656669
}
657670
};
658671
}
659672
}
660673

661-
#[test] #[should_fail]
674+
#[test]
675+
#[ignore(cfg(windows))]
676+
#[should_fail]
677+
fn test_rekillable_not_nested() {
678+
do rekillable {
679+
// This should fail before
680+
// receiving anything since
681+
// this block should be nested
682+
// into a unkillable block.
683+
yield();
684+
}
685+
}
686+
687+
688+
#[test]
689+
#[ignore(cfg(windows))]
690+
fn test_rekillable_nested_failure() {
691+
692+
let result = do task::try {
693+
do unkillable {
694+
do rekillable {
695+
let (port,chan) = comm::stream();
696+
do task::spawn { chan.send(()); fail!(); }
697+
port.recv(); // wait for child to exist
698+
port.recv(); // block forever, expect to get killed.
699+
}
700+
}
701+
};
702+
assert!(result.is_err());
703+
}
704+
705+
706+
#[test] #[should_fail] #[ignore(cfg(windows))]
662707
fn test_cant_dup_task_builder() {
663708
let mut builder = task();
664709
builder.unlinked();

trunk/src/libstd/vec.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ use rt::global_heap::realloc_raw;
7575
use sys;
7676
use sys::size_of;
7777
use uint;
78+
use unstable::finally::Finally;
7879
use unstable::intrinsics;
7980
use unstable::intrinsics::{get_tydesc, contains_managed};
8081
use unstable::raw::{Box, Repr, Slice, Vec};
@@ -97,11 +98,14 @@ pub fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> ~[T] {
9798
let mut v = with_capacity(n_elts);
9899
let p = raw::to_mut_ptr(v);
99100
let mut i: uint = 0u;
100-
while i < n_elts {
101-
intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i as int)), op(i));
102-
i += 1u;
101+
do (|| {
102+
while i < n_elts {
103+
intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i as int)), op(i));
104+
i += 1u;
105+
}
106+
}).finally {
107+
raw::set_len(&mut v, i);
103108
}
104-
raw::set_len(&mut v, n_elts);
105109
v
106110
}
107111
}

trunk/src/llvm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 0964c68ddf2c67ce455e7443a06f4bb3db9e92bb
1+
Subproject commit f67442eee27d3d075a65cf7f9a70f7ec6649ffd1

0 commit comments

Comments
 (0)