Skip to content

Commit a51ef37

Browse files
committed
[chore]: add related info
1 parent 8ae328d commit a51ef37

File tree

8 files changed

+79
-104
lines changed

8 files changed

+79
-104
lines changed

modules/axembassy/src/asynch.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use axtask::yield_now;
99

1010
pub use embassy_executor::{SendSpawner, Spawner};
1111

12+
/// Global spawner for multi-thread executor
1213
pub(crate) static SPAWNER: Mutex<OnceCell<SendSpawner>> = Mutex::new(OnceCell::new());
1314

1415
fn init_spawn() {
@@ -17,7 +18,7 @@ fn init_spawn() {
1718
}
1819

1920
fn init() {
20-
use crate::executor_thread::Executor;
21+
use crate::executor::Executor;
2122
use static_cell::StaticCell;
2223

2324
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
@@ -60,7 +61,7 @@ pub(crate) fn set_spawner(spawner: SendSpawner) {
6061
let _ = sp.set(spawner);
6162
}
6263

63-
fn wake(ctx: *const ()) {
64+
fn wake(_ctx: *const ()) {
6465
// let id = ctx as u64;
6566
// unpark_task(id, true);
6667
}

modules/axembassy/src/delegate.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ unsafe impl<T> Sync for Delegate<T> {}
148148

149149
impl<T> Delegate<T> {
150150
#[must_use]
151+
/// Creates a new `Delegate`
152+
///
153+
/// **NOT** thread safe and only executor safe
151154
pub const fn new() -> Self {
152155
Self {
153156
send: Signal::new(),
@@ -157,7 +160,8 @@ impl<T> Delegate<T> {
157160
}
158161
}
159162

160-
/// lend
163+
/// lend target `T` to other task in the same executor
164+
/// with lifetime longer than delegate itself
161165
pub async fn lend<'a, 'b: 'a>(&'a self, target: &'b mut T) -> Result<(), DelegateError> {
162166
use DelegateError::*;
163167
use DelegateState::*;
@@ -183,7 +187,10 @@ impl<T> Delegate<T> {
183187
Ok(())
184188
}
185189

186-
/// lend and reset
190+
/// lend target `T` to other task in the same executor
191+
/// with lifetime longer than delegate itself
192+
///
193+
/// reset state afterwards for reuse
187194
pub async fn lend_new<'a, 'b: 'a>(&'a self, target: &'b mut T) -> Result<(), DelegateError> {
188195
match self.lend(target).await {
189196
Ok(()) => {
@@ -194,6 +201,8 @@ impl<T> Delegate<T> {
194201
}
195202
}
196203

204+
/// Returns a mutable reference to the inner value lent
205+
/// by other task in the same executor
197206
pub async fn with<U>(&self, func: impl FnOnce(&mut T) -> U) -> Result<U, DelegateError> {
198207
use DelegateError::*;
199208
use DelegateState::*;
@@ -219,6 +228,7 @@ impl<T> Delegate<T> {
219228
Ok(res)
220229
}
221230

231+
/// Reset the delegate to reuse
222232
pub fn reset(&self) {
223233
use DelegateState::*;
224234

modules/axembassy/src/executor.rs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1-
use core::sync::atomic::{AtomicBool, Ordering};
21
use core::marker::PhantomData;
2+
use core::sync::atomic::{AtomicBool, Ordering};
33
use embassy_executor::raw;
44

5-
static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false);
5+
#[cfg(feature = "executor-single")]
6+
static SIGNAL_SINGLE: AtomicBool = AtomicBool::new(false);
7+
8+
#[cfg(feature = "executor-thread")]
9+
#[percpu::def_percpu]
10+
static SINGAL_THREAD: AtomicBool = AtomicBool::new(false);
611

712
#[unsafe(export_name = "__pender")]
813
fn __pender(_context: *mut ()) {
9-
SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst);
14+
#[cfg(feature = "executor-single")]
15+
SIGNAL_SINGLE.store(true, Ordering::SeqCst);
16+
17+
#[cfg(feature = "executor-thread")]
18+
SINGAL_THREAD.with_current(|m| {
19+
m.store(true, Ordering::SeqCst);
20+
});
1021
}
1122

1223
pub struct Executor {
@@ -36,10 +47,26 @@ impl Executor {
3647
unsafe {
3748
self.inner.poll();
3849

39-
if SIGNAL_WORK_THREAD_MODE.load(Ordering::SeqCst) {
40-
SIGNAL_WORK_THREAD_MODE.store(false, Ordering::SeqCst);
41-
} else {
42-
axhal::arch::wait_for_irqs();
50+
#[cfg(feature = "executor-single")]
51+
{
52+
if SIGNAL_SINGLE.load(Ordering::SeqCst) {
53+
SIGNAL_SINGLE.store(false, Ordering::SeqCst);
54+
} else {
55+
axhal::arch::wait_for_irqs();
56+
}
57+
}
58+
59+
#[cfg(feature = "executor-thread")]
60+
{
61+
let polled = SINGAL_THREAD.with_current(|m| m.load(Ordering::Acquire));
62+
if polled {
63+
SINGAL_THREAD.with_current(|m| {
64+
m.store(false, Ordering::Release);
65+
});
66+
} else {
67+
// park_current_task();
68+
axtask::yield_now();
69+
}
4370
}
4471
};
4572
}

modules/axembassy/src/executor_thread.rs

Lines changed: 0 additions & 54 deletions
This file was deleted.

modules/axembassy/src/lib.rs

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
//! [ArceOS](https://github.com/arceos-org/arceos) embassy integration
2+
//!
3+
//! This module provides embassy asynchronous runtime integration, including
4+
//! time driver, and executor with single-thread, multi-thread, preemptive(partially)
5+
//! which are configurable by cargo features.
6+
//!
7+
//! # Cargo Features
8+
//!
9+
//! - `driver`: Enable time driver support. If it's enabled, time driver is used.
10+
//! Usually used by `axruntime` module in `irq` initiation.
11+
//! - `executor-single`: Use the [single-thread executor][1]. It also enables the
12+
//! related utils modules.
13+
//! - `executor-thread`: Use the [multi-thread executor][2]. It also enables the
14+
//! related utils modules and enables the `multitask` feature if it is enabled.
15+
//! - `executor-preempt`: Use the [preemptive executor][3]. It also enables the
16+
//! related utils modules and enables the `executor-thread` feature if it is
17+
//! enabled.
18+
//!
19+
//! [1]: single-thread executor
20+
//! [2]: multi-thread executor(`spawner`, `block_on`)
21+
//! [3]: preemptive executor(`PrioFuture`)
22+
123
#![cfg_attr(not(test), no_std)]
224
#![feature(doc_cfg)]
325
#![feature(doc_auto_cfg)]
@@ -7,30 +29,21 @@ cfg_if::cfg_if! {
729
extern crate alloc;
830
extern crate log;
931

10-
pub mod delegate;
11-
12-
#[cfg(feature = "executor-thread")]
13-
mod executor_thread;
14-
#[cfg(feature = "executor-thread")]
1532
mod asynch;
16-
#[cfg(feature = "executor-thread")]
17-
mod executor_thread_exports {
18-
pub use crate::executor_thread::Executor;
19-
pub use crate::asynch::{spawner,block_on,Spawner,SendSpawner};
20-
#[cfg(feature = "executor-preempt")]
21-
pub use crate::preempt::PrioFuture;
22-
}
23-
#[cfg(feature = "executor-thread")]
24-
pub use executor_thread_exports::*;
33+
pub mod delegate;
2534

26-
#[cfg(feature = "executor-single")]
2735
mod executor;
28-
#[cfg(feature = "executor-single")]
2936
mod executor_exports {
3037
pub use crate::executor::Executor;
3138
pub use crate::asynch::Spawner;
39+
40+
#[cfg(feature = "executor-thread")]
41+
pub use crate::asynch::{spawner,block_on,SendSpawner};
42+
43+
#[cfg(feature = "executor-preempt")]
44+
pub use crate::preempt::PrioFuture;
3245
}
33-
#[cfg(feature = "executor-single")]
46+
3447
pub use executor_exports::*;
3548
}
3649
}

modules/axtask/src/api.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,6 @@ pub fn exit(exit_code: i32) -> ! {
206206
current_run_queue::<NoPreemptIrqSave>().exit_current(exit_code)
207207
}
208208

209-
/// Park the current task.
210-
pub fn park_current_task() {
211-
let mut cur_rq = current_run_queue::<NoPreemptIrqSave>();
212-
cur_rq.park_current_task();
213-
}
214-
215209
/// The idle task routine.
216210
///
217211
/// It runs an infinite loop that keeps calling [`yield_now()`].

modules/axtask/src/run_queue.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -420,20 +420,6 @@ impl<G: BaseGuard> CurrentRunQueueRef<'_, G> {
420420
self.inner.resched();
421421
}
422422

423-
/// Park the current task, and reschedule.
424-
pub fn park_current_task(&mut self) {
425-
let curr = &self.current_task;
426-
assert!(curr.is_running());
427-
assert!(!curr.is_idle());
428-
429-
// Ensure preemption is disabled
430-
#[cfg(feature = "preempt")]
431-
assert!(curr.can_preempt(1));
432-
433-
curr.set_state(TaskState::Parked);
434-
self.inner.resched();
435-
}
436-
437423
#[cfg(feature = "irq")]
438424
pub fn sleep_until(&mut self, deadline: axhal::time::TimeValue) {
439425
let curr = &self.current_task;

ulib/axasync/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
pub mod executor {
77
use arceos_api::embassy_async as api;
88

9-
pub use embassy_executor::{main, task};
10-
119
pub use api::AxExecutor as Executor;
1210
pub use embassy_executor::*;
1311
pub use embassy_futures::*;

0 commit comments

Comments
 (0)