/rust/registry/src/index.crates.io-1949cf8c6b5b557f/concurrent-queue-2.5.0/src/sync.rs
Line | Count | Source |
1 | | //! Synchronization facade to choose between `core` primitives and `loom` primitives. |
2 | | |
3 | | #[cfg(all(feature = "portable-atomic", not(loom)))] |
4 | | mod sync_impl { |
5 | | pub(crate) use core::cell; |
6 | | pub(crate) use portable_atomic as atomic; |
7 | | |
8 | | #[cfg(not(feature = "std"))] |
9 | | pub(crate) use atomic::hint::spin_loop; |
10 | | |
11 | | #[cfg(feature = "std")] |
12 | | pub(crate) use std::thread::yield_now; |
13 | | } |
14 | | |
15 | | #[cfg(all(not(feature = "portable-atomic"), not(loom)))] |
16 | | mod sync_impl { |
17 | | pub(crate) use core::cell; |
18 | | pub(crate) use core::sync::atomic; |
19 | | |
20 | | #[cfg(not(feature = "std"))] |
21 | | #[inline] |
22 | | pub(crate) fn spin_loop() { |
23 | | #[allow(deprecated)] |
24 | | atomic::spin_loop_hint(); |
25 | | } |
26 | | |
27 | | #[cfg(feature = "std")] |
28 | | pub(crate) use std::thread::yield_now; |
29 | | } |
30 | | |
31 | | #[cfg(loom)] |
32 | | mod sync_impl { |
33 | | pub(crate) use loom::cell; |
34 | | |
35 | | pub(crate) mod atomic { |
36 | | pub(crate) use loom::sync::atomic::*; |
37 | | } |
38 | | |
39 | | #[cfg(not(feature = "std"))] |
40 | | pub(crate) use loom::hint::spin_loop; |
41 | | #[cfg(feature = "std")] |
42 | | pub(crate) use loom::thread::yield_now; |
43 | | } |
44 | | |
45 | | pub(crate) use sync_impl::*; |
46 | | |
47 | | /// Notify the CPU that we are currently busy-waiting. |
48 | | #[inline] |
49 | 0 | pub(crate) fn busy_wait() { |
50 | | #[cfg(feature = "std")] |
51 | 0 | yield_now(); |
52 | | |
53 | | #[cfg(not(feature = "std"))] |
54 | | spin_loop(); |
55 | 0 | } Unexecuted instantiation: concurrent_queue::sync::busy_wait Unexecuted instantiation: concurrent_queue::sync::busy_wait Unexecuted instantiation: concurrent_queue::sync::busy_wait |
56 | | |
57 | | #[cfg(loom)] |
58 | | pub(crate) mod prelude {} |
59 | | |
60 | | #[cfg(not(loom))] |
61 | | pub(crate) mod prelude { |
62 | | use super::{atomic, cell}; |
63 | | |
64 | | /// Emulate `loom::UnsafeCell`'s API. |
65 | | pub(crate) trait UnsafeCellExt { |
66 | | type Value; |
67 | | |
68 | | fn with_mut<R, F>(&self, f: F) -> R |
69 | | where |
70 | | F: FnOnce(*mut Self::Value) -> R; |
71 | | } |
72 | | |
73 | | impl<T> UnsafeCellExt for cell::UnsafeCell<T> { |
74 | | type Value = T; |
75 | | |
76 | 0 | fn with_mut<R, F>(&self, f: F) -> R |
77 | 0 | where |
78 | 0 | F: FnOnce(*mut Self::Value) -> R, |
79 | | { |
80 | 0 | f(self.get()) |
81 | 0 | } Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<surrealdb_types::notification::Notification, <concurrent_queue::single::Single<surrealdb_types::notification::Notification>>::pop::{closure#1}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<surrealdb_types::notification::Notification, <concurrent_queue::bounded::Bounded<surrealdb_types::notification::Notification>>::pop::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<surrealdb_types::notification::Notification, <concurrent_queue::unbounded::Unbounded<surrealdb_types::notification::Notification>>::pop::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>, <concurrent_queue::single::Single<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>>::pop::{closure#1}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>, <concurrent_queue::bounded::Bounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>>::pop::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>, <concurrent_queue::unbounded::Unbounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>>::pop::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<(), <concurrent_queue::bounded::Bounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>>::push_or_else<<concurrent_queue::bounded::Bounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>>::push::{closure#0}>::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<(), <concurrent_queue::unbounded::Unbounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}::{closure#0}::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<(), <concurrent_queue::bounded::Bounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<(), <concurrent_queue::single::Single<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<(), <concurrent_queue::single::Single<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>>::push::{closure#1}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<(), <concurrent_queue::unbounded::Unbounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>>::push::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<(), <concurrent_queue::bounded::Bounded<surrealdb_types::notification::Notification>>::push_or_else<<concurrent_queue::bounded::Bounded<surrealdb_types::notification::Notification>>::push::{closure#0}>::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<(), <concurrent_queue::unbounded::Unbounded<surrealdb_types::notification::Notification> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}::{closure#0}::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<(), <concurrent_queue::bounded::Bounded<surrealdb_types::notification::Notification> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<(), <concurrent_queue::single::Single<surrealdb_types::notification::Notification> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<(), <concurrent_queue::single::Single<surrealdb_types::notification::Notification>>::push::{closure#1}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<(), <concurrent_queue::unbounded::Unbounded<surrealdb_types::notification::Notification>>::push::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<surrealdb_types::notification::Notification, <concurrent_queue::single::Single<surrealdb_types::notification::Notification>>::pop::{closure#1}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<surrealdb_types::notification::Notification, <concurrent_queue::bounded::Bounded<surrealdb_types::notification::Notification>>::pop::{closure#0}>Unexecuted instantiation: <core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::UnsafeCellExt>::with_mut::<surrealdb_types::notification::Notification, <concurrent_queue::unbounded::Unbounded<surrealdb_types::notification::Notification>>::pop::{closure#0}> |
82 | | } |
83 | | |
84 | | /// Emulate `loom::Atomic*`'s API. |
85 | | pub(crate) trait AtomicExt { |
86 | | type Value; |
87 | | |
88 | | fn with_mut<R, F>(&mut self, f: F) -> R |
89 | | where |
90 | | F: FnOnce(&mut Self::Value) -> R; |
91 | | } |
92 | | |
93 | | impl AtomicExt for atomic::AtomicUsize { |
94 | | type Value = usize; |
95 | | |
96 | 2 | fn with_mut<R, F>(&mut self, f: F) -> R |
97 | 2 | where |
98 | 2 | F: FnOnce(&mut Self::Value) -> R, |
99 | | { |
100 | 2 | f(self.get_mut()) |
101 | 2 | } Unexecuted instantiation: <core::sync::atomic::AtomicUsize as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::unbounded::Unbounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}>Unexecuted instantiation: <core::sync::atomic::AtomicUsize as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::unbounded::Unbounded<surrealdb_types::notification::Notification> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}><core::sync::atomic::AtomicUsize as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::bounded::Bounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}>Line | Count | Source | 96 | 1 | fn with_mut<R, F>(&mut self, f: F) -> R | 97 | 1 | where | 98 | 1 | F: FnOnce(&mut Self::Value) -> R, | 99 | | { | 100 | 1 | f(self.get_mut()) | 101 | 1 | } |
Unexecuted instantiation: <core::sync::atomic::AtomicUsize as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::bounded::Bounded<surrealdb_types::notification::Notification> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}>Unexecuted instantiation: <core::sync::atomic::AtomicUsize as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::unbounded::Unbounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>> as core::ops::drop::Drop>::drop::{closure#0}>Unexecuted instantiation: <core::sync::atomic::AtomicUsize as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::unbounded::Unbounded<surrealdb_types::notification::Notification> as core::ops::drop::Drop>::drop::{closure#0}>Unexecuted instantiation: <core::sync::atomic::AtomicUsize as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::single::Single<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>> as core::ops::drop::Drop>::drop::{closure#0}>Unexecuted instantiation: <core::sync::atomic::AtomicUsize as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::single::Single<surrealdb_types::notification::Notification> as core::ops::drop::Drop>::drop::{closure#0}><core::sync::atomic::AtomicUsize as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::bounded::Bounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>> as core::ops::drop::Drop>::drop::{closure#0}>Line | Count | Source | 96 | 1 | fn with_mut<R, F>(&mut self, f: F) -> R | 97 | 1 | where | 98 | 1 | F: FnOnce(&mut Self::Value) -> R, | 99 | | { | 100 | 1 | f(self.get_mut()) | 101 | 1 | } |
Unexecuted instantiation: <core::sync::atomic::AtomicUsize as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::bounded::Bounded<surrealdb_types::notification::Notification> as core::ops::drop::Drop>::drop::{closure#0}> |
102 | | } |
103 | | |
104 | | impl<T> AtomicExt for atomic::AtomicPtr<T> { |
105 | | type Value = *mut T; |
106 | | |
107 | 0 | fn with_mut<R, F>(&mut self, f: F) -> R |
108 | 0 | where |
109 | 0 | F: FnOnce(&mut Self::Value) -> R, |
110 | | { |
111 | 0 | f(self.get_mut()) |
112 | 0 | } Unexecuted instantiation: <core::sync::atomic::AtomicPtr<concurrent_queue::unbounded::Block<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>> as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<*mut concurrent_queue::unbounded::Block<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>, <concurrent_queue::unbounded::Unbounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}::{closure#1}::{closure#0}>Unexecuted instantiation: <core::sync::atomic::AtomicPtr<concurrent_queue::unbounded::Block<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>> as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::unbounded::Unbounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}::{closure#0}>Unexecuted instantiation: <core::sync::atomic::AtomicPtr<concurrent_queue::unbounded::Block<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>> as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::unbounded::Unbounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}::{closure#2}>Unexecuted instantiation: <core::sync::atomic::AtomicPtr<concurrent_queue::unbounded::Block<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>>> as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::unbounded::Unbounded<core::result::Result<surrealdb_core::exec::ValueBatch, surrealdb_core::expr::ControlFlow>> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}::{closure#1}>Unexecuted instantiation: <core::sync::atomic::AtomicPtr<concurrent_queue::unbounded::Block<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<*mut concurrent_queue::unbounded::Block<surrealdb_types::notification::Notification>, <concurrent_queue::unbounded::Unbounded<surrealdb_types::notification::Notification> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}::{closure#1}::{closure#0}>Unexecuted instantiation: <core::sync::atomic::AtomicPtr<concurrent_queue::unbounded::Block<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::unbounded::Unbounded<surrealdb_types::notification::Notification> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}::{closure#0}>Unexecuted instantiation: <core::sync::atomic::AtomicPtr<concurrent_queue::unbounded::Block<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::unbounded::Unbounded<surrealdb_types::notification::Notification> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}::{closure#2}>Unexecuted instantiation: <core::sync::atomic::AtomicPtr<concurrent_queue::unbounded::Block<surrealdb_types::notification::Notification>> as concurrent_queue::sync::prelude::AtomicExt>::with_mut::<(), <concurrent_queue::unbounded::Unbounded<surrealdb_types::notification::Notification> as core::ops::drop::Drop>::drop::{closure#0}::{closure#0}::{closure#1}> |
113 | | } |
114 | | } |