Skip to content

Commit 6d91846

Browse files
committed
(cleanup) Don't check taskgroup generation monotonicity unless cfg(test).
1 parent 87bbcb5 commit 6d91846

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/libstd/task/spawn.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ struct AncestorNode {
176176
// circular references arise, deadlock and memory leaks are imminent).
177177
// Hence we assert that this counter monotonically decreases as we
178178
// approach the tail of the list.
179-
// FIXME(#3068): Make the generation counter togglable with #[cfg(debug)].
180179
generation: uint,
181180
// Handle to the tasks in the group of the current generation.
182181
parent_group: TaskGroupArc,
@@ -202,6 +201,18 @@ fn access_ancestors<U>(x: &Exclusive<AncestorNode>,
202201
}
203202
}
204203

204+
#[inline] #[cfg(test)]
205+
fn check_generation(younger: uint, older: uint) { assert!(younger > older); }
206+
#[inline] #[cfg(not(test))]
207+
fn check_generation(_younger: uint, _older: uint) { }
208+
209+
#[inline] #[cfg(test)]
210+
fn incr_generation(ancestors: &AncestorList) -> uint {
211+
ancestors.map_default(0, |arc| access_ancestors(arc, |a| a.generation+1))
212+
}
213+
#[inline] #[cfg(not(test))]
214+
fn incr_generation(_ancestors: &AncestorList) -> uint { 0 }
215+
205216
// Iterates over an ancestor list.
206217
// (1) Runs forward_blk on each ancestral taskgroup in the list
207218
// (2) If forward_blk "break"s, runs optional bail_blk on all ancestral
@@ -264,7 +275,7 @@ fn each_ancestor(list: &mut AncestorList,
264275
// Argh, but we couldn't give it to coalesce() otherwise.
265276
let forward_blk = forward_blk.take();
266277
// Check monotonicity
267-
assert!(last_generation > nobe.generation);
278+
check_generation(last_generation, nobe.generation);
268279
/*##########################################################*
269280
* Step 1: Look at this ancestor group (call iterator block).
270281
*##########################################################*/
@@ -594,16 +605,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
594605
descendants: new_taskset(),
595606
}));
596607
let a = if supervised {
597-
// FIXME(#3068) - The generation counter is only used for a
598-
// debug assertion, but initialising it requires locking a
599-
// mutex. Hence it should be enabled only in debug builds.
600-
let new_generation =
601-
match *ancestors {
602-
Some(ref arc) => {
603-
access_ancestors(arc, |a| a.generation+1)
604-
}
605-
None => 0 // the actual value doesn't really matter.
606-
};
608+
let new_generation = incr_generation(&ancestors);
607609
assert!(new_generation < uint::max_value);
608610
// Child's ancestors start with the spawner.
609611
// Build a new node in the ancestor list.
@@ -710,8 +712,7 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) {
710712
let child_data = Cell::new((child_tg, ancestors, f));
711713
// Being killed with the unsafe task/closure pointers would leak them.
712714
do unkillable {
713-
// Agh. Get move-mode items into the closure. FIXME (#2829)
714-
let (child_tg, ancestors, f) = child_data.take();
715+
let (child_tg, ancestors, f) = child_data.take(); // :(
715716
// Create child task.
716717
let new_task = match opts.sched.mode {
717718
DefaultScheduler => rt::new_task(),
@@ -745,8 +746,7 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) {
745746
-> ~fn() {
746747
let child_data = Cell::new((notify_chan, child_arc, ancestors));
747748
let result: ~fn() = || {
748-
// Agh. Get move-mode items into the closure. FIXME (#2829)
749-
let (notify_chan, child_arc, ancestors) = child_data.take();
749+
let (notify_chan, child_arc, ancestors) = child_data.take(); // :(
750750
let mut ancestors = ancestors;
751751
// Child task runs this code.
752752

0 commit comments

Comments
 (0)