about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHiroki Noda <kubo39@gmail.com>2020-02-02 21:25:38 +0900
committerHiroki Noda <kubo39@gmail.com>2020-02-16 19:53:42 +0900
commit67068f35dd41409c8e79710f1335cc9dc64f1860 (patch)
tree3cb93eab65ece97de74db5db3ed65485e0a5212d
parent0cbcb17d3306d6e22eafc2c05ce885db97d0189c (diff)
downloadrust-67068f35dd41409c8e79710f1335cc9dc64f1860.tar.gz
rust-67068f35dd41409c8e79710f1335cc9dc64f1860.zip
macOS: avoid calling pthread_self() twice
-rw-r--r--src/libstd/sys/unix/thread.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs
index 3ca778354e4..674d4c71138 100644
--- a/src/libstd/sys/unix/thread.rs
+++ b/src/libstd/sys/unix/thread.rs
@@ -255,8 +255,9 @@ pub mod guard {
 
     #[cfg(target_os = "macos")]
     unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
-        let stackaddr = libc::pthread_get_stackaddr_np(libc::pthread_self()) as usize
-            - libc::pthread_get_stacksize_np(libc::pthread_self());
+        let th = libc::pthread_self();
+        let stackaddr =
+            libc::pthread_get_stackaddr_np(th) as usize - libc::pthread_get_stacksize_np(th);
         Some(stackaddr as *mut libc::c_void)
     }