|
|
@ -29,22 +29,22 @@ static mut THREAD_ID: libc::pthread_t = MAIN_THREAD_ID; |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)] |
|
|
|
#[derive(Copy, Clone)] |
|
|
|
struct PThread { |
|
|
|
struct PThread { |
|
|
|
thread: SendPtr<ctru_sys::Thread_tag>, |
|
|
|
thread: ShareablePtr<ctru_sys::Thread_tag>, |
|
|
|
os_thread_id: u32, |
|
|
|
os_thread_id: u32, |
|
|
|
is_detached: bool, |
|
|
|
is_detached: bool, |
|
|
|
is_finished: bool, |
|
|
|
is_finished: bool, |
|
|
|
result: SendPtr<libc::c_void>, |
|
|
|
result: ShareablePtr<libc::c_void>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Pointers are not Send, though it's really just a lint. This struct lets us
|
|
|
|
/// Pointers are not Send or Sync, though it's really just a lint. This struct
|
|
|
|
/// ignore that "lint".
|
|
|
|
/// lets us ignore that "lint".
|
|
|
|
struct SendPtr<T>(*mut T); |
|
|
|
struct ShareablePtr<T>(*mut T); |
|
|
|
unsafe impl<T> Send for SendPtr<T> {} |
|
|
|
unsafe impl<T> Send for ShareablePtr<T> {} |
|
|
|
unsafe impl<T> Sync for SendPtr<T> {} |
|
|
|
unsafe impl<T> Sync for ShareablePtr<T> {} |
|
|
|
|
|
|
|
|
|
|
|
// We can't use the derives because they add an unnecessary T: Copy/Clone bound.
|
|
|
|
// We can't use the derives because they add an unnecessary T: Copy/Clone bound.
|
|
|
|
impl<T> Copy for SendPtr<T> {} |
|
|
|
impl<T> Copy for ShareablePtr<T> {} |
|
|
|
impl<T> Clone for SendPtr<T> { |
|
|
|
impl<T> Clone for ShareablePtr<T> { |
|
|
|
fn clone(&self) -> Self { |
|
|
|
fn clone(&self) -> Self { |
|
|
|
*self |
|
|
|
*self |
|
|
|
} |
|
|
|
} |
|
|
@ -128,11 +128,11 @@ pub unsafe extern "C" fn pthread_create( |
|
|
|
THREADS.write().insert( |
|
|
|
THREADS.write().insert( |
|
|
|
thread_id, |
|
|
|
thread_id, |
|
|
|
PThread { |
|
|
|
PThread { |
|
|
|
thread: SendPtr(thread), |
|
|
|
thread: ShareablePtr(thread), |
|
|
|
os_thread_id, |
|
|
|
os_thread_id, |
|
|
|
is_detached: false, |
|
|
|
is_detached: false, |
|
|
|
is_finished: false, |
|
|
|
is_finished: false, |
|
|
|
result: SendPtr(ptr::null_mut()), |
|
|
|
result: ShareablePtr(ptr::null_mut()), |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
@ -232,11 +232,11 @@ pub unsafe extern "C" fn pthread_self() -> libc::pthread_t { |
|
|
|
PThread { |
|
|
|
PThread { |
|
|
|
// This null pointer is safe because we return before ever using
|
|
|
|
// This null pointer is safe because we return before ever using
|
|
|
|
// it (in pthread_join and pthread_detach).
|
|
|
|
// it (in pthread_join and pthread_detach).
|
|
|
|
thread: SendPtr(ptr::null_mut()), |
|
|
|
thread: ShareablePtr(ptr::null_mut()), |
|
|
|
os_thread_id, |
|
|
|
os_thread_id, |
|
|
|
is_detached: true, |
|
|
|
is_detached: true, |
|
|
|
is_finished: false, |
|
|
|
is_finished: false, |
|
|
|
result: SendPtr(ptr::null_mut()), |
|
|
|
result: ShareablePtr(ptr::null_mut()), |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|