Skip to content

Commit d3a0689

Browse files
authored
fix: fix drop ordering issue (#186)
1 parent 82b0007 commit d3a0689

File tree

8 files changed

+20
-19
lines changed

8 files changed

+20
-19
lines changed

README-zh.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Monoio 就是这样一个 Runtime:它并不像 Tokio 那样通过公平调度
3939

4040
这是一个非常简单的例子,基于 Monoio 实现一个简单的 echo 服务。运行起来之后你可以通过 `nc 127.0.0.1 50002` 来连接它。
4141

42-
```rust
42+
```rust,no_run
4343
/// A echo example.
4444
///
4545
/// Run the example and `nc 127.0.0.1 50002` in another shell.
@@ -66,7 +66,7 @@ async fn main() {
6666
}
6767
}
6868
69-
async fn echo(stream: TcpStream) -> std::io::Result<()> {
69+
async fn echo(mut stream: TcpStream) -> std::io::Result<()> {
7070
let mut buf: Vec<u8> = Vec::with_capacity(8 * 1024);
7171
let mut res;
7272
loop {

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Also, if you want to use io_uring, you must make sure your kernel supports it([5
3636

3737
Here is a basic example of how to use Monoio.
3838

39-
```rust
39+
```rust,no_run
4040
/// A echo example.
4141
///
4242
/// Run the example and `nc 127.0.0.1 50002` in another shell.
@@ -63,7 +63,7 @@ async fn main() {
6363
}
6464
}
6565
66-
async fn echo(stream: TcpStream) -> std::io::Result<()> {
66+
async fn echo(mut stream: TcpStream) -> std::io::Result<()> {
6767
let mut buf: Vec<u8> = Vec::with_capacity(8 * 1024);
6868
let mut res;
6969
loop {

monoio/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "MIT/Apache-2.0"
88
name = "monoio"
99
readme = "../README.md"
1010
repository = "https://github.com/bytedance/monoio"
11-
version = "0.1.5"
11+
version = "0.1.6"
1212

1313
# common dependencies
1414
[dependencies]
@@ -35,7 +35,7 @@ tracing = { version = "0.1", default-features = false, features = [
3535
ctrlc = { version = "3", optional = true }
3636

3737
# windows dependencies(will be added when windows support finished)
38-
[dependencies.windows-sys]
38+
[target.'cfg(windows)'.dependencies.windows-sys]
3939
features = ["Win32_Foundation", "Win32_Networking_WinSock"]
4040
version = "0.48.0"
4141

monoio/src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl Buildable for LegacyDriver {
102102
let context = crate::runtime::Context::new(blocking_handle);
103103
#[cfg(not(feature = "sync"))]
104104
let context = crate::runtime::Context::new();
105-
Ok(Runtime { driver, context })
105+
Ok(Runtime::new(context, driver))
106106
})
107107
}
108108
}
@@ -123,7 +123,7 @@ impl Buildable for IoUringDriver {
123123
let context = crate::runtime::Context::new(blocking_handle);
124124
#[cfg(not(feature = "sync"))]
125125
let context = crate::runtime::Context::new();
126-
Ok(Runtime { driver, context })
126+
Ok(Runtime::new(context, driver))
127127
})
128128
}
129129
}

monoio/src/driver/uring/lifecycle.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ impl<'a> Ref<'a, Lifecycle> {
7676
if let Some(data) = data.take() {
7777
*ref_mut = Lifecycle::Ignored(Box::new(data));
7878
} else {
79-
*ref_mut = Lifecycle::Ignored(Box::new(())); // () is a ZST, so it does not allocate
79+
*ref_mut = Lifecycle::Ignored(Box::new(())); // () is a ZST, so it does not
80+
// allocate
8081
};
8182
return false;
8283
}

monoio/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(io_error_more)]
77
#![feature(lazy_cell)]
88
#![feature(slice_internals)]
9+
#![feature(stmt_expr_attributes)]
910

1011
#[macro_use]
1112
pub mod macros;

monoio/src/runtime.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ thread_local! {
3232
scoped_thread_local!(pub(crate) static CURRENT: Context);
3333

3434
pub(crate) struct Context {
35+
/// Owned task set and local run queue
36+
pub(crate) tasks: TaskQueue,
37+
3538
/// Thread id(not the kernel thread id but a generated unique number)
3639
pub(crate) thread_id: usize,
3740

@@ -45,8 +48,6 @@ pub(crate) struct Context {
4548
pub(crate) waker_sender_cache:
4649
std::cell::RefCell<fxhash::FxHashMap<usize, flume::Sender<std::task::Waker>>>,
4750

48-
/// Owned task set and local run queue
49-
pub(crate) tasks: TaskQueue,
5051
/// Time Handle
5152
pub(crate) time_handle: Option<TimeHandle>,
5253

@@ -95,10 +96,7 @@ impl Context {
9596
let w = v.clone();
9697
self.unpark_cache.borrow_mut().insert(id, w);
9798
v.unpark();
98-
return;
9999
}
100-
101-
panic!("thread to unpark has not been registered");
102100
}
103101

104102
#[allow(unused)]
@@ -114,20 +112,21 @@ impl Context {
114112
// Write back to local cache
115113
let _ = s.send(w);
116114
self.waker_sender_cache.borrow_mut().insert(id, s);
117-
return;
118115
}
119-
120-
panic!("sender has not been registered");
121116
}
122117
}
123118

124119
/// Monoio runtime
125120
pub struct Runtime<D> {
126-
pub(crate) driver: D,
127121
pub(crate) context: Context,
122+
pub(crate) driver: D,
128123
}
129124

130125
impl<D> Runtime<D> {
126+
pub(crate) fn new(context: Context, driver: D) -> Self {
127+
Self { context, driver }
128+
}
129+
131130
/// Block on
132131
pub fn block_on<F>(&mut self, future: F) -> F::Output
133132
where

monoio/src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Common utils
22
3+
pub(crate) mod box_into_inner;
34
pub(crate) mod linked_list;
45
pub(crate) mod slab;
56
pub(crate) mod thread_id;
67
pub(crate) mod uring_detect;
7-
pub(crate) mod box_into_inner;
88

99
mod rand;
1010
pub use rand::thread_rng_n;

0 commit comments

Comments
 (0)