Skip to content

Commit

Permalink
Move current_thread_unique_ptr to the only module that uses it.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Apr 7, 2022
1 parent d5e0eaf commit 6888fb1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
10 changes: 9 additions & 1 deletion library/std/src/sys/unix/locks/futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::sync::atomic::{
Ordering::{Acquire, Relaxed, Release},
};
use crate::sys::futex::{futex_wait, futex_wake, futex_wake_all};
use crate::sys_common::thread_info::current_thread_unique_ptr;
use crate::time::Duration;

pub type MovableMutex = Mutex;
Expand Down Expand Up @@ -248,3 +247,12 @@ impl ReentrantMutex {
}
}
}

/// Get an address that is unique per running thread.
///
/// This can be used as a non-null usize-sized ID.
pub fn current_thread_unique_ptr() -> usize {
// Use a non-drop type to make sure it's still available during thread destruction.
thread_local! { static X: u8 = 0 }
X.with(|x| <*const _>::addr(x))
}
9 changes: 0 additions & 9 deletions library/std/src/sys_common/thread_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ impl ThreadInfo {
}
}

/// Get an address that is unique per running thread.
///
/// This can be used as a non-null usize-sized ID.
pub fn current_thread_unique_ptr() -> usize {
// Use a non-drop type to make sure it's still available during thread destruction.
thread_local! { static X: u8 = 0 }
X.with(|x| <*const _>::addr(x))
}

pub fn current_thread() -> Option<Thread> {
ThreadInfo::with(|info| info.thread.clone())
}
Expand Down

0 comments on commit 6888fb1

Please sign in to comment.