Skip to content

Commit 1fa53ab

Browse files
committed
zephyr: Apply cargo fmt to new work-queue code
The newly added code needs some fixups to comply with rustfmt. Apply these. Signed-off-by: David Brown <[email protected]>
1 parent 0dbfd14 commit 1fa53ab

File tree

8 files changed

+39
-45
lines changed

8 files changed

+39
-45
lines changed

zephyr/src/kio.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ where
5252
F: Future + 'static,
5353
F::Output: Send + 'static,
5454
{
55-
WorkBuilder::new()
56-
.set_name(name)
57-
.start_local(future)
55+
WorkBuilder::new().set_name(name).start_local(future)
5856
}
5957

6058
/// Yield the current thread, returning it to the work queue to be run after other work on that

zephyr/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
pub mod align;
1414
pub mod device;
1515
pub mod error;
16+
#[cfg(CONFIG_RUST_ALLOC)]
17+
pub mod kio;
1618
pub mod logging;
1719
pub mod object;
1820
#[cfg(CONFIG_RUST_ALLOC)]
@@ -24,8 +26,6 @@ pub mod time;
2426
pub mod timer;
2527
#[cfg(CONFIG_RUST_ALLOC)]
2628
pub mod work;
27-
#[cfg(CONFIG_RUST_ALLOC)]
28-
pub mod kio;
2929

3030
pub use error::{Error, Result};
3131

zephyr/src/simpletls.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<T: Copy + Send> StaticTls<T> {
7575
Self {
7676
data: AtomicPtr::new(ptr::null_mut()),
7777
}
78-
}
78+
}
7979

8080
/// Get the underlying Mutex out of the data, initializing it with an empty type if necessary.
8181
fn get_inner(&self) -> &Mutex<SimpleTls<T>> {
@@ -92,7 +92,8 @@ impl<T: Copy + Send> StaticTls<T> {
9292
// If there was already a value, just use it.
9393
None
9494
}
95-
});
95+
},
96+
);
9697
let data = match data {
9798
Ok(_) => {
9899
// If the update stored something, it unhelpfully returns the old value, which was

zephyr/src/sync.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,7 @@ pub use portable_atomic_util::Weak;
3232

3333
mod mutex;
3434

35-
pub use mutex::{
36-
Mutex,
37-
MutexGuard,
38-
Condvar,
39-
LockResult,
40-
TryLockResult,
41-
TryLockError,
42-
};
35+
pub use mutex::{Condvar, LockResult, Mutex, MutexGuard, TryLockError, TryLockResult};
4336

4437
mod spinmutex;
4538

zephyr/src/sync/channel.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,11 @@ 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-
pub fn send_timeout_async<'a>(&'a self, msg: T, timeout: impl Into<Timeout>)
219-
-> impl Future<Output = Result<(), SendError<T>>> + 'a
220-
{
218+
pub fn send_timeout_async<'a>(
219+
&'a self,
220+
msg: T,
221+
timeout: impl Into<Timeout>,
222+
) -> impl Future<Output = Result<(), SendError<T>>> + 'a {
221223
SendFuture {
222224
sender: self,
223225
msg: Some(msg),
@@ -245,7 +247,10 @@ struct SendFuture<'a, T: Unpin> {
245247
impl<'a, T: Unpin> Future for SendFuture<'a, T> {
246248
type Output = Result<(), SendError<T>>;
247249

248-
fn poll(self: Pin<&mut Self>, cx: &mut core::task::Context<'_>) -> core::task::Poll<Self::Output> {
250+
fn poll(
251+
self: Pin<&mut Self>,
252+
cx: &mut core::task::Context<'_>,
253+
) -> core::task::Poll<Self::Output> {
249254
/*
250255
let this = unsafe {
251256
Pin::get_unchecked_mut(self)
@@ -426,9 +431,10 @@ impl<T> Receiver<T> {
426431
/// If the channel is empty and not disconnected, this call will block until the receive
427432
/// operation can proceed or the operation times out.
428433
/// wake up and return an error.
429-
pub fn recv_timeout_async<'a>(&'a self, timeout: impl Into<Timeout>)
430-
-> impl Future<Output = Result<T, RecvError>> + 'a
431-
{
434+
pub fn recv_timeout_async<'a>(
435+
&'a self,
436+
timeout: impl Into<Timeout>,
437+
) -> impl Future<Output = Result<T, RecvError>> + 'a {
432438
RecvFuture {
433439
receiver: self,
434440
timeout: timeout.into(),
@@ -644,7 +650,7 @@ pub struct RecvError;
644650
///
645651
/// TODO: This function, in general, is completely worthless without Rust support for [async
646652
/// closures](https://rust-lang.github.io/rfcs/3668-async-closures.html).
647-
pub async fn event_loop_useless<T, EF, EFF> (
653+
pub async fn event_loop_useless<T, EF, EFF>(
648654
events: Receiver<T>,
649655
period: Duration,
650656
mut handle: EF,

zephyr/src/sys/sync/semaphore.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
//! operation, which in situation where counting is actually desired, will result in the count being
1212
//! incorrect.
1313
14-
#[cfg(CONFIG_RUST_ALLOC)]
15-
use core::pin::Pin;
16-
#[cfg(CONFIG_RUST_ALLOC)]
17-
use core::task::{Context, Poll};
18-
#[cfg(CONFIG_RUST_ALLOC)]
19-
use core::future::Future;
2014
use core::ffi::c_uint;
2115
use core::fmt;
2216
#[cfg(CONFIG_RUST_ALLOC)]
17+
use core::future::Future;
18+
#[cfg(CONFIG_RUST_ALLOC)]
2319
use core::mem;
20+
#[cfg(CONFIG_RUST_ALLOC)]
21+
use core::pin::Pin;
22+
#[cfg(CONFIG_RUST_ALLOC)]
23+
use core::task::{Context, Poll};
2424

2525
#[cfg(CONFIG_RUST_ALLOC)]
2626
use zephyr_sys::ETIMEDOUT;
@@ -81,7 +81,10 @@ impl Semaphore {
8181
///
8282
/// Returns a future that either waits for the semaphore, or returns status.
8383
#[cfg(CONFIG_RUST_ALLOC)]
84-
pub fn take_async<'a>(&'a self, timeout: impl Into<Timeout>) -> impl Future<Output = Result<()>> + 'a {
84+
pub fn take_async<'a>(
85+
&'a self,
86+
timeout: impl Into<Timeout>,
87+
) -> impl Future<Output = Result<()>> + 'a {
8588
SemTake {
8689
sem: self,
8790
timeout: timeout.into(),
@@ -139,7 +142,6 @@ impl<'a> Future for SemTake<'a> {
139142
if self.ran {
140143
// If we ran once, and still don't have any data, indicate this as a timeout.
141144
return Poll::Ready(Err(crate::Error(ETIMEDOUT)));
142-
143145
}
144146

145147
// TODO: Clean this up.

zephyr/src/work.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ use zephyr_sys::{
194194
k_work_queue_start, k_work_submit, k_work_submit_to_queue, ETIMEDOUT,
195195
};
196196

197-
use crate::{error::to_result_void, kio::ContextExt, object::Fixed, simpletls::StaticTls, sys::thread::ThreadStack, time::Timeout};
197+
use crate::{
198+
error::to_result_void, kio::ContextExt, object::Fixed, simpletls::StaticTls,
199+
sys::thread::ThreadStack, time::Timeout,
200+
};
198201

199202
pub mod futures;
200203

zephyr/src/work/futures.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub struct JoinHandle<F: Future> {
195195
unsafe impl<F> Send for JoinHandle<F>
196196
where
197197
F: Future,
198-
F::Output: Send
198+
F::Output: Send,
199199
{
200200
}
201201

@@ -205,12 +205,7 @@ impl<F: Future + Send> JoinHandle<F> {
205205
// Answer holds the result when the work finishes.
206206
let answer = Arc::new(Answer::new());
207207

208-
let work = WorkData::new(
209-
future,
210-
Arc::downgrade(&answer),
211-
builder.queue,
212-
builder.name,
213-
);
208+
let work = WorkData::new(future, Arc::downgrade(&answer), builder.queue, builder.name);
214209
WorkData::submit(work).expect("Unable to enqueue worker");
215210

216211
Self { answer }
@@ -422,9 +417,7 @@ impl<F: Future> WorkData<F> {
422417
fn submit(mut this: Pin<Box<Self>>) -> crate::Result<SubmitResult> {
423418
// SAFETY: This is unsafe because the pointer lose the Pin guarantee, but C code will not
424419
// move it.
425-
let this_ref = unsafe {
426-
Pin::get_unchecked_mut(this.as_mut())
427-
};
420+
let this_ref = unsafe { Pin::get_unchecked_mut(this.as_mut()) };
428421

429422
let result = if let Some(queue) = this_ref.info.queue {
430423
unsafe {
@@ -474,9 +467,7 @@ impl<F: Future> WorkData<F> {
474467
// not necessarily at the beginning of the struct.
475468
let mut this = unsafe { Self::from_raw(work) };
476469

477-
let this_ref = unsafe {
478-
Pin::get_unchecked_mut(this.as_mut())
479-
};
470+
let this_ref = unsafe { Pin::get_unchecked_mut(this.as_mut()) };
480471

481472
// Set the next work to Forever, with no events. TODO: This prevents the next poll from
482473
// being able to determine the reason for the wakeup.

0 commit comments

Comments
 (0)