diff options
| author | Simon BD <simon@server> | 2012-10-03 21:47:09 -0500 |
|---|---|---|
| committer | Simon BD <simon@server> | 2012-10-03 21:47:09 -0500 |
| commit | efcd2385ea2389f270ff8ac8bc256636f647b130 (patch) | |
| tree | 7e142ef709bc907a34ab1cb252eef6dcc0e83b91 /src/libcore/task | |
| parent | 44f8a4401ab37a45ba49db56611d77807bcbce35 (diff) | |
| parent | 3ccf6f5932d8223fd6c5cbf7c6ac429ca9e8912a (diff) | |
Merge remote-tracking branch 'original/incoming' into incoming
Conflicts: src/libstd/json.rs src/libstd/sort.rs
Diffstat (limited to 'src/libcore/task')
| -rw-r--r-- | src/libcore/task/local_data.rs | 66 | ||||
| -rw-r--r-- | src/libcore/task/local_data_priv.rs | 34 | ||||
| -rw-r--r-- | src/libcore/task/rt.rs | 8 | ||||
| -rw-r--r-- | src/libcore/task/spawn.rs | 85 |
4 files changed, 95 insertions, 98 deletions
diff --git a/src/libcore/task/local_data.rs b/src/libcore/task/local_data.rs index d91783284c0..2130354229a 100644 --- a/src/libcore/task/local_data.rs +++ b/src/libcore/task/local_data.rs @@ -16,12 +16,6 @@ magic. */ -export LocalDataKey; -export local_data_pop; -export local_data_get; -export local_data_set; -export local_data_modify; - use local_data_priv::{ local_pop, local_get, @@ -43,13 +37,13 @@ use local_data_priv::{ * * These two cases aside, the interface is safe. */ -type LocalDataKey<T: Owned> = &fn(+v: @T); +pub type LocalDataKey<T: Owned> = &fn(v: @T); /** * Remove a task-local data value from the table, returning the * reference that was originally created to insert it. */ -unsafe fn local_data_pop<T: Owned>( +pub unsafe fn local_data_pop<T: Owned>( key: LocalDataKey<T>) -> Option<@T> { local_pop(rt::rust_get_task(), key) @@ -58,7 +52,7 @@ unsafe fn local_data_pop<T: Owned>( * Retrieve a task-local data value. It will also be kept alive in the * table until explicitly removed. */ -unsafe fn local_data_get<T: Owned>( +pub unsafe fn local_data_get<T: Owned>( key: LocalDataKey<T>) -> Option<@T> { local_get(rt::rust_get_task(), key) @@ -67,8 +61,8 @@ unsafe fn local_data_get<T: Owned>( * Store a value in task-local data. If this key already has a value, * that value is overwritten (and its destructor is run). */ -unsafe fn local_data_set<T: Owned>( - key: LocalDataKey<T>, +data: @T) { +pub unsafe fn local_data_set<T: Owned>( + key: LocalDataKey<T>, data: @T) { local_set(rt::rust_get_task(), key, data) } @@ -76,7 +70,7 @@ unsafe fn local_data_set<T: Owned>( * Modify a task-local data value. If the function returns 'None', the * data is removed (and its reference dropped). */ -unsafe fn local_data_modify<T: Owned>( +pub unsafe fn local_data_modify<T: Owned>( key: LocalDataKey<T>, modify_fn: fn(Option<@T>) -> Option<@T>) { @@ -84,8 +78,8 @@ unsafe fn local_data_modify<T: Owned>( } #[test] -fn test_tls_multitask() unsafe { - fn my_key(+_x: @~str) { } +pub fn test_tls_multitask() unsafe { + fn my_key(_x: @~str) { } local_data_set(my_key, @~"parent data"); do task::spawn unsafe { assert local_data_get(my_key).is_none(); // TLS shouldn't carry over. @@ -100,16 +94,16 @@ fn test_tls_multitask() unsafe { } #[test] -fn test_tls_overwrite() unsafe { - fn my_key(+_x: @~str) { } +pub fn test_tls_overwrite() unsafe { + fn my_key(_x: @~str) { } local_data_set(my_key, @~"first data"); local_data_set(my_key, @~"next data"); // Shouldn't leak. assert *(local_data_get(my_key).get()) == ~"next data"; } #[test] -fn test_tls_pop() unsafe { - fn my_key(+_x: @~str) { } +pub fn test_tls_pop() unsafe { + fn my_key(_x: @~str) { } local_data_set(my_key, @~"weasel"); assert *(local_data_pop(my_key).get()) == ~"weasel"; // Pop must remove the data from the map. @@ -117,18 +111,18 @@ fn test_tls_pop() unsafe { } #[test] -fn test_tls_modify() unsafe { - fn my_key(+_x: @~str) { } +pub fn test_tls_modify() unsafe { + fn my_key(_x: @~str) { } local_data_modify(my_key, |data| { match data { - Some(@val) => fail ~"unwelcome value: " + val, + Some(@ref val) => fail ~"unwelcome value: " + *val, None => Some(@~"first data") } }); local_data_modify(my_key, |data| { match data { Some(@~"first data") => Some(@~"next data"), - Some(@val) => fail ~"wrong value: " + val, + Some(@ref val) => fail ~"wrong value: " + *val, None => fail ~"missing value" } }); @@ -136,23 +130,23 @@ fn test_tls_modify() unsafe { } #[test] -fn test_tls_crust_automorestack_memorial_bug() unsafe { +pub fn test_tls_crust_automorestack_memorial_bug() unsafe { // This might result in a stack-canary clobber if the runtime fails to set // sp_limit to 0 when calling the cleanup extern - it might automatically // jump over to the rust stack, which causes next_c_sp to get recorded as // Something within a rust stack segment. Then a subsequent upcall (esp. // for logging, think vsnprintf) would run on a stack smaller than 1 MB. - fn my_key(+_x: @~str) { } + fn my_key(_x: @~str) { } do task::spawn { unsafe { local_data_set(my_key, @~"hax"); } } } #[test] -fn test_tls_multiple_types() unsafe { - fn str_key(+_x: @~str) { } - fn box_key(+_x: @@()) { } - fn int_key(+_x: @int) { } +pub fn test_tls_multiple_types() unsafe { + fn str_key(_x: @~str) { } + fn box_key(_x: @@()) { } + fn int_key(_x: @int) { } do task::spawn unsafe { local_data_set(str_key, @~"string data"); local_data_set(box_key, @@()); @@ -161,10 +155,10 @@ fn test_tls_multiple_types() unsafe { } #[test] -fn test_tls_overwrite_multiple_types() { - fn str_key(+_x: @~str) { } - fn box_key(+_x: @@()) { } - fn int_key(+_x: @int) { } +pub fn test_tls_overwrite_multiple_types() { + fn str_key(_x: @~str) { } + fn box_key(_x: @@()) { } + fn int_key(_x: @int) { } do task::spawn unsafe { local_data_set(str_key, @~"string data"); local_data_set(int_key, @42); @@ -177,10 +171,10 @@ fn test_tls_overwrite_multiple_types() { #[test] #[should_fail] #[ignore(cfg(windows))] -fn test_tls_cleanup_on_failure() unsafe { - fn str_key(+_x: @~str) { } - fn box_key(+_x: @@()) { } - fn int_key(+_x: @int) { } +pub fn test_tls_cleanup_on_failure() unsafe { + fn str_key(_x: @~str) { } + fn box_key(_x: @@()) { } + fn int_key(_x: @int) { } local_data_set(str_key, @~"parent data"); local_data_set(box_key, @@()); do task::spawn unsafe { // spawn_linked diff --git a/src/libcore/task/local_data_priv.rs b/src/libcore/task/local_data_priv.rs index 2fbb88327ed..9849ce7b68c 100644 --- a/src/libcore/task/local_data_priv.rs +++ b/src/libcore/task/local_data_priv.rs @@ -3,7 +3,7 @@ use local_data::LocalDataKey; use rt::rust_task; -trait LocalData { } +pub trait LocalData { } impl<T: Owned> @T: LocalData { } impl LocalData: Eq { @@ -17,11 +17,11 @@ impl LocalData: Eq { // We use dvec because it's the best data structure in core. If TLS is used // heavily in future, this could be made more efficient with a proper map. -type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData); +pub type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData); // Has to be a pointer at outermost layer; the foreign call returns void *. -type TaskLocalMap = @dvec::DVec<Option<TaskLocalElement>>; +pub type TaskLocalMap = @dvec::DVec<Option<TaskLocalElement>>; -extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { +pub extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { assert !map_ptr.is_null(); // Get and keep the single reference that was created at the beginning. let _map: TaskLocalMap = cast::reinterpret_cast(&map_ptr); @@ -29,7 +29,7 @@ extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { } // Gets the map from the runtime. Lazily initialises if not done so already. -unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { +pub unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { // Relies on the runtime initialising the pointer to null. // NOTE: The map's box lives in TLS invisibly referenced once. Each time @@ -52,7 +52,7 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { } } -unsafe fn key_to_key_value<T: Owned>( +pub unsafe fn key_to_key_value<T: Owned>( key: LocalDataKey<T>) -> *libc::c_void { // Keys are closures, which are (fnptr,envptr) pairs. Use fnptr. @@ -62,25 +62,25 @@ unsafe fn key_to_key_value<T: Owned>( } // If returning Some(..), returns with @T with the map's reference. Careful! -unsafe fn local_data_lookup<T: Owned>( +pub unsafe fn local_data_lookup<T: Owned>( map: TaskLocalMap, key: LocalDataKey<T>) -> Option<(uint, *libc::c_void)> { let key_value = key_to_key_value(key); let map_pos = (*map).position(|entry| - match entry { + match *entry { Some((k,_,_)) => k == key_value, None => false } ); do map_pos.map |index| { // .get() is guaranteed because of "None { false }" above. - let (_, data_ptr, _) = (*map)[index].get(); - (index, data_ptr) + let (_, data_ptr, _) = (*map)[*index].get(); + (*index, data_ptr) } } -unsafe fn local_get_helper<T: Owned>( +pub unsafe fn local_get_helper<T: Owned>( task: *rust_task, key: LocalDataKey<T>, do_pop: bool) -> Option<@T> { @@ -91,7 +91,7 @@ unsafe fn local_get_helper<T: Owned>( // was referenced in the local_data box, though, not here, so before // overwriting the local_data_box we need to give an extra reference. // We must also give an extra reference when not removing. - let (index, data_ptr) = result; + let (index, data_ptr) = *result; let data: @T = cast::transmute(move data_ptr); cast::bump_box_refcount(data); if do_pop { @@ -102,22 +102,22 @@ unsafe fn local_get_helper<T: Owned>( } -unsafe fn local_pop<T: Owned>( +pub unsafe fn local_pop<T: Owned>( task: *rust_task, key: LocalDataKey<T>) -> Option<@T> { local_get_helper(task, key, true) } -unsafe fn local_get<T: Owned>( +pub unsafe fn local_get<T: Owned>( task: *rust_task, key: LocalDataKey<T>) -> Option<@T> { local_get_helper(task, key, false) } -unsafe fn local_set<T: Owned>( - task: *rust_task, key: LocalDataKey<T>, +data: @T) { +pub unsafe fn local_set<T: Owned>( + task: *rust_task, key: LocalDataKey<T>, data: @T) { let map = get_task_local_map(task); // Store key+data as *voids. Data is invisibly referenced once; key isn't. @@ -148,7 +148,7 @@ unsafe fn local_set<T: Owned>( } } -unsafe fn local_modify<T: Owned>( +pub unsafe fn local_modify<T: Owned>( task: *rust_task, key: LocalDataKey<T>, modify_fn: fn(Option<@T>) -> Option<@T>) { diff --git a/src/libcore/task/rt.rs b/src/libcore/task/rt.rs index b1f7b99bd07..db3d1ec9f70 100644 --- a/src/libcore/task/rt.rs +++ b/src/libcore/task/rt.rs @@ -7,16 +7,16 @@ The task interface to the runtime #[doc(hidden)]; // FIXME #3538 #[allow(non_camel_case_types)] // runtime type -type sched_id = int; +pub type sched_id = int; #[allow(non_camel_case_types)] // runtime type -type task_id = int; +pub type task_id = int; // These are both opaque runtime/compiler types that we don't know the // structure of and should only deal with via unsafe pointer #[allow(non_camel_case_types)] // runtime type -type rust_task = libc::c_void; +pub type rust_task = libc::c_void; #[allow(non_camel_case_types)] // runtime type -type rust_closure = libc::c_void; +pub type rust_closure = libc::c_void; extern { #[rust_stack] diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 21f217d57f4..0e1284da3bc 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -66,28 +66,28 @@ use rt::rust_task; use rt::rust_closure; macro_rules! move_it ( - { $x:expr } => { unsafe { let y <- *ptr::addr_of($x); move y } } + { $x:expr } => { unsafe { let y <- *ptr::addr_of(&($x)); move y } } ) -type TaskSet = send_map::linear::LinearMap<*rust_task,()>; +pub type TaskSet = send_map::linear::LinearMap<*rust_task,()>; -fn new_taskset() -> TaskSet { +pub fn new_taskset() -> TaskSet { send_map::linear::LinearMap() } -fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) { +pub fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) { let didnt_overwrite = tasks.insert(task, ()); assert didnt_overwrite; } -fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) { +pub fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) { let was_present = tasks.remove(&task); assert was_present; } -fn taskset_each(tasks: &TaskSet, blk: fn(+v: *rust_task) -> bool) { +pub fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) { tasks.each_key(|k| blk(*k)) } // One of these per group of linked-failure tasks. -type TaskGroupData = { +pub type TaskGroupData = { // All tasks which might kill this group. When this is empty, the group // can be "GC"ed (i.e., its link in the ancestor list can be removed). mut members: TaskSet, @@ -95,12 +95,12 @@ type TaskGroupData = { // tasks in this group. mut descendants: TaskSet, }; -type TaskGroupArc = private::Exclusive<Option<TaskGroupData>>; +pub type TaskGroupArc = private::Exclusive<Option<TaskGroupData>>; -type TaskGroupInner = &mut Option<TaskGroupData>; +pub type TaskGroupInner = &mut Option<TaskGroupData>; // A taskgroup is 'dead' when nothing can cause it to fail; only members can. -pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { +pub pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { (&tg.members).is_empty() } @@ -111,7 +111,7 @@ pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { // taskgroup which was spawned-unlinked. Tasks from intermediate generations // have references to the middle of the list; when intermediate generations // die, their node in the list will be collected at a descendant's spawn-time. -type AncestorNode = { +pub type AncestorNode = { // Since the ancestor list is recursive, we end up with references to // exclusives within other exclusives. This is dangerous business (if // circular references arise, deadlock and memory leaks are imminent). @@ -124,16 +124,16 @@ type AncestorNode = { // Recursive rest of the list. mut ancestors: AncestorList, }; -enum AncestorList = Option<private::Exclusive<AncestorNode>>; +pub enum AncestorList = Option<private::Exclusive<AncestorNode>>; // Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety. #[inline(always)] -fn access_group<U>(x: &TaskGroupArc, blk: fn(TaskGroupInner) -> U) -> U { +pub fn access_group<U>(x: &TaskGroupArc, blk: fn(TaskGroupInner) -> U) -> U { unsafe { x.with(blk) } } #[inline(always)] -fn access_ancestors<U>(x: &private::Exclusive<AncestorNode>, +pub fn access_ancestors<U>(x: &private::Exclusive<AncestorNode>, blk: fn(x: &mut AncestorNode) -> U) -> U { unsafe { x.with(blk) } } @@ -146,9 +146,9 @@ fn access_ancestors<U>(x: &private::Exclusive<AncestorNode>, // (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list. // FIXME(#2190): Change Option<fn@(...)> to Option<fn&(...)>, to save on // allocations. Once that bug is fixed, changing the sigil should suffice. -fn each_ancestor(list: &mut AncestorList, - bail_opt: Option<fn@(TaskGroupInner)>, - forward_blk: fn(TaskGroupInner) -> bool) +pub fn each_ancestor(list: &mut AncestorList, + bail_opt: Option<fn@(TaskGroupInner)>, + forward_blk: fn(TaskGroupInner) -> bool) -> bool { // "Kickoff" call - there was no last generation. return !coalesce(list, bail_opt, forward_blk, uint::max_value); @@ -200,7 +200,7 @@ fn each_ancestor(list: &mut AncestorList, // the end of the list, which doesn't make sense to coalesce. return do (**ancestors).map_default((None,false)) |ancestor_arc| { // NB: Takes a lock! (this ancestor node) - do access_ancestors(&ancestor_arc) |nobe| { + do access_ancestors(ancestor_arc) |nobe| { // Check monotonicity assert last_generation > nobe.generation; /*##########################################################* @@ -240,7 +240,7 @@ fn each_ancestor(list: &mut AncestorList, if need_unwind && !nobe_is_dead { do bail_opt.iter |bail_blk| { do with_parent_tg(&mut nobe.parent_group) |tg_opt| { - bail_blk(tg_opt) + (*bail_blk)(tg_opt) } } } @@ -271,7 +271,7 @@ fn each_ancestor(list: &mut AncestorList, } // One of these per task. -struct TCB { +pub struct TCB { me: *rust_task, // List of tasks with whose fates this one's is intertwined. tasks: TaskGroupArc, // 'none' means the group has failed. @@ -303,8 +303,8 @@ struct TCB { } } -fn TCB(me: *rust_task, +tasks: TaskGroupArc, +ancestors: AncestorList, - is_main: bool, +notifier: Option<AutoNotify>) -> TCB { +pub fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, + is_main: bool, notifier: Option<AutoNotify>) -> TCB { let notifier = move notifier; notifier.iter(|x| { x.failed = false; }); @@ -318,7 +318,7 @@ fn TCB(me: *rust_task, +tasks: TaskGroupArc, +ancestors: AncestorList, } } -struct AutoNotify { +pub struct AutoNotify { notify_chan: Chan<Notification>, mut failed: bool, drop { @@ -327,15 +327,15 @@ struct AutoNotify { } } -fn AutoNotify(+chan: Chan<Notification>) -> AutoNotify { +pub fn AutoNotify(chan: Chan<Notification>) -> AutoNotify { AutoNotify { notify_chan: chan, failed: true // Un-set above when taskgroup successfully made. } } -fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task, - is_member: bool) -> bool { +pub fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task, + is_member: bool) -> bool { let newstate = util::replace(state, None); // If 'None', the group was failing. Can't enlist. if newstate.is_some() { @@ -350,7 +350,8 @@ fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task, } // NB: Runs in destructor/post-exit context. Can't 'fail'. -fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, is_member: bool) { +pub fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, + is_member: bool) { let newstate = util::replace(state, None); // If 'None', already failing and we've already gotten a kill signal. if newstate.is_some() { @@ -362,7 +363,7 @@ fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, is_member: bool) { } // NB: Runs in destructor/post-exit context. Can't 'fail'. -fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) { +pub fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) { // NB: We could do the killing iteration outside of the group arc, by // having "let mut newstate" here, swapping inside, and iterating after. // But that would let other exiting tasks fall-through and exit while we @@ -377,13 +378,13 @@ fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) { // see 'None' if Somebody already failed and we got a kill signal.) if newstate.is_some() { let group = option::unwrap(move newstate); - for taskset_each(&group.members) |+sibling| { + for taskset_each(&group.members) |sibling| { // Skip self - killing ourself won't do much good. if sibling != me { rt::rust_task_kill_other(sibling); } } - for taskset_each(&group.descendants) |+child| { + for taskset_each(&group.descendants) |child| { assert child != me; rt::rust_task_kill_other(child); } @@ -404,8 +405,8 @@ macro_rules! taskgroup_key ( () => (cast::transmute((-2 as uint, 0u))) ) -fn gen_child_taskgroup(linked: bool, supervised: bool) - -> (TaskGroupArc, AncestorList, bool) { +pub fn gen_child_taskgroup(linked: bool, supervised: bool) + -> (TaskGroupArc, AncestorList, bool) { let spawner = rt::rust_get_task(); /*######################################################################* * Step 1. Get spawner's taskgroup info. @@ -451,7 +452,9 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) // it should be enabled only in debug builds. let new_generation = match *old_ancestors { - Some(arc) => access_ancestors(&arc, |a| a.generation+1), + Some(ref arc) => { + access_ancestors(arc, |a| a.generation+1) + } None => 0 // the actual value doesn't really matter. }; assert new_generation < uint::max_value; @@ -484,7 +487,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) } } -fn spawn_raw(+opts: TaskOpts, +f: fn~()) { +pub fn spawn_raw(opts: TaskOpts, +f: fn~()) { let (child_tg, ancestors, is_main) = gen_child_taskgroup(opts.linked, opts.supervised); @@ -509,8 +512,8 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) { let child_wrapper = make_child_wrapper(new_task, move child_tg, move ancestors, is_main, move notify_chan, move f); - let fptr = ptr::addr_of(child_wrapper); - let closure: *rust_closure = cast::reinterpret_cast(&fptr); + + let closure = cast::transmute(&child_wrapper); // Getting killed between these two calls would free the child's // closure. (Reordering them wouldn't help - then getting killed @@ -526,9 +529,9 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) { // (3a) If any of those fails, it leaves all groups, and does nothing. // (3b) Otherwise it builds a task control structure and puts it in TLS, // (4) ...and runs the provided body function. - fn make_child_wrapper(child: *rust_task, +child_arc: TaskGroupArc, - +ancestors: AncestorList, is_main: bool, - +notify_chan: Option<Chan<Notification>>, + fn make_child_wrapper(child: *rust_task, child_arc: TaskGroupArc, + ancestors: AncestorList, is_main: bool, + notify_chan: Option<Chan<Notification>>, +f: fn~()) -> fn~() { let child_data = ~mut Some((move child_arc, move ancestors)); return fn~(move notify_chan, move child_data, move f) { @@ -541,8 +544,8 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) { //let mut notifier = None;//notify_chan.map(|c| AutoNotify(c)); let notifier = match notify_chan { - Some(notify_chan_value) => { - let moved_ncv = move_it!(notify_chan_value); + Some(ref notify_chan_value) => { + let moved_ncv = move_it!(*notify_chan_value); Some(AutoNotify(move moved_ncv)) } _ => None |
