Use Freeze
for SourceFile.lines
This commit is contained in:
parent
c5996b80be
commit
f49382c050
11 changed files with 199 additions and 179 deletions
|
@ -3,6 +3,7 @@ use crate::sync::{AtomicBool, ReadGuard, RwLock, WriteGuard};
|
|||
use crate::sync::{DynSend, DynSync};
|
||||
use std::{
|
||||
cell::UnsafeCell,
|
||||
intrinsics::likely,
|
||||
marker::PhantomData,
|
||||
ops::{Deref, DerefMut},
|
||||
sync::atomic::Ordering,
|
||||
|
@ -49,6 +50,17 @@ impl<T> FreezeLock<T> {
|
|||
self.frozen.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
/// Get the inner value if frozen.
|
||||
#[inline]
|
||||
pub fn get(&self) -> Option<&T> {
|
||||
if likely(self.frozen.load(Ordering::Acquire)) {
|
||||
// SAFETY: This is frozen so the data cannot be modified.
|
||||
unsafe { Some(&*self.data.get()) }
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn read(&self) -> FreezeReadGuard<'_, T> {
|
||||
FreezeReadGuard {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue