diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-11-06 00:38:08 -0500 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-11-26 14:49:10 -0500 |
| commit | 1795ae4e8a472ce500660fa59abf61114f5ef8c9 (patch) | |
| tree | 5443d91db53a3d4fcccdf48971689a1cd4bbf26a /src | |
| parent | e03f17eb214e925b15f2c684ddb69a48fbd3d8f2 (diff) | |
| download | rust-1795ae4e8a472ce500660fa59abf61114f5ef8c9.tar.gz rust-1795ae4e8a472ce500660fa59abf61114f5ef8c9.zip | |
add `#[thread_local]` attribute
This provides a building block for fast thread-local storage. It does not change the safety semantics of `static mut`. Closes #10310
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/lib/llvm.rs | 6 | ||||
| -rw-r--r-- | src/librustc/middle/lint.rs | 1 | ||||
| -rw-r--r-- | src/librustc/middle/trans/base.rs | 4 |
3 files changed, 11 insertions, 0 deletions
diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 160bc511168..66f6e6a4746 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -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) diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 2b2c2aa74c7..a08afcfd7c5 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -816,6 +816,7 @@ static obsolete_attrs: &'static [(&'static str, &'static str)] = &[ 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", diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 0ece7c8c024..20cc2f8944e 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2543,6 +2543,10 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef { 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); |
