Skip to content

Deprecate old async #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ license = "Apache-2.0 or MIT"
crate-type = ["staticlib"]

[dependencies]
zephyr = { version = "0.1.0", features = ["executor-zephyr", "async-drivers"] }
zephyr = { version = "0.2.0", features = ["executor-zephyr", "async-drivers"] }
2 changes: 1 addition & 1 deletion samples/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "Apache-2.0 or MIT"
crate-type = ["staticlib"]

[dependencies]
zephyr = "0.1.0"
zephyr = "0.2.0"
critical-section = "1.1.2"

# Dependencies that are used by build.rs.
Expand Down
2 changes: 2 additions & 0 deletions samples/bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// uses a large number of Kconfigs and there is no easy way to know which ones might conceivably be
// valid. This prevents a warning about each cfg that is used.
#![allow(unexpected_cfgs)]
// While in the process of deprecating the "kio" async code, allow the deprecation warnings.
#![allow(deprecated)]

extern crate alloc;

Expand Down
2 changes: 1 addition & 1 deletion samples/blinky/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "Apache-2.0 OR MIT"
crate-type = ["staticlib"]

[dependencies]
zephyr = "0.1.0"
zephyr = "0.2.0"
log = "0.4.22"

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion samples/embassy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "Apache-2.0 or MIT"
crate-type = ["staticlib"]

[dependencies]
zephyr = { version = "0.1.0", features = ["time-driver"] }
zephyr = { version = "0.2.0", features = ["time-driver"] }
log = "0.4.22"
static_cell = "2.1"
heapless = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion samples/hello_world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ license = "Apache-2.0 or MIT"
crate-type = ["staticlib"]

[dependencies]
zephyr = "0.1.0"
zephyr = "0.2.0"
log = "0.4.22"
2 changes: 1 addition & 1 deletion samples/philosophers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "Apache-2.0 or MIT"
crate-type = ["staticlib"]

[dependencies]
zephyr = "0.1.0"
zephyr = "0.2.0"

# Dependencies that are used by build.rs.
[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion samples/work-philosophers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "Apache-2.0 or MIT"
crate-type = ["staticlib"]

[dependencies]
zephyr = "0.1.0"
zephyr = "0.2.0"

# Dependencies that are used by build.rs.
[build-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions samples/work-philosophers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// uses a large number of Kconfigs and there is no easy way to know which ones might conceivably be
// valid. This prevents a warning about each cfg that is used.
#![allow(unexpected_cfgs)]
// During the transition of deprecating 'kio' async, allow the deprecation warnings.
#![allow(deprecated)]

extern crate alloc;

Expand Down
2 changes: 1 addition & 1 deletion tests/time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ license = "Apache-2.0 or MIT"
crate-type = ["staticlib"]

[dependencies]
zephyr = "0.1.0"
zephyr = "0.2.0"
2 changes: 1 addition & 1 deletion tests/timer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ crate-type = ["staticlib"]
[dependencies]
rand = { version = "0.8", default-features = false }
rand_pcg = { version = "0.3.1", default-features = false }
zephyr = "0.1.0"
zephyr = "0.2.0"
2 changes: 1 addition & 1 deletion zephyr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "zephyr"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
description = """
Functionality for Rust-based applications that run on Zephyr.
Expand Down
4 changes: 4 additions & 0 deletions zephyr/src/kio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ use crate::work::{futures::JoinHandle, futures::WorkBuilder, WorkQueue};

pub mod sync;

#[allow(deprecated)]
pub use crate::work::futures::sleep;

/// Run an async future on the given worker thread.
///
/// Arrange to have the given future run on the given worker thread. The resulting `JoinHandle` has
/// `join` and `join_async` methods that can be used to wait for the given thread.
#[deprecated(since = "0.1.0", note = "Prefer the executor-zephyr")]
pub fn spawn<F>(future: F, worker: &WorkQueue, name: &'static CStr) -> JoinHandle<F>
where
F: Future + Send + 'static,
Expand Down Expand Up @@ -54,6 +56,7 @@ where
///
/// # Panics
/// If this is called other than from a worker task running on a work thread, it will panic.
#[deprecated(since = "0.1.0", note = "Prefer the executor-zephyr")]
pub fn spawn_local<F>(future: F, name: &'static CStr) -> JoinHandle<F>
where
F: Future + 'static,
Expand All @@ -64,6 +67,7 @@ where

/// Yield the current thread, returning it to the work queue to be run after other work on that
/// queue. (This has to be called `yield_now` in Rust, because `yield` is a keyword.)
#[deprecated(since = "0.1.0", note = "Prefer the executor-zephyr")]
pub fn yield_now() -> impl Future<Output = ()> {
YieldNow { waited: false }
}
Expand Down
11 changes: 11 additions & 0 deletions zephyr/src/kio/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::{
/// A mutual exclusion primitive useful for protecting shared data. Async version.
///
/// This mutex will block a task waiting for the lock to become available.
#[deprecated(since = "0.1.0", note = "Prefer the executor-zephyr")]
pub struct Mutex<T: ?Sized> {
/// The semaphore indicating ownership of the data. When it is "0" the task that did the 'take'
/// on it owns the data, and will use `give` when it is unlocked. This mechanism works for
Expand All @@ -40,16 +41,20 @@ pub struct Mutex<T: ?Sized> {
}

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

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

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

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

#[allow(deprecated)]
impl<T> Mutex<T> {
/// Construct a new Mutex.
pub fn new(t: T) -> Mutex<T> {
Expand All @@ -68,6 +74,7 @@ impl<T> Mutex<T> {
}
}

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

#[allow(deprecated)]
impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> {
unsafe fn new(lock: &'mutex Mutex<T>) -> MutexGuard<'mutex, T> {
MutexGuard {
Expand All @@ -103,6 +111,7 @@ impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> {
}
}

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

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

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

#[allow(deprecated)]
impl<T: ?Sized> Drop for MutexGuard<'_, T> {
#[inline]
fn drop(&mut self) {
Expand Down
6 changes: 6 additions & 0 deletions zephyr/src/sync/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl<T: Unpin> Sender<T> {
/// This has the same behavior as [`send_timeout`], but as an Async function.
///
/// [`send_timeout`]: Sender::send_timeout
#[deprecated(since = "0.1.0", note = "Prefer the executor-zephyr")]
pub fn send_timeout_async<'a>(
&'a self,
msg: T,
Expand All @@ -229,6 +230,8 @@ impl<T: Unpin> Sender<T> {
}

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

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

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

Expand Down Expand Up @@ -662,6 +667,7 @@ where
// Start with a deadline 'period' out in the future.
let mut next = crate::time::now() + period;
loop {
#[allow(deprecated)]
if let Ok(ev) = events.recv_timeout_async(next).await {
handle(Some(ev)).await;
continue;
Expand Down
1 change: 1 addition & 0 deletions zephyr/src/sys/sync/semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl Semaphore {
///
/// Returns a future that either waits for the semaphore, or returns status.
#[cfg(CONFIG_RUST_ALLOC)]
#[deprecated(since = "0.1.0", note = "Prefer the executor-zephyr")]
pub fn take_async<'a>(
&'a self,
timeout: impl Into<Timeout>,
Expand Down
2 changes: 2 additions & 0 deletions zephyr/src/work/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl<T> Answer<T> {

/// Asynchronously wait for an answer.
pub async fn take_async(&self) -> T {
#[allow(deprecated)]
self.wake
.take_async(Forever)
.await
Expand Down Expand Up @@ -587,6 +588,7 @@ unsafe fn void_drop(_: *const ()) {}
type EventArray = ArrayVec<UnsafeCell<k_poll_event>, 1>;

/// Async sleep.
#[deprecated(since = "0.1.0", note = "Prefer the executor-zephyr")]
pub fn sleep(duration: Duration) -> Sleep {
Sleep {
ticks_left: duration.ticks(),
Expand Down