use core::ffi::c_ulong;
use core::num::NonZero;
#[cfg(not(wip_feature_std))]
pub use thread_local::*;
#[cfg(not(wip_feature_std))]
mod thread_local;
#[cfg(not(wip_feature_std))]
use pyo3_ffi::PyThread_get_thread_ident;
#[must_use]
pub fn current() -> Thread {
cfg_select! {
wip_feature_std => Thread { id: ThreadId(std::thread::current().id()) },
_ => Thread {
id: ThreadId(unsafe { NonZero::new_unchecked(PyThread_get_thread_ident()) }),
}
}
}
pub struct Thread {
id: ThreadId,
}
impl Thread {
pub fn id(&self) -> ThreadId {
self.id
}
}
#[cfg(wip_feature_std)]
#[expect(clippy::disallowed_types)]
mod std_feature {
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct ThreadId(pub(super) std::thread::ThreadId);
}
#[cfg(wip_feature_std)]
pub use std_feature::ThreadId;
#[cfg(not(wip_feature_std))]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct ThreadId(NonZero<c_ulong>);
#[cfg(wip_feature_std)]
pub use std::thread::{AccessError, LocalKey};