]> git.lizzy.rs Git - rust.git/commitdiff
add `#[thread_local]` attribute
authorDaniel Micay <danielmicay@gmail.com>
Wed, 6 Nov 2013 05:38:08 +0000 (00:38 -0500)
committerDaniel Micay <danielmicay@gmail.com>
Tue, 26 Nov 2013 19:49:10 +0000 (14:49 -0500)
This provides a building block for fast thread-local storage. It does
not change the safety semantics of `static mut`.

Closes #10310

doc/rust.md
src/librustc/lib/llvm.rs
src/librustc/middle/lint.rs
src/librustc/middle/trans/base.rs

index fe8d0a834e3e416d1d652a9f689617aad173a8ce..f15e767ca82a9cc7655929ac3d64c1b920dfbd4f 100644 (file)
@@ -1754,6 +1754,8 @@ names are effectively reserved. Some significant attributes include:
 * The `deriving` attribute, for automatically generating
   implementations of certain traits.
 * The `static_assert` attribute, for asserting that a static bool is true at compiletime
 * The `deriving` attribute, for automatically generating
   implementations of certain traits.
 * The `static_assert` attribute, for asserting that a static bool is true at compiletime
+* The `thread_local` attribute, for defining a `static mut` as a thread-local. Note that this is
+  only a low-level building block, and is not local to a *task*, nor does it provide safety.
 
 Other attributes may be added or removed during development of the language.
 
 
 Other attributes may be added or removed during development of the language.
 
index 160bc5111688a1fe98695f690f9d6abec2ae2ad3..66f6e6a4746f1af10ec583044ba823d6a08b7df2 100644 (file)
@@ -1749,6 +1749,12 @@ pub fn SetUnnamedAddr(Global: ValueRef, Unnamed: bool) {
     }
 }
 
     }
 }
 
+pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
+    unsafe {
+        llvm::LLVMSetThreadLocal(global, is_thread_local as Bool);
+    }
+}
+
 pub fn ConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
     unsafe {
         llvm::LLVMConstICmp(Pred as c_ushort, V1, V2)
 pub fn ConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
     unsafe {
         llvm::LLVMConstICmp(Pred as c_ushort, V1, V2)
index 2b2c2aa74c709a6b0f4c1526edb1430cd4195ae1..a08afcfd7c5e0018505e3c43c4623ea0f4988582 100644 (file)
@@ -816,6 +816,7 @@ fn check_heap_item(cx: &Context, it: &ast::item) {
 static other_attrs: &'static [&'static str] = &[
     // item-level
     "address_insignificant", // can be crate-level too
 static other_attrs: &'static [&'static str] = &[
     // item-level
     "address_insignificant", // can be crate-level too
+    "thread_local", // for statics
     "allow", "deny", "forbid", "warn", // lint options
     "deprecated", "experimental", "unstable", "stable", "locked", "frozen", //item stability
     "crate_map", "cfg", "doc", "export_name", "link_section", "no_freeze",
     "allow", "deny", "forbid", "warn", // lint options
     "deprecated", "experimental", "unstable", "stable", "locked", "frozen", //item stability
     "crate_map", "cfg", "doc", "export_name", "link_section", "no_freeze",
index 0ece7c8c024deb728a3a8bc1acc6f0e9bfce72b6..20cc2f8944e373d30ca62165cfaee3b0a2127f99 100644 (file)
@@ -2543,6 +2543,10 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
                                     inlineable = true;
                                 }
 
                                     inlineable = true;
                                 }
 
+                                if attr::contains_name(i.attrs, "thread_local") {
+                                    lib::llvm::set_thread_local(g, true);
+                                }
+
                                 if !inlineable {
                                     debug!("{} not inlined", sym);
                                     ccx.non_inlineable_statics.insert(id);
                                 if !inlineable {
                                     debug!("{} not inlined", sym);
                                     ccx.non_inlineable_statics.insert(id);