Skip to content

Commit

Permalink
[style] rename AxResource as ResArc
Browse files Browse the repository at this point in the history
  • Loading branch information
Azure-stars committed Feb 9, 2025
1 parent 5723dce commit aa4c2a6
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
23 changes: 21 additions & 2 deletions api/arceos_posix_api/src/imp/fd_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::ffi::c_int;

use axerrno::{LinuxError, LinuxResult};
use axio::PollState;
use axns::{AxResource, def_resource};
use axns::{ResArc, def_resource};
use flatten_objects::FlattenObjects;
use spin::RwLock;

Expand All @@ -23,7 +23,7 @@ pub trait FileLike: Send + Sync {

def_resource! {
#[allow(non_camel_case_types)]
pub(crate) static FD_TABLE: AxResource<RwLock<FlattenObjects<Arc<dyn FileLike>, AX_FILE_LIMIT>>> = AxResource::new();
pub(crate) static FD_TABLE: ResArc<RwLock<FlattenObjects<Arc<dyn FileLike>, AX_FILE_LIMIT>>> = ResArc::new();
}

pub fn get_file_like(fd: c_int) -> LinuxResult<Arc<dyn FileLike>> {
Expand Down Expand Up @@ -122,3 +122,22 @@ pub fn sys_fcntl(fd: c_int, cmd: c_int, arg: usize) -> c_int {
}
})
}

#[ctor_bare::register_ctor]
#[cfg(feature = "fd")]
fn init_stdio() {
use crate::imp::fd_ops::FD_TABLE;
use crate::imp::stdio::{stdin, stdout};
use alloc::sync::Arc;
let mut fd_table = flatten_objects::FlattenObjects::new();
fd_table
.add_at(0, Arc::new(stdin()) as _)
.unwrap_or_else(|_| panic!()); // stdin
fd_table
.add_at(1, Arc::new(stdout()) as _)
.unwrap_or_else(|_| panic!()); // stdout
fd_table
.add_at(2, Arc::new(stdout()) as _)
.unwrap_or_else(|_| panic!()); // stderr
FD_TABLE.init_new(spin::RwLock::new(fd_table));
}
19 changes: 0 additions & 19 deletions api/arceos_posix_api/src/imp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,3 @@ pub mod net;
pub mod pipe;
#[cfg(feature = "multitask")]
pub mod pthread;

#[ctor_bare::register_ctor]
#[cfg(feature = "fd")]
fn init_stdio() {
use crate::imp::fd_ops::FD_TABLE;
use alloc::sync::Arc;
use stdio::{stdin, stdout};
let mut fd_table = flatten_objects::FlattenObjects::new();
fd_table
.add_at(0, Arc::new(stdin()) as _)
.unwrap_or_else(|_| panic!()); // stdin
fd_table
.add_at(1, Arc::new(stdout()) as _)
.unwrap_or_else(|_| panic!()); // stdout
fd_table
.add_at(2, Arc::new(stdout()) as _)
.unwrap_or_else(|_| panic!()); // stderr
FD_TABLE.init_new(spin::RwLock::new(fd_table));
}
6 changes: 3 additions & 3 deletions modules/axfs/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
use alloc::{string::String, sync::Arc, vec::Vec};
use axerrno::{AxError, AxResult, ax_err};
use axfs_vfs::{VfsNodeAttr, VfsNodeOps, VfsNodeRef, VfsNodeType, VfsOps, VfsResult};
use axns::{AxResource, def_resource};
use axns::{ResArc, def_resource};
use axsync::Mutex;
use lazyinit::LazyInit;

use crate::{api::FileType, fs, mounts};

def_resource! {
#[allow(non_camel_case_types)]
static CURRENT_DIR_PATH: AxResource<Mutex<String>> = AxResource::new();
static CURRENT_DIR_PATH: ResArc<Mutex<String>> = ResArc::new();
#[allow(non_camel_case_types)]
static CURRENT_DIR: AxResource<Mutex<VfsNodeRef>> = AxResource::new();
static CURRENT_DIR: ResArc<Mutex<VfsNodeRef>> = ResArc::new();
}

struct MountPoint {
Expand Down
16 changes: 8 additions & 8 deletions modules/axns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ impl Drop for AxNamespace {
///
/// It provides methods to lazily initialize the resource of the current thread,
/// or to share the resource with other threads.
pub struct AxResource<T>(LazyInit<Arc<T>>);
pub struct ResArc<T>(LazyInit<Arc<T>>);

impl<T> AxResource<T> {
impl<T> ResArc<T> {
/// Creates a new uninitialized resource.
pub const fn new() -> Self {
Self(LazyInit::new())
Expand All @@ -142,15 +142,15 @@ impl<T> AxResource<T> {
}
}

impl<T> Deref for AxResource<T> {
impl<T> Deref for ResArc<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
self.0.deref()
}
}

impl<T: fmt::Debug> fmt::Debug for AxResource<T> {
impl<T: fmt::Debug> fmt::Debug for ResArc<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
Expand Down Expand Up @@ -195,11 +195,11 @@ pub unsafe fn current_namespace_base() -> *mut u8 {
/// # Example
///
/// ```
/// use axns::AxResource;
/// use axns::ResArc;
///
/// axns::def_resource! {
/// static FOO: u32 = 42;
/// static BAR: AxResource<String> = AxResource::new();
/// static BAR: ResArc<String> = ResArc::new();
/// }
///
/// BAR.init_new("hello world".to_string());
Expand All @@ -209,10 +209,10 @@ pub unsafe fn current_namespace_base() -> *mut u8 {
/// mod imp {
/// use axns::{AxNamespace, AxNamespaceIf};
///
/// struct AxResourceImpl;
/// struct ResArcImpl;
///
/// #[crate_interface::impl_interface]
/// impl AxNamespaceIf for AxResourceImpl {
/// impl AxNamespaceIf for ResArcImpl {
/// fn current_namespace_base() -> *mut u8 {
/// AxNamespace::global().base()
/// }
Expand Down
6 changes: 3 additions & 3 deletions modules/axns/tests/test_global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Barrier, Mutex};
use std::thread;

use axns::{AxResource, def_resource};
use axns::{ResArc, def_resource};

use self::imp::thread_init_namespace;

def_resource! {
static FOO: AxResource<AtomicUsize> = AxResource::new();
static BAR: AxResource<Mutex<String>> = AxResource::new();
static FOO: ResArc<AtomicUsize> = ResArc::new();
static BAR: ResArc<Mutex<String>> = ResArc::new();
}

static BARRIER: Barrier = Barrier::new(3);
Expand Down
6 changes: 3 additions & 3 deletions modules/axns/tests/test_thread_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Barrier, Mutex};
use std::thread;

use axns::{AxResource, def_resource};
use axns::{ResArc, def_resource};

use self::imp::thread_init_namespace;

def_resource! {
static FOO: AxResource<AtomicUsize> = AxResource::new();
static BAR: AxResource<Mutex<String>> = AxResource::new();
static FOO: ResArc<AtomicUsize> = ResArc::new();
static BAR: ResArc<Mutex<String>> = ResArc::new();
}

static BARRIER: Barrier = Barrier::new(3);
Expand Down
4 changes: 2 additions & 2 deletions modules/axruntime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ pub extern "C" fn rust_main(cpu_id: usize, dtb: usize) -> ! {
init_tls();
}

ctor_bare::call_ctors();

info!("Primary CPU {} init OK.", cpu_id);
INITED_CPUS.fetch_add(1, Ordering::Relaxed);

ctor_bare::call_ctors();

while !is_init_ok() {
core::hint::spin_loop();
}
Expand Down

0 comments on commit aa4c2a6

Please sign in to comment.