Skip to content

Commit 6d8704c

Browse files
committed
fix(runtime): use SendWrapper to ensure Send + Sync
1 parent c7dd9c8 commit 6d8704c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

compio-runtime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ criterion = { workspace = true, optional = true }
3939
crossbeam-queue = { workspace = true }
4040
futures-util = { workspace = true }
4141
once_cell = { workspace = true }
42+
send_wrapper = "0.6.0"
4243
slab = { workspace = true, optional = true }
4344
smallvec = "1.11.1"
4445
socket2 = { workspace = true }

compio-runtime/src/runtime/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use compio_driver::{
1919
use compio_log::{debug, instrument};
2020
use crossbeam_queue::SegQueue;
2121
use futures_util::{future::Either, FutureExt};
22+
use send_wrapper::SendWrapper;
2223
use smallvec::SmallVec;
2324

2425
pub(crate) mod op;
@@ -47,7 +48,7 @@ impl Default for FutureState {
4748

4849
pub(crate) struct RuntimeInner {
4950
driver: RefCell<Proactor>,
50-
local_runnables: Arc<RefCell<VecDeque<Runnable>>>,
51+
local_runnables: SendWrapper<Arc<RefCell<VecDeque<Runnable>>>>,
5152
sync_runnables: Arc<SegQueue<Runnable>>,
5253
op_runtime: RefCell<OpRuntime>,
5354
#[cfg(feature = "time")]
@@ -60,7 +61,7 @@ impl RuntimeInner {
6061
driver: RefCell::new(builder.build()?),
6162
// Arc to send to another thread, but only in current thread will the inner be accessed.
6263
#[allow(clippy::arc_with_non_send_sync)]
63-
local_runnables: Arc::new(RefCell::new(VecDeque::new())),
64+
local_runnables: SendWrapper::new(Arc::new(RefCell::new(VecDeque::new()))),
6465
sync_runnables: Arc::new(SegQueue::new()),
6566
op_runtime: RefCell::default(),
6667
#[cfg(feature = "time")]
@@ -77,10 +78,8 @@ impl RuntimeInner {
7778
.borrow()
7879
.handle()
7980
.expect("cannot create notify handle of the proactor");
80-
let main_id = std::thread::current().id();
8181
let schedule = move |runnable| {
82-
let in_current_thread = main_id == std::thread::current().id();
83-
if in_current_thread {
82+
if local_runnables.valid() {
8483
local_runnables.borrow_mut().push_back(runnable);
8584
} else {
8685
sync_runnables.push(runnable);

0 commit comments

Comments
 (0)