| 1 | |
| 2 |
|
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 |
|
| 8 | use crate::prelude::*;
|
| 9 | use crate::types::Opaque;
|
| 10 | use pin_init;
|
| 11 |
|
| 12 | mod arc;
|
| 13 | pub mod completion;
|
| 14 | mod condvar;
|
| 15 | pub mod lock;
|
| 16 | mod locked_by;
|
| 17 | pub mod poll;
|
| 18 | pub mod rcu;
|
| 19 |
|
| 20 | pub use arc::{Arc, ArcBorrow, UniqueArc};
|
| 21 | pub use completion::Completion;
|
| 22 | pub use condvar::{new_condvar, CondVar, CondVarTimeoutResult};
|
| 23 | pub use lock::global::{global_lock, GlobalGuard, GlobalLock, GlobalLockBackend, GlobalLockedBy};
|
| 24 | pub use lock::mutex::{new_mutex, Mutex, MutexGuard};
|
| 25 | pub use lock::spinlock::{new_spinlock, SpinLock, SpinLockGuard};
|
| 26 | pub use locked_by::LockedBy;
|
| 27 |
|
| 28 | |
| 29 | #[repr(transparent)]
|
| 30 | #[pin_data(PinnedDrop)]
|
| 31 | pub struct LockClassKey {
|
| 32 | #[pin]
|
| 33 | inner: Opaque<bindings::lock_class_key>,
|
| 34 | }
|
| 35 |
|
| 36 | |
| 37 | |
| 38 | unsafe impl Sync for LockClassKey {}
|
| 39 |
|
| 40 | impl LockClassKey {
|
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | pub fn new_dynamic() -> impl PinInit<Self> {
|
| 72 | pin_init!(Self {
|
| 73 | |
| 74 | inner <- Opaque::ffi_init(|slot| unsafe { bindings::lockdep_register_key(slot) })
|
| 75 | })
|
| 76 | }
|
| 77 |
|
| 78 | pub(crate) fn as_ptr(&self) -> *mut bindings::lock_class_key {
|
| 79 | self.inner.get()
|
| 80 | }
|
| 81 | }
|
| 82 |
|
| 83 | #[pinned_drop]
|
| 84 | impl PinnedDrop for LockClassKey {
|
| 85 | fn drop(self: Pin<&mut Self>) {
|
| 86 | |
| 87 | |
| 88 | unsafe { bindings::lockdep_unregister_key(self.as_ptr()) }
|
| 89 | }
|
| 90 | }
|
| 91 |
|
| 92 | |
| 93 | #[doc(hidden)]
|
| 94 | #[macro_export]
|
| 95 | macro_rules! static_lock_class {
|
| 96 | () => {{
|
| 97 | static CLASS: $crate::sync::LockClassKey =
|
| 98 | |
| 99 | |
| 100 | unsafe { ::core::mem::MaybeUninit::uninit().assume_init() };
|
| 101 | $crate::prelude::Pin::static_ref(&CLASS)
|
| 102 | }};
|
| 103 | }
|
| 104 |
|
| 105 | |
| 106 | |
| 107 | #[doc(hidden)]
|
| 108 | #[macro_export]
|
| 109 | macro_rules! optional_name {
|
| 110 | () => {
|
| 111 | $crate::c_str!(::core::concat!(::core::file!(), ":", ::core::line!()))
|
| 112 | };
|
| 113 | ($name:literal) => {
|
| 114 | $crate::c_str!($name)
|
| 115 | };
|
| 116 | }
|