about summary refs log tree commit diff
path: root/src/libstd/task/spawn.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-14 10:19:21 -0700
committerbors <bors@rust-lang.org>2013-07-14 10:19:21 -0700
commit1c35ab322ff2f26962a3550fffc2fa4154224b64 (patch)
treed95eb9acc27f980f2365330b3aa9566e8eec2010 /src/libstd/task/spawn.rs
parent66e2857253ff9bc8ce299398ad5bb346d64e3fc3 (diff)
parent9fd2ac7428afa4f414f32b8b4876ca817ee85f16 (diff)
downloadrust-1c35ab322ff2f26962a3550fffc2fa4154224b64.tar.gz
rust-1c35ab322ff2f26962a3550fffc2fa4154224b64.zip
auto merge of #7751 : alexcrichton/rust/finish-tls, r=pcwalton
This changes the interface to `get`, and it also changes the keys to be static slices instead of static functions.

This allows the removal of the `unsafe` interface because while functions can monomorphize from different types to the same actual function, static slices cannot do this.

From at least what I can tell, we don't need to worry about LLVM coalescing these addresses. If we ever use the `unnamed_addr` it looks like there's cause for worry, but there doesn't appear to be any coalescing atm.
Diffstat (limited to 'src/libstd/task/spawn.rs')
-rw-r--r--src/libstd/task/spawn.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs
index 27cb1c2c100..206d19e175f 100644
--- a/src/libstd/task/spawn.rs
+++ b/src/libstd/task/spawn.rs
@@ -80,6 +80,7 @@ use cell::Cell;
 use container::MutableMap;
 use comm::{Chan, GenericChan};
 use hashmap::HashSet;
+use local_data;
 use task::local_data_priv::{local_get, local_set, OldHandle};
 use task::rt::rust_task;
 use task::rt;
@@ -465,10 +466,14 @@ fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) {
 
 // FIXME (#2912): Work around core-vs-coretest function duplication. Can't use
 // a proper closure because the #[test]s won't understand. Have to fake it.
-macro_rules! taskgroup_key (
-    // Use a "code pointer" value that will never be a real code pointer.
-    () => (cast::transmute((-2 as uint, 0u)))
-)
+#[cfg(not(stage0))]
+fn taskgroup_key() -> local_data::Key<@@mut TCB> {
+    unsafe { cast::transmute(-2) }
+}
+#[cfg(stage0)]
+fn taskgroup_key() -> local_data::Key<@@mut TCB> {
+    unsafe { cast::transmute((-2, 0)) }
+}
 
 fn gen_child_taskgroup(linked: bool, supervised: bool)
     -> (TaskGroupArc, AncestorList, bool) {
@@ -478,7 +483,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
          * Step 1. Get spawner's taskgroup info.
          *##################################################################*/
         let spawner_group: @@mut TCB =
-            do local_get(OldHandle(spawner), taskgroup_key!()) |group| {
+            do local_get(OldHandle(spawner), taskgroup_key()) |group| {
                 match group {
                     None => {
                         // Main task, doing first spawn ever. Lazily initialise
@@ -495,7 +500,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
                                               AncestorList(None),
                                               true,
                                               None);
-                        local_set(OldHandle(spawner), taskgroup_key!(), group);
+                        local_set(OldHandle(spawner), taskgroup_key(), group);
                         group
                     }
                     Some(&group) => group
@@ -688,7 +693,7 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) {
                                       is_main,
                                       notifier);
                 unsafe {
-                    local_set(OldHandle(child), taskgroup_key!(), group);
+                    local_set(OldHandle(child), taskgroup_key(), group);
                 }
 
                 // Run the child's body.