about summary refs log tree commit diff
path: root/src/libstd/thread/local.rs
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2017-08-13 16:42:10 +0300
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2017-09-04 08:24:06 +0300
commit4e2be14986b022dfdf5efa73293566cc6faf570e (patch)
tree2fe56e583ad5296c28d4590566078ba6a2f5ff4c /src/libstd/thread/local.rs
parenta3beb8fe61cb73c2eb3a2d47c87d3945a6f52865 (diff)
downloadrust-4e2be14986b022dfdf5efa73293566cc6faf570e.tar.gz
rust-4e2be14986b022dfdf5efa73293566cc6faf570e.zip
Make the LocalKey facade of thread_local! inlineable cross-crate.
Diffstat (limited to 'src/libstd/thread/local.rs')
-rw-r--r--src/libstd/thread/local.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs
index 02347bf4906..4ee8132f55c 100644
--- a/src/libstd/thread/local.rs
+++ b/src/libstd/thread/local.rs
@@ -159,8 +159,9 @@ macro_rules! thread_local {
 #[allow_internal_unstable]
 #[allow_internal_unsafe]
 macro_rules! __thread_local_inner {
-    ($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $init:expr) => {
-        $(#[$attr])* $vis static $name: $crate::thread::LocalKey<$t> = {
+    (@key $(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $init:expr) => {
+        {
+            #[inline]
             fn __init() -> $t { $init }
 
             unsafe fn __getit() -> $crate::option::Option<
@@ -182,7 +183,16 @@ macro_rules! __thread_local_inner {
             unsafe {
                 $crate::thread::LocalKey::new(__getit, __init)
             }
-        };
+        }
+    };
+    ($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $init:expr) => {
+        #[cfg(stage0)]
+        $(#[$attr])* $vis static $name: $crate::thread::LocalKey<$t> =
+            __thread_local_inner!(@key $(#[$attr])* $vis $name, $t, $init);
+
+        #[cfg(not(stage0))]
+        $(#[$attr])* $vis const $name: $crate::thread::LocalKey<$t> =
+            __thread_local_inner!(@key $(#[$attr])* $vis $name, $t, $init);
     }
 }