Cleanup: Use `AtomicStatusFlags::new(flags)` instead of `AtomicU32::new(flags.bits())`

This commit is contained in:
Wang Siyuan 2025-12-27 03:23:15 +00:00 committed by Tate, Hongliang Tian
parent 4a88b6aa86
commit 1e77c0a938
3 changed files with 29 additions and 13 deletions

View File

@ -2,10 +2,7 @@
//! Opened Inode-backed File Handle
use core::{
fmt::Display,
sync::atomic::{AtomicU32, Ordering},
};
use core::{fmt::Display, sync::atomic::Ordering};
use aster_rights::Rights;
@ -18,8 +15,8 @@ use crate::{
path::Path,
pipe::PipeHandle,
utils::{
AccessMode, CreationFlags, DirentVisitor, FallocMode, FileRange, FlockItem, InodeType,
OFFSET_MAX, RangeLockItem, RangeLockType, SeekFrom, StatusFlags,
AccessMode, AtomicStatusFlags, CreationFlags, DirentVisitor, FallocMode, FileRange,
FlockItem, InodeType, OFFSET_MAX, RangeLockItem, RangeLockType, SeekFrom, StatusFlags,
},
},
prelude::*,
@ -34,7 +31,7 @@ pub struct InodeHandle {
/// be provided by `file_io`, instead of `path`.
file_io: Option<Box<dyn FileIo>>,
offset: Mutex<usize>,
status_flags: AtomicU32,
status_flags: AtomicStatusFlags,
rights: Rights,
}
@ -71,7 +68,7 @@ impl InodeHandle {
path,
file_io,
offset: Mutex::new(0),
status_flags: AtomicU32::new(status_flags.bits()),
status_flags: AtomicStatusFlags::new(status_flags),
rights,
})
}
@ -360,8 +357,7 @@ impl FileLike for InodeHandle {
}
fn status_flags(&self) -> StatusFlags {
let bits = self.status_flags.load(Ordering::Relaxed);
StatusFlags::from_bits(bits).unwrap()
self.status_flags.load(Ordering::Relaxed)
}
fn set_status_flags(&self, new_status_flags: StatusFlags) -> Result<()> {
@ -377,8 +373,7 @@ impl FileLike for InodeHandle {
crate::fs::pipe::check_status_flags(new_status_flags)?;
}
self.status_flags
.store(new_status_flags.bits(), Ordering::Relaxed);
self.status_flags.store(new_status_flags, Ordering::Relaxed);
Ok(())
}

View File

@ -23,7 +23,7 @@ pub use page_cache::{CachePage, PageCache, PageCacheBackend};
#[cfg(ktest)]
pub use random_test::{generate_random_operation, new_fs_in_memory};
pub use range_lock::{FileRange, OFFSET_MAX, RangeLockItem, RangeLockList, RangeLockType};
pub use status_flags::StatusFlags;
pub use status_flags::{AtomicStatusFlags, StatusFlags};
pub use xattr::{
XATTR_LIST_MAX_LEN, XATTR_NAME_MAX_LEN, XATTR_VALUE_MAX_LEN, XattrName, XattrNamespace,
XattrSetFlags,

View File

@ -1,5 +1,8 @@
// SPDX-License-Identifier: MPL-2.0
use core::sync::atomic::AtomicU32;
use atomic_integer_wrapper::define_atomic_version_of_integer_like_type;
use bitflags::bitflags;
bitflags! {
@ -23,3 +26,21 @@ bitflags! {
const O_PATH = 1 << 21;
}
}
impl From<u32> for StatusFlags {
fn from(value: u32) -> Self {
Self::from_bits_truncate(value)
}
}
impl From<StatusFlags> for u32 {
fn from(value: StatusFlags) -> Self {
value.bits()
}
}
define_atomic_version_of_integer_like_type!(StatusFlags, {
/// An atomic version of `StatusFlags`.
#[derive(Debug)]
pub struct AtomicStatusFlags(AtomicU32);
});