Skip to content

Commit e7d75e6

Browse files
George-MiaoCopilot
andauthored
ci: add job to check code format (#495)
* ci: add job to check code format * style: compio-fs/src/file.rs Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent c3eb5f7 commit e7d75e6

File tree

4 files changed

+56
-22
lines changed

4 files changed

+56
-22
lines changed

.github/workflows/ci_format.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Check Code Format
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
env:
12+
RUST_BACKTRACE: 1
13+
14+
jobs:
15+
check:
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Setup Rust Toolchain
20+
run: |
21+
rustup default nightly
22+
rustup component add rustfmt
23+
- name: Check Format
24+
run: cargo fmt --all -- --check

compio-fs/src/file.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ use crate::{Metadata, OpenOptions, Permissions};
2323
/// it was opened with. The `File` type provides **positional** read and write
2424
/// operations. The file does not maintain an internal cursor. The caller is
2525
/// required to specify an offset when issuing an operation.
26-
///
27-
///
28-
/// If you'd like to use methods from [`AsyncRead`](`compio_io::AsyncRead`) or [`AsyncWrite`](`compio_io::AsyncWrite`) traits,
29-
/// you can wrap `File` with [`std::io::Cursor`].
26+
///
27+
///
28+
/// If you'd like to use methods from [`AsyncRead`](`compio_io::AsyncRead`) or
29+
/// [`AsyncWrite`](`compio_io::AsyncWrite`) traits, you can wrap `File` with
30+
/// [`std::io::Cursor`].
31+
///
3032
/// # Examples
3133
/// ```ignore
3234
/// use compio::fs::File;
@@ -35,13 +37,13 @@ use crate::{Metadata, OpenOptions, Permissions};
3537
///
3638
/// let file = File::open("foo.txt").await?;
3739
/// let cursor = Cursor::new(file);
38-
///
40+
///
3941
/// let int = cursor.read_u32().await?;
4042
/// let float = cursor.read_f32().await?;
41-
///
43+
///
4244
/// let mut string = String::new();
4345
/// let BufResult(result, string) = cursor.read_to_string(string).await;
44-
///
46+
///
4547
/// let mut buf = vec![0; 1024];
4648
/// let BufResult(result, buf) = cursor.read_exact(buf).await;
4749
/// ```

compio-runtime/src/runtime/scheduler/mod.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
use crate::runtime::scheduler::{
2-
drop_hook::DropHook, local_queue::LocalQueue, send_wrapper::SendWrapper,
3-
};
1+
use std::{cell::RefCell, future::Future, marker::PhantomData, rc::Rc, sync::Arc, task::Waker};
2+
43
use async_task::{Runnable, Task};
54
use compio_driver::NotifyHandle;
65
use crossbeam_queue::SegQueue;
76
use slab::Slab;
8-
use std::{cell::RefCell, future::Future, marker::PhantomData, rc::Rc, sync::Arc, task::Waker};
7+
8+
use crate::runtime::scheduler::{
9+
drop_hook::DropHook, local_queue::LocalQueue, send_wrapper::SendWrapper,
10+
};
911

1012
mod drop_hook;
1113
mod local_queue;
@@ -28,8 +30,8 @@ impl TaskQueue {
2830

2931
/// Pushes a `Runnable` task to the appropriate queue.
3032
///
31-
/// If the current thread is the same as the creator thread, push to the local queue.
32-
/// Otherwise, push to the sync queue.
33+
/// If the current thread is the same as the creator thread, push to the
34+
/// local queue. Otherwise, push to the sync queue.
3335
fn push(&self, runnable: Runnable, notify: &NotifyHandle) {
3436
if let Some(local_queue) = self.local_queue.get() {
3537
local_queue.push(runnable);
@@ -41,7 +43,8 @@ impl TaskQueue {
4143
}
4244
}
4345

44-
/// Pops at most one task from each queue and returns them as `(local_task, sync_task)`.
46+
/// Pops at most one task from each queue and returns them as `(local_task,
47+
/// sync_task)`.
4548
///
4649
/// # Safety
4750
///
@@ -52,7 +55,8 @@ impl TaskQueue {
5255

5356
let local_task = local_queue.pop();
5457

55-
// Perform an empty check as a fast path, since `SegQueue::pop()` is more expensive.
58+
// Perform an empty check as a fast path, since `SegQueue::pop()` is more
59+
// expensive.
5660
let sync_task = if self.sync_queue.is_empty() {
5761
None
5862
} else {
@@ -145,13 +149,15 @@ impl Scheduler {
145149
};
146150

147151
let schedule = {
148-
// The schedule closure is managed by the `Waker` and may be dropped on another thread,
149-
// so use `Weak` to ensure the `TaskQueue` is always dropped on the creator thread.
152+
// The schedule closure is managed by the `Waker` and may be dropped on another
153+
// thread, so use `Weak` to ensure the `TaskQueue` is always dropped
154+
// on the creator thread.
150155
let task_queue = Arc::downgrade(&self.task_queue);
151156

152157
move |runnable| {
153-
// The `upgrade()` never fails because all tasks are dropped when the `Scheduler` is dropped,
154-
// if a `Waker` is used after that, the schedule closure will never be called.
158+
// The `upgrade()` never fails because all tasks are dropped when the
159+
// `Scheduler` is dropped, if a `Waker` is used after that, the
160+
// schedule closure will never be called.
155161
task_queue.upgrade().unwrap().push(runnable, &notify);
156162
}
157163
};
@@ -216,8 +222,9 @@ impl Scheduler {
216222
// Then drop all scheduled tasks, which will drop all futures.
217223
//
218224
// SAFETY:
219-
// Since spawned tasks are not required to be `Send`, they must always be dropped
220-
// on the same thread. Because `Scheduler` is `!Send` and `!Sync`, this is safe.
225+
// Since spawned tasks are not required to be `Send`, they must always be
226+
// dropped on the same thread. Because `Scheduler` is `!Send` and
227+
// `!Sync`, this is safe.
221228
//
222229
// This method is only called on `TaskQueue`'s creator thread
223230
// because `Scheduler` is `!Send` and `!Sync`.

compio-runtime/tests/drop.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use futures_util::task::AtomicWaker;
21
use std::{
32
future::Future,
43
pin::Pin,
@@ -7,6 +6,8 @@ use std::{
76
thread::{self, ThreadId},
87
};
98

9+
use futures_util::task::AtomicWaker;
10+
1011
struct DropWatcher {
1112
waker: Arc<AtomicWaker>,
1213
thread_id: ThreadId,

0 commit comments

Comments
 (0)