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