Skip to content

Commit 8297fe4

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 1d81dfa commit 8297fe4

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed

zephyr/src/kio.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ 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", note = "Prefer the executor-zephyr")]
2931
pub fn spawn<F>(future: F, worker: &WorkQueue, name: &'static CStr) -> JoinHandle<F>
3032
where
3133
F: Future + Send + 'static,
@@ -54,6 +56,7 @@ where
5456
///
5557
/// # Panics
5658
/// If this is called other than from a worker task running on a work thread, it will panic.
59+
#[deprecated(since = "0.1.0", note = "Prefer the executor-zephyr")]
5760
pub fn spawn_local<F>(future: F, name: &'static CStr) -> JoinHandle<F>
5861
where
5962
F: Future + 'static,
@@ -64,6 +67,7 @@ where
6467

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

zephyr/src/kio/sync.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ 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", note = "Prefer the executor-zephyr")]
3435
pub struct Mutex<T: ?Sized> {
3536
/// The semaphore indicating ownership of the data. When it is "0" the task that did the 'take'
3637
/// on it owns the data, and will use `give` when it is unlocked. This mechanism works for
@@ -40,16 +41,20 @@ pub struct Mutex<T: ?Sized> {
4041
}
4142

4243
// SAFETY: The semaphore, with the semantics provided here, provide Send and Sync.
44+
#[allow(deprecated)]
4345
unsafe impl<T: ?Sized + Send> Send for Mutex<T> {}
46+
#[allow(deprecated)]
4447
unsafe impl<T: ?Sized + Send> Sync for Mutex<T> {}
4548

49+
#[allow(deprecated)]
4650
impl<T> fmt::Debug for Mutex<T> {
4751
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4852
write!(f, "Mutex {:?}", self.inner)
4953
}
5054
}
5155

5256
/// An RAII implementation of a held lock.
57+
#[allow(deprecated)]
5358
pub struct MutexGuard<'a, T: ?Sized + 'a> {
5459
lock: &'a Mutex<T>,
5560
// Mark !Send explicitly until support is added to Rust for this.
@@ -58,6 +63,7 @@ pub struct MutexGuard<'a, T: ?Sized + 'a> {
5863

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

66+
#[allow(deprecated)]
6167
impl<T> Mutex<T> {
6268
/// Construct a new Mutex.
6369
pub fn new(t: T) -> Mutex<T> {
@@ -68,6 +74,7 @@ impl<T> Mutex<T> {
6874
}
6975
}
7076

77+
#[allow(deprecated)]
7178
impl<T: ?Sized> Mutex<T> {
7279
/// Acquire the mutex, blocking the current thread until it is able to do so.
7380
///
@@ -94,6 +101,7 @@ impl<T: ?Sized> Mutex<T> {
94101
}
95102
}
96103

104+
#[allow(deprecated)]
97105
impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> {
98106
unsafe fn new(lock: &'mutex Mutex<T>) -> MutexGuard<'mutex, T> {
99107
MutexGuard {
@@ -103,6 +111,7 @@ impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> {
103111
}
104112
}
105113

114+
#[allow(deprecated)]
106115
impl<T: ?Sized> Deref for MutexGuard<'_, T> {
107116
type Target = T;
108117

@@ -111,12 +120,14 @@ impl<T: ?Sized> Deref for MutexGuard<'_, T> {
111120
}
112121
}
113122

123+
#[allow(deprecated)]
114124
impl<T: ?Sized> DerefMut for MutexGuard<'_, T> {
115125
fn deref_mut(&mut self) -> &mut T {
116126
unsafe { &mut *self.lock.data.get() }
117127
}
118128
}
119129

130+
#[allow(deprecated)]
120131
impl<T: ?Sized> Drop for MutexGuard<'_, T> {
121132
#[inline]
122133
fn drop(&mut self) {

zephyr/src/sync/channel.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ 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", note = "Prefer the executor-zephyr")]
218219
pub fn send_timeout_async<'a>(
219220
&'a self,
220221
msg: T,
@@ -229,6 +230,8 @@ impl<T: Unpin> Sender<T> {
229230
}
230231

231232
/// Sends a message over the given channel, waiting if necessary. Async version.
233+
#[deprecated(since = "0.1.0", note = "Prefer the executor-zephyr")]
234+
#[allow(deprecated)]
232235
pub async fn send_async(&self, msg: T) -> Result<(), SendError<T>> {
233236
self.send_timeout_async(msg, Forever).await
234237
}
@@ -424,6 +427,7 @@ impl<T> Receiver<T> {
424427
}
425428

426429
// Note that receive doesn't need the Unpin constraint, as we aren't storing any message.
430+
#[deprecated(since = "0.1.0", note = "Prefer the executor-zephyr")]
427431
impl<T> Receiver<T> {
428432
/// Waits for a message to be received from the channel, but only for a limited time.
429433
/// Async version.
@@ -526,6 +530,7 @@ impl<'a, T> Future for RecvFuture<'a, T> {
526530
}
527531

528532
// Otherwise, schedule to wakeup on receipt or timeout.
533+
#[allow(deprecated)]
529534
cx.add_queue(self.receiver.as_queue(), self.timeout);
530535
self.waited = true;
531536

@@ -662,6 +667,7 @@ where
662667
// Start with a deadline 'period' out in the future.
663668
let mut next = crate::time::now() + period;
664669
loop {
670+
#[allow(deprecated)]
665671
if let Ok(ev) = events.recv_timeout_async(next).await {
666672
handle(Some(ev)).await;
667673
continue;

zephyr/src/sys/sync/semaphore.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ 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", note = "Prefer the executor-zephyr")]
8586
pub fn take_async<'a>(
8687
&'a self,
8788
timeout: impl Into<Timeout>,

zephyr/src/work/futures.rs

Lines changed: 2 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,7 @@ unsafe fn void_drop(_: *const ()) {}
587588
type EventArray = ArrayVec<UnsafeCell<k_poll_event>, 1>;
588589

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

0 commit comments

Comments
 (0)