Skip to content

Commit c2bd8b9

Browse files
author
Lucas Paixão
committed
Code and formater fix
1 parent 39ff6c1 commit c2bd8b9

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

src/runtime/context.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use std::cell::{Cell, RefCell};
44
/// Owns the driver and resides in thread-local storage.
55
pub(crate) struct RuntimeContext {
66
driver: RefCell<Option<Handle>>,
7-
on_thread_park: Cell<fn()>
7+
on_thread_park: Cell<fn()>,
88
}
99

10-
fn noop(){}
10+
fn noop() {}
1111

1212
impl RuntimeContext {
1313
/// Construct the context with an uninitialized driver.
@@ -51,7 +51,8 @@ impl RuntimeContext {
5151
/// Check if driver is initialized
5252
#[allow(dead_code)]
5353
pub(crate) fn is_set(&self) -> bool {
54-
self.driver
54+
self
55+
.driver
5556
.try_borrow()
5657
.map(|b| b.is_some())
5758
.unwrap_or(false)

src/runtime/driver/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ impl Driver {
134134
cq.sync();
135135

136136
for cqe in cq {
137-
if cqe.user_data() == u64::MAX ||
138-
cqe.user_data() == 0 {
137+
if cqe.user_data() == u64::MAX || cqe.user_data() == 0 {
139138
// Result of the cancellation action. There isn't anything we
140139
// need to do here. We must wait for the CQE for the operation
141140
// that was canceled.
@@ -425,10 +424,7 @@ impl Drop for Driver {
425424

426425
unsafe {
427426
let cancel = opcode::AsyncCancel::new(u64::MAX);
428-
let sqe = cancel
429-
.build()
430-
.user_data(0)
431-
.flags(any_flags);
427+
let sqe = cancel.build().user_data(0).flags(any_flags);
432428

433429
while self.uring.submission().push(&sqe).is_err() {
434430
self

src/runtime/driver/op/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ where
440440
.upgrade()
441441
.expect("Not in runtime context")
442442
.poll_multishot_op(self.get_mut(), cx);
443-
443+
444444
CONTEXT.with(|x| x.call_on_thread_park());
445-
445+
446446
result
447447
}
448448
}

src/runtime/mod.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ mod context;
1212
pub(crate) mod driver;
1313

1414
use crate::runtime::driver::Handle;
15+
use crate::Builder;
1516
pub(crate) use context::RuntimeContext;
16-
use crate::{Builder};
1717

1818
type Context = Arc<RuntimeContext>;
1919

@@ -43,7 +43,7 @@ pub struct Runtime {
4343
signal: Arc<Notify>,
4444

4545
/// Builder for runtime contexts
46-
builder: Builder
46+
builder: Builder,
4747
}
4848

4949
/// Spawns a new asynchronous task, returning a [`JoinHandle`] for it.
@@ -109,7 +109,7 @@ impl Runtime {
109109
tokio_rt: MaybeUninit::zeroed(),
110110
contexts: Default::default(),
111111
builder: builder.clone(),
112-
signal: Arc::new(Notify::new())
112+
signal: Arc::new(Notify::new()),
113113
};
114114

115115
let on_thread_start = runtime.create_on_thread_start_callback();
@@ -128,7 +128,7 @@ impl Runtime {
128128
runtime.start_uring_wakes_task();
129129

130130
CONTEXT.with(|x| {
131-
x.set_handle(Handle::new(&builder).expect("Internal error"));
131+
x.set_handle(Handle::new(builder).expect("Internal error"));
132132
x.set_on_thread_park(Runtime::on_thread_park);
133133
let mut lock = runtime.contexts.lock().unwrap();
134134
lock.push_back(x.clone());
@@ -139,12 +139,12 @@ impl Runtime {
139139
Ok(runtime)
140140
}
141141

142-
fn on_thread_park(){
142+
fn on_thread_park() {
143143
CONTEXT.with(|x| {
144144
let _ = x.handle().flush();
145145
});
146146
}
147-
147+
148148
fn create_on_thread_start_callback(&self) -> impl Fn() + Sync + 'static {
149149
let is_unique = |item: &Context, list: &LinkedList<Context>| {
150150
let item_fd = item.handle().as_raw_fd();
@@ -182,27 +182,25 @@ impl Runtime {
182182
//SAFETY: It's always already initialized on Runtime::new method
183183
let tokio_rt = unsafe { self.tokio_rt.assume_init_ref() };
184184
let _guard = tokio_rt.enter();
185-
self.local.spawn_local(
186-
Runtime::drive_uring_wakes(
187-
self.contexts.clone(),
188-
self.signal.clone(),
189-
self.builder.threads
190-
)
191-
);
185+
self.local.spawn_local(Runtime::drive_uring_wakes(
186+
self.contexts.clone(),
187+
self.signal.clone(),
188+
self.builder.threads,
189+
));
192190
}
193191

194192
async fn drive_uring_wakes(
195193
contexts: Arc<Mutex<LinkedList<Context>>>,
196194
signal: Arc<Notify>,
197-
threads: usize
195+
threads: usize,
198196
) {
199197
let mut total = 0;
200198

201199
while total != threads + 1 {
202200
signal.notified().await;
203201

204202
let mut guard = contexts.lock().unwrap();
205-
203+
206204
for i in guard.iter() {
207205
tokio::spawn(Runtime::wait_event(Item::new(i.clone())));
208206
total += 1;
@@ -262,8 +260,8 @@ impl Drop for Runtime {
262260

263261
#[cfg(test)]
264262
mod test {
265-
use crate::builder;
266263
use super::*;
264+
use crate::builder;
267265

268266
#[test]
269267
fn block_on() {

0 commit comments

Comments
 (0)