about summary refs log tree commit diff
diff options
context:
space:
mode:
authorzachs18 <8355914+zachs18@users.noreply.github.com>2024-07-08 09:19:25 -0500
committerGitHub <noreply@github.com>2024-07-08 09:19:25 -0500
commit8bcbab5dd1c6449c2acd3ea6a94b245c0936722d (patch)
treea31deb3ded90409ea6b4ffeec738ac40c9ba222c
parent98010765f949307bf53ebb692e45e428ba318aa1 (diff)
downloadrust-8bcbab5dd1c6449c2acd3ea6a94b245c0936722d.tar.gz
rust-8bcbab5dd1c6449c2acd3ea6a94b245c0936722d.zip
Attempt to fix CI
-rw-r--r--library/std/src/sys/exit_guard.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/library/std/src/sys/exit_guard.rs b/library/std/src/sys/exit_guard.rs
index ad6246cc831..5a090f50666 100644
--- a/library/std/src/sys/exit_guard.rs
+++ b/library/std/src/sys/exit_guard.rs
@@ -1,5 +1,14 @@
 cfg_if::cfg_if! {
     if #[cfg(target_os = "linux")] {
+        /// pthread_t is a pointer on some platforms,
+        /// so we wrap it in this to impl Send + Sync.
+        #[derive(Clone, Copy)]
+        #[repr(transparent)]
+        struct PThread(libc::pthread_t);
+        // Safety: pthread_t is safe to send between threads
+        unsafe impl Send for PThread {}
+        // Safety: pthread_t is safe to share between threads
+        unsafe impl Sync for PThread {}
         /// Mitigation for <https://github.com/rust-lang/rust/issues/126600>
         ///
         /// On glibc, `libc::exit` has been observed to not always be thread-safe.
@@ -23,7 +32,7 @@ cfg_if::cfg_if! {
         pub(crate) fn unique_thread_exit() {
             let this_thread_id = unsafe { libc::pthread_self() };
             use crate::sync::{Mutex, PoisonError};
-            static EXITING_THREAD_ID: Mutex<Option<libc::pthread_t>> = Mutex::new(None);
+            static EXITING_THREAD_ID: Mutex<Option<PThread>> = Mutex::new(None);
             let mut exiting_thread_id =
                 EXITING_THREAD_ID.lock().unwrap_or_else(PoisonError::into_inner);
             match *exiting_thread_id {
@@ -31,9 +40,9 @@ cfg_if::cfg_if! {
                     // This is the first thread to call `unique_thread_exit`,
                     // and this is the first time it is called.
                     // Set EXITING_THREAD_ID to this thread's ID and return.
-                    *exiting_thread_id = Some(this_thread_id);
+                    *exiting_thread_id = Some(PThread(this_thread_id));
                 },
-                Some(exiting_thread_id) if exiting_thread_id == this_thread_id => {
+                Some(exiting_thread_id) if exiting_thread_id.0 == this_thread_id => {
                     // This is the first thread to call `unique_thread_exit`,
                     // but this is the second time it is called.
                     // Abort the process.