Skip to content

Commit 2dab6c6

Browse files
committed
zephyr: mark old async methods as deprecated
This work-queue based async executor, although functional, has some significant problems. Most notably, it doesn't use wakers, and as such, is incompatible with other utilities that have been written to be used with Async. Trying to combine them will, in fact, result in undefined behavior. Now that the embassy-based executor-zephyr is in main, mark these as deprecated so that code can gradually move to newer solutions. Signed-off-by: David Brown <[email protected]>
1 parent 817b991 commit 2dab6c6

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

zephyr/src/kio.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ use crate::work::{futures::JoinHandle, futures::WorkBuilder, WorkQueue};
2020

2121
pub mod sync;
2222

23+
#[allow(deprecated)]
2324
pub use crate::work::futures::sleep;
2425

2526
/// Run an async future on the given worker thread.
2627
///
2728
/// Arrange to have the given future run on the given worker thread. The resulting `JoinHandle` has
2829
/// `join` and `join_async` methods that can be used to wait for the given thread.
30+
#[deprecated(since = "0.1.0",
31+
note = "Prefer the executor-zephyr")]
2932
pub fn spawn<F>(future: F, worker: &WorkQueue, name: &'static CStr) -> JoinHandle<F>
3033
where
3134
F: Future + Send + 'static,
@@ -54,6 +57,8 @@ where
5457
///
5558
/// # Panics
5659
/// If this is called other than from a worker task running on a work thread, it will panic.
60+
#[deprecated(since = "0.1.0",
61+
note = "Prefer the executor-zephyr")]
5762
pub fn spawn_local<F>(future: F, name: &'static CStr) -> JoinHandle<F>
5863
where
5964
F: Future + 'static,
@@ -64,6 +69,8 @@ where
6469

6570
/// Yield the current thread, returning it to the work queue to be run after other work on that
6671
/// queue. (This has to be called `yield_now` in Rust, because `yield` is a keyword.)
72+
#[deprecated(since = "0.1.0",
73+
note = "Prefer the executor-zephyr")]
6774
pub fn yield_now() -> impl Future<Output = ()> {
6875
YieldNow { waited: false }
6976
}

zephyr/src/kio/sync.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ use crate::{
3131
/// A mutual exclusion primitive useful for protecting shared data. Async version.
3232
///
3333
/// This mutex will block a task waiting for the lock to become available.
34+
#[deprecated(since = "0.1.0",
35+
note = "Prefer the executor-zephyr")]
3436
pub struct Mutex<T: ?Sized> {
3537
/// The semaphore indicating ownership of the data. When it is "0" the task that did the 'take'
3638
/// on it owns the data, and will use `give` when it is unlocked. This mechanism works for
@@ -40,16 +42,20 @@ pub struct Mutex<T: ?Sized> {
4042
}
4143

4244
// SAFETY: The semaphore, with the semantics provided here, provide Send and Sync.
45+
#[allow(deprecated)]
4346
unsafe impl<T: ?Sized + Send> Send for Mutex<T> {}
47+
#[allow(deprecated)]
4448
unsafe impl<T: ?Sized + Send> Sync for Mutex<T> {}
4549

50+
#[allow(deprecated)]
4651
impl<T> fmt::Debug for Mutex<T> {
4752
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4853
write!(f, "Mutex {:?}", self.inner)
4954
}
5055
}
5156

5257
/// An RAII implementation of a held lock.
58+
#[allow(deprecated)]
5359
pub struct MutexGuard<'a, T: ?Sized + 'a> {
5460
lock: &'a Mutex<T>,
5561
// Mark !Send explicitly until support is added to Rust for this.
@@ -58,6 +64,7 @@ pub struct MutexGuard<'a, T: ?Sized + 'a> {
5864

5965
unsafe impl<T: ?Sized + Sync> Sync for MutexGuard<'_, T> {}
6066

67+
#[allow(deprecated)]
6168
impl<T> Mutex<T> {
6269
/// Construct a new Mutex.
6370
pub fn new(t: T) -> Mutex<T> {
@@ -68,6 +75,7 @@ impl<T> Mutex<T> {
6875
}
6976
}
7077

78+
#[allow(deprecated)]
7179
impl<T: ?Sized> Mutex<T> {
7280
/// Acquire the mutex, blocking the current thread until it is able to do so.
7381
///
@@ -94,6 +102,7 @@ impl<T: ?Sized> Mutex<T> {
94102
}
95103
}
96104

105+
#[allow(deprecated)]
97106
impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> {
98107
unsafe fn new(lock: &'mutex Mutex<T>) -> MutexGuard<'mutex, T> {
99108
MutexGuard {
@@ -103,6 +112,7 @@ impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> {
103112
}
104113
}
105114

115+
#[allow(deprecated)]
106116
impl<T: ?Sized> Deref for MutexGuard<'_, T> {
107117
type Target = T;
108118

@@ -111,12 +121,14 @@ impl<T: ?Sized> Deref for MutexGuard<'_, T> {
111121
}
112122
}
113123

124+
#[allow(deprecated)]
114125
impl<T: ?Sized> DerefMut for MutexGuard<'_, T> {
115126
fn deref_mut(&mut self) -> &mut T {
116127
unsafe { &mut *self.lock.data.get() }
117128
}
118129
}
119130

131+
#[allow(deprecated)]
120132
impl<T: ?Sized> Drop for MutexGuard<'_, T> {
121133
#[inline]
122134
fn drop(&mut self) {

zephyr/src/sync/channel.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ impl<T: Unpin> Sender<T> {
215215
/// This has the same behavior as [`send_timeout`], but as an Async function.
216216
///
217217
/// [`send_timeout`]: Sender::send_timeout
218+
#[deprecated(since = "0.1.0",
219+
note = "Prefer the executor-zephyr")]
218220
pub fn send_timeout_async<'a>(
219221
&'a self,
220222
msg: T,
@@ -229,6 +231,9 @@ impl<T: Unpin> Sender<T> {
229231
}
230232

231233
/// Sends a message over the given channel, waiting if necessary. Async version.
234+
#[deprecated(since = "0.1.0",
235+
note = "Prefer the executor-zephyr")]
236+
#[allow(deprecated)]
232237
pub async fn send_async(&self, msg: T) -> Result<(), SendError<T>> {
233238
self.send_timeout_async(msg, Forever).await
234239
}
@@ -424,6 +429,8 @@ impl<T> Receiver<T> {
424429
}
425430

426431
// Note that receive doesn't need the Unpin constraint, as we aren't storing any message.
432+
#[deprecated(since = "0.1.0",
433+
note = "Prefer the executor-zephyr")]
427434
impl<T> Receiver<T> {
428435
/// Waits for a message to be received from the channel, but only for a limited time.
429436
/// Async version.
@@ -526,6 +533,7 @@ impl<'a, T> Future for RecvFuture<'a, T> {
526533
}
527534

528535
// Otherwise, schedule to wakeup on receipt or timeout.
536+
#[allow(deprecated)]
529537
cx.add_queue(self.receiver.as_queue(), self.timeout);
530538
self.waited = true;
531539

@@ -662,6 +670,7 @@ where
662670
// Start with a deadline 'period' out in the future.
663671
let mut next = crate::time::now() + period;
664672
loop {
673+
#[allow(deprecated)]
665674
if let Ok(ev) = events.recv_timeout_async(next).await {
666675
handle(Some(ev)).await;
667676
continue;

zephyr/src/sys/sync/semaphore.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ impl Semaphore {
8282
///
8383
/// Returns a future that either waits for the semaphore, or returns status.
8484
#[cfg(CONFIG_RUST_ALLOC)]
85+
#[deprecated(since = "0.1.0",
86+
note = "Prefer the executor-zephyr")]
8587
pub fn take_async<'a>(
8688
&'a self,
8789
timeout: impl Into<Timeout>,

zephyr/src/work/futures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl<T> Answer<T> {
104104

105105
/// Asynchronously wait for an answer.
106106
pub async fn take_async(&self) -> T {
107+
#[allow(deprecated)]
107108
self.wake
108109
.take_async(Forever)
109110
.await
@@ -587,6 +588,8 @@ unsafe fn void_drop(_: *const ()) {}
587588
type EventArray = ArrayVec<UnsafeCell<k_poll_event>, 1>;
588589

589590
/// Async sleep.
591+
#[deprecated(since = "0.1.0",
592+
note = "Prefer the executor-zephyr")]
590593
pub fn sleep(duration: Duration) -> Sleep {
591594
Sleep {
592595
ticks_left: duration.ticks(),

0 commit comments

Comments
 (0)