Skip to content

Commit

Permalink
[feat] refactor axstd sync, expose sync types provided by axsync dire…
Browse files Browse the repository at this point in the history
…ctly
  • Loading branch information
hky1999 committed Dec 26, 2024
1 parent ab2ecad commit a589da4
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 221 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/axfeat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ smp = ["axhal/smp", "axruntime/smp", "axtask?/smp", "kspin/smp"]
fp_simd = ["axhal/fp_simd"]

# Interrupts
irq = ["axhal/irq", "axruntime/irq", "axtask?/irq"]
irq = ["axhal/irq", "axruntime/irq", "axtask?/irq", "axsync/irq"]

# Memory
alloc = ["axalloc", "axruntime/alloc"]
Expand Down
1 change: 1 addition & 0 deletions modules/axsync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ documentation = "https://arceos-org.github.io/arceos/axsync/index.html"

[features]
multitask = ["axtask/multitask", "dep:axhal"]
irq = ["axtask/irq"]
default = []

[dependencies]
Expand Down
4 changes: 3 additions & 1 deletion modules/axsync/src/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ impl Condvar {
};

// Lock the mutex again.
(mutex.lock(), WaitTimeoutResult(!success))
mutex.inner_lock();

(guard, WaitTimeoutResult(!success))
}

/// Waits on this condition variable for a notification, timing out after a
Expand Down
4 changes: 2 additions & 2 deletions modules/axsync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ cfg_if::cfg_if! {
mod semaphore;

pub use self::barrier::{Barrier, BarrierWaitResult};
pub use self::condvar::Condvar;
pub use self::condvar::{Condvar, WaitTimeoutResult};
#[doc(cfg(feature = "multitask"))]
pub use self::mutex::{Mutex, MutexGuard};
pub use semaphore::Semaphore;
pub use semaphore::{Semaphore, SemaphoreGuard};
} else {
#[doc(cfg(not(feature = "multitask")))]
pub use kspin::{SpinNoIrq as Mutex, SpinNoIrqGuard as MutexGuard};
Expand Down
1 change: 1 addition & 0 deletions ulib/axstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ log-level-trace = ["axfeat/log-level-trace"]
[dependencies]
axfeat = { workspace = true }
arceos_api = { workspace = true }
axsync = { workspace = true }
axio = "0.1"
axerrno = "0.1"
kspin = "0.1"
26 changes: 26 additions & 0 deletions ulib/axstd/src/sync.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! Useful synchronization primitives.
#[doc(no_inline)]
pub use core::sync::atomic;

#[cfg(feature = "alloc")]
#[doc(no_inline)]
pub use alloc::sync::{Arc, Weak};

// Re-export the `Mutex` and `MutexGuard` types.
pub use axsync::{Mutex, MutexGuard};

// Re-export the `RwLock` and related types.
pub use axsync::{
MappedRwLockReadGuard, MappedRwLockWriteGuard, RwLock, RwLockReadGuard, RwLockWriteGuard,
};

// Re-export the `Barrier` and `BarrierWaitResult` types.
#[cfg(feature = "multitask")]
pub use axsync::{Barrier, BarrierWaitResult};
// Re-export the `Condvar` and `WaitTimeoutResult` types.
#[cfg(feature = "multitask")]
pub use axsync::{Condvar, WaitTimeoutResult};
// Re-export the `Semaphore` and `SemaphoreGuard` types.
#[cfg(feature = "multitask")]
pub use axsync::{Semaphore, SemaphoreGuard};
19 changes: 0 additions & 19 deletions ulib/axstd/src/sync/mod.rs

This file was deleted.

198 changes: 0 additions & 198 deletions ulib/axstd/src/sync/mutex.rs

This file was deleted.

0 comments on commit a589da4

Please sign in to comment.