Lines Matching full:guard
9 /// A guard that keeps the current thread pinned.
13 /// The current thread is pinned by calling [`pin`], which returns a new guard:
19 /// // This is not really necessary, but makes passing references to the guard a bit easier.
20 /// let guard = &epoch::pin();
23 /// When a guard gets dropped, the current thread is automatically unpinned.
27 /// Having a guard allows us to create pointers on the stack to heap-allocated objects.
38 /// let guard = &epoch::pin();
41 /// let p = a.load(SeqCst, guard);
53 /// thread will actually be pinned only when the first guard is created and unpinned when the last
69 pub struct Guard { struct
73 impl Guard { argument
87 /// If this method is called from an [`unprotected`] guard, the function will simply be
112 /// If this method is called from an [`unprotected`] guard, the function will simply be
124 /// let guard = &epoch::pin();
128 /// guard.defer_unchecked(move || {
142 /// let shared = Owned::new(7i32).into_shared(guard);
143 /// guard.defer_unchecked(move || shared.into_owned()); // `Shared` is not `Send`!
168 /// let guard = &epoch::pin();
171 /// let p = a.swap(Owned::new("bar").into_shared(guard), SeqCst, guard);
178 /// guard.defer_unchecked(move || {
212 /// If this method is called from an [`unprotected`] guard, the destructor will simply be
228 /// let shared = Owned::new(7i32).into_shared(guard);
229 /// guard.defer_destroy(shared); // `Shared` is not `Send`!
254 /// let guard = &epoch::pin();
257 /// let p = a.swap(Owned::new("bar").into_shared(guard), SeqCst, guard);
263 /// guard.defer_destroy(p);
279 /// If this method is called from an [`unprotected`] guard, it is a no-op (nothing happens).
286 /// let guard = &epoch::pin();
287 /// guard.defer(move || {
290 /// guard.flush();
301 /// holding an old epoch. For safety, you should not maintain any guard-based reference across
303 /// is the only active guard for the current thread.
305 /// If this method is called from an [`unprotected`] guard, then the call will be just no-op.
314 /// let mut guard = epoch::pin();
316 /// let p = a.load(SeqCst, &guard);
319 /// guard.repin();
321 /// let p = a.load(SeqCst, &guard);
335 /// and don't need to maintain any guard-based reference across the call (the latter is enforced
336 /// by `&mut self`). The thread will only be unpinned if this is the only active guard for the
339 /// If this method is called from an [`unprotected`] guard, then the passed function is called
351 /// let mut guard = epoch::pin();
353 /// let p = a.load(SeqCst, &guard);
356 /// guard.repin_after(|| thread::sleep(Duration::from_millis(50)));
358 /// let p = a.load(SeqCst, &guard);
367 // Ensure the Guard is re-pinned even if the function panics in repin_after()
390 /// Returns the `Collector` associated with this guard.
395 /// If this method is called from an [`unprotected`] guard, then `None` is returned.
411 impl Drop for Guard { implementation
420 impl fmt::Debug for Guard { implementation
422 f.pad("Guard { .. }") in fmt()
426 /// Returns a reference to a dummy guard that allows unprotected access to [`Atomic`]s.
428 /// This guard should be used in special occasions only. Note that it doesn't actually keep any
429 /// thread pinned - it's just a fake guard that allows loading from [`Atomic`]s unsafely.
431 /// Note that calling [`defer`] with a dummy guard will not defer the function - it will just
438 /// Loading and dereferencing data from an [`Atomic`] using this guard is safe only if the
467 /// For example, we can use a dummy guard in the destructor of a Treiber stack because at that
511 /// [`defer`]: Guard::defer
513 pub unsafe fn unprotected() -> &'static Guard { in unprotected()
514 // An unprotected guard is just a `Guard` with its field `local` set to null. in unprotected()
515 // We make a newtype over `Guard` because `Guard` isn't `Sync`, so can't be directly stored in in unprotected()
517 struct GuardWrapper(Guard); in unprotected()
519 static UNPROTECTED: GuardWrapper = GuardWrapper(Guard { in unprotected()