tracing_subscriber/
sync.rs1#[allow(unused_imports)] pub(crate) use std::sync::{LockResult, PoisonError, TryLockResult};
12
13#[cfg(not(feature = "parking_lot"))]
14pub(crate) use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
15
16#[cfg(feature = "parking_lot")]
17pub(crate) use self::parking_lot_impl::*;
18
19#[cfg(feature = "parking_lot")]
20mod parking_lot_impl {
21 pub(crate) use parking_lot::{RwLockReadGuard, RwLockWriteGuard};
22 use std::sync::{LockResult, TryLockError, TryLockResult};
23
24 #[derive(Debug)]
25 pub(crate) struct RwLock<T> {
26 inner: parking_lot::RwLock<T>,
27 }
28
29 impl<T> RwLock<T> {
30 pub(crate) fn new(val: T) -> Self {
31 Self {
32 inner: parking_lot::RwLock::new(val),
33 }
34 }
35
36 #[inline]
37 pub(crate) fn get_mut(&mut self) -> LockResult<&mut T> {
38 Ok(self.inner.get_mut())
39 }
40
41 #[inline]
42 pub(crate) fn read(&self) -> LockResult<RwLockReadGuard<'_, T>> {
43 Ok(self.inner.read())
44 }
45
46 #[inline]
47 #[allow(dead_code)] pub(crate) fn try_read(&self) -> TryLockResult<RwLockReadGuard<'_, T>> {
49 self.inner.try_read().ok_or(TryLockError::WouldBlock)
50 }
51
52 #[inline]
53 pub(crate) fn write(&self) -> LockResult<RwLockWriteGuard<'_, T>> {
54 Ok(self.inner.write())
55 }
56 }
57}