1 // Manage the thread-local state, providing access to a `Participant` record.
3 use std
::sync
::atomic
::Ordering
::Relaxed
;
5 use epoch
::participant
::Participant
;
10 participant
: *const Participant
,
14 fn new() -> LocalEpoch
{
15 LocalEpoch { participant: global::get().participants.enroll() }
18 fn get(&self) -> &Participant
{
19 unsafe { &*self.participant }
23 // FIXME: avoid leaking when all threads have exited
24 impl Drop
for LocalEpoch
{
30 p
.active
.store(false, Relaxed
);
34 thread_local
!(static LOCAL_EPOCH
: LocalEpoch
= LocalEpoch
::new() );
36 pub fn with_participant
<F
, T
>(f
: F
) -> T
where F
: FnOnce(&Participant
) -> T
{
37 LOCAL_EPOCH
.with(|e
| f(e
.get()))