linted code

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
juju committed 2022-12-11 01:39:22 +01:00
1 parent 745b8efb8f
commit b5ebe0d4ad
12 files changed
+72 -62

No files matched your search

+6 -6
View File
@@ -6,7 +6,7 @@ use crossbeam_queue::ArrayQueue;
pub struct Executor {
tasks: BTreeMap<TaskId, Task>,
task_queue: Arc<ArrayQueue<TaskId>>,
waker_cache: BTreeMap<TaskId, Waker>
waker_cache: BTreeMap<TaskId, Waker>,
}
impl Executor {
@@ -14,7 +14,7 @@ impl Executor {
Executor {
tasks: BTreeMap::new(),
task_queue: Arc::new(ArrayQueue::new(100)),
waker_cache: BTreeMap::new()
waker_cache: BTreeMap::new(),
}
}
@@ -48,7 +48,7 @@ impl Executor {
let Self {
tasks,
task_queue,
waker_cache
waker_cache,
} = self; // Executor destructuring
while let Ok(task_id) = task_queue.pop() {
@@ -74,14 +74,14 @@ impl Executor {
struct TaskWaker {
task_id: TaskId,
task_queue: Arc<ArrayQueue<TaskId>>
task_queue: Arc<ArrayQueue<TaskId>>,
}
impl TaskWaker {
fn new(task_id: TaskId, task_queue: Arc<ArrayQueue<TaskId>>) -> Waker {
Waker::from(Arc::new(TaskWaker {
task_id,
task_queue
task_queue,
}))
}
@@ -98,4 +98,4 @@ impl Wake for TaskWaker {
fn wake_by_ref(self: &Arc<Self>) {
self.wake_task();
}
}
}
+14 -12
View File
@@ -1,10 +1,13 @@
use crate::{println, print};
use crate::{print, println};
use conquer_once::spin::OnceCell;
use core::{pin::Pin, task::{Context, Poll}};
use core::{
pin::Pin,
task::{Context, Poll},
};
use crossbeam_queue::ArrayQueue;
use futures_util::task::AtomicWaker;
use futures_util::stream::{Stream, StreamExt};
use futures_util::task::AtomicWaker;
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
static SCANCODE_QUEUE: OnceCell<ArrayQueue<u8>> = OnceCell::uninit();
@@ -18,7 +21,8 @@ pub struct ScancodeStream {
impl ScancodeStream {
pub fn new() -> Self {
SCANCODE_QUEUE.try_init_once(|| ArrayQueue::new(100))
SCANCODE_QUEUE
.try_init_once(|| ArrayQueue::new(100))
.expect("ScancodeStream::new should only be called once");
ScancodeStream { _private: () }
}
@@ -42,8 +46,8 @@ impl Stream for ScancodeStream {
Ok(scancode) => {
WAKER.take();
Poll::Ready(Some(scancode))
},
Err(crossbeam_queue::PopError) => Poll::Pending
}
Err(crossbeam_queue::PopError) => Poll::Pending,
}
}
}
@@ -52,19 +56,17 @@ pub(crate) fn add_scancode(scancode: u8) {
if let Ok(queue) = SCANCODE_QUEUE.try_get() {
if let Err(_) = queue.push(scancode) {
println!("Keyboard scancode queue full, dropping input {}", scancode);
}
else {
} else {
WAKER.wake();
}
}
else {
} else {
println!("Keyboard scancode queue uninitialized");
}
}
pub async fn print_keypresses() {
let mut scancodes = ScancodeStream::new();
let mut keyboard: Keyboard<layouts::Us104Key, ScancodeSet1> =
let mut keyboard: Keyboard<layouts::Us104Key, ScancodeSet1> =
Keyboard::new(layouts::Us104Key, ScancodeSet1, HandleControl::Ignore);
while let Some(scancode) = scancodes.next().await {
@@ -77,4 +79,4 @@ pub async fn print_keypresses() {
}
}
}
}
}
+4 -4
View File
@@ -1,8 +1,8 @@
use alloc::boxed::Box;
use core::future::Future;
use core::pin::Pin;
use core::sync::atomic::{AtomicU64, Ordering};
use core::task::{Context, Poll};
use alloc::boxed::Box;
pub mod executor;
pub mod keyboard;
@@ -19,18 +19,18 @@ impl TaskId {
pub struct Task {
id: TaskId,
future: Pin<Box<dyn Future<Output = ()>>>
future: Pin<Box<dyn Future<Output = ()>>>,
}
impl Task {
pub fn new(future: impl Future<Output = ()> + 'static) -> Task {
Task {
id: TaskId::new(),
future: Box::pin(future)
future: Box::pin(future),
}
}
fn poll(&mut self, context: &mut Context) -> Poll<()> {
self.future.as_mut().poll(context)
}
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.