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
This commit is contained in:
Daniel Micay 2013-11-06 00:38:08 -05:00
parent e03f17eb21
commit 1795ae4e8a
4 changed files with 13 additions and 0 deletions

View 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 `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.

View 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)

View File

@ -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",

View File

@ -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);