diff options
| author | tyler <tyler@brainiumstudios.com> | 2019-04-27 08:01:32 -0700 |
|---|---|---|
| committer | tyler <tyler@brainiumstudios.com> | 2019-05-15 07:30:33 -0700 |
| commit | 430a091cd80c0e4b6bf44f6a19463a832e566f97 (patch) | |
| tree | 9c9d3baeed0c0eab8d434a76b41148997d42611a /src/libstd/sys/unix | |
| parent | ae4be16e407061828fe604b1ccbd61181b14a3f1 (diff) | |
| download | rust-430a091cd80c0e4b6bf44f6a19463a832e566f97.tar.gz rust-430a091cd80c0e4b6bf44f6a19463a832e566f97.zip | |
ensure fast thread local lookups occur once per access on macos
Diffstat (limited to 'src/libstd/sys/unix')
| -rw-r--r-- | src/libstd/sys/unix/fast_thread_local.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libstd/sys/unix/fast_thread_local.rs b/src/libstd/sys/unix/fast_thread_local.rs index c34c2e6e786..28fb9800541 100644 --- a/src/libstd/sys/unix/fast_thread_local.rs +++ b/src/libstd/sys/unix/fast_thread_local.rs @@ -82,3 +82,20 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { } } } + +#[cfg(not(target_os = "macos"))] +pub unsafe fn lookup_once<T>(ptr: *const &T) -> &T { + *ptr +} + +#[cfg(target_os = "macos")] +pub unsafe fn lookup_once<T>(ptr: *const &T) -> &T { + // On macos, thread_local lookups can result in terrible code due to + // aggressive rerunning of the macos equivalent of `__tls_get_addr` - four + // lookups per actual reference in user code. + // + // Using a read_volatile on a value holding fast Key's address tricks the + // optimizer into only calling the macos get_addr equivalent once per time + // requested by the user. + crate::ptr::read_volatile(ptr) +} |
