Skip to main content

rustc_thread_pool/
tlv.rs

1//! Allows access to the Rayon's thread local value
2//! which is preserved when moving jobs across threads
3
4use std::cell::Cell;
5use std::ptr;
6
7pub const TLV: ::std::thread::LocalKey<Cell<*const ()>> =
    {
        const __RUST_STD_INTERNAL_INIT: Cell<*const ()> =
            { Cell::new(ptr::null()) };
        unsafe {
            ::std::thread::LocalKey::new(const {
                        if ::std::mem::needs_drop::<Cell<*const ()>>() {
                            |_|
                                {
                                    #[thread_local]
                                    static __RUST_STD_INTERNAL_VAL:
                                        ::std::thread::local_impl::EagerStorage<Cell<*const ()>> =
                                        ::std::thread::local_impl::EagerStorage::new(__RUST_STD_INTERNAL_INIT);
                                    __RUST_STD_INTERNAL_VAL.get()
                                }
                        } else {
                            |_|
                                {
                                    #[thread_local]
                                    static __RUST_STD_INTERNAL_VAL: Cell<*const ()> =
                                        __RUST_STD_INTERNAL_INIT;
                                    &__RUST_STD_INTERNAL_VAL
                                }
                        }
                    })
        }
    };thread_local!(pub static TLV: Cell<*const ()> = const { Cell::new(ptr::null()) });
8
9#[derive(#[automatically_derived]
impl ::core::marker::Copy for Tlv { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Tlv {
    #[inline]
    fn clone(&self) -> Tlv {
        let _: ::core::clone::AssertParamIsClone<*const ()>;
        *self
    }
}Clone)]
10pub(crate) struct Tlv(pub(crate) *const ());
11
12impl Tlv {
13    #[inline]
14    pub(crate) fn null() -> Self {
15        Self(ptr::null())
16    }
17}
18
19unsafe impl Sync for Tlv {}
20unsafe impl Send for Tlv {}
21
22/// Sets the current thread-local value
23#[inline]
24pub(crate) fn set(value: Tlv) {
25    TLV.with(|tlv| tlv.set(value.0));
26}
27
28/// Returns the current thread-local value
29#[inline]
30pub(crate) fn get() -> Tlv {
31    TLV.with(|tlv| Tlv(tlv.get()))
32}