From 911890417df342330d339fc945fb348ddfeb8ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Sat, 23 Nov 2024 17:12:02 +0900 Subject: [PATCH] fix(runtime): wrap runnable queue with Arc to make it Send & Sync --- compio-runtime/src/runtime/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compio-runtime/src/runtime/mod.rs b/compio-runtime/src/runtime/mod.rs index 9518aca4..c26c9a20 100644 --- a/compio-runtime/src/runtime/mod.rs +++ b/compio-runtime/src/runtime/mod.rs @@ -6,6 +6,7 @@ use std::{ io, panic::AssertUnwindSafe, rc::Rc, + sync::Arc, task::Poll, time::Duration, }; @@ -85,7 +86,7 @@ impl RunnableQueue { /// sent to other threads. pub struct Runtime { driver: Rc>, - runnables: Rc, + runnables: Arc, #[cfg(feature = "time")] timer_runtime: Rc>, event_interval: usize, @@ -105,7 +106,7 @@ impl Runtime { fn with_builder(builder: &RuntimeBuilder) -> io::Result { Ok(Self { driver: Rc::new(RefCell::new(builder.proactor_builder.build()?)), - runnables: Rc::new(RunnableQueue::new()), + runnables: Arc::new(RunnableQueue::new()), #[cfg(feature = "time")] timer_runtime: Rc::new(RefCell::new(TimerRuntime::new())), event_interval: builder.event_interval, @@ -152,7 +153,7 @@ impl Runtime { /// /// The caller should ensure the captured lifetime long enough. pub unsafe fn spawn_unchecked(&self, future: F) -> Task { - let runnables = Rc::downgrade(&self.runnables); + let runnables = Arc::downgrade(&self.runnables); let handle = self .driver .borrow()