Skip to content

Commit e1f9bbb

Browse files
committed
leak handle because why not
Signed-off-by: Onur Satici <[email protected]>
1 parent 128848a commit e1f9bbb

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

vortex-io/src/runtime/uring.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl HandleSet {
103103
}
104104

105105
/// Returns a handle that round-robins spawned work across the underlying executors.
106-
pub(crate) fn dispatching_handle(&self) -> Handle {
106+
pub(crate) fn handle(&self) -> Handle {
107107
let exec: Arc<dyn Executor> = self.dispatcher.clone();
108108
Handle::new(Arc::downgrade(&exec))
109109
}
@@ -115,10 +115,13 @@ impl HandleSet {
115115
}
116116

117117
/// Create a [`Handle`] that dispatches work round-robin across the provided handles.
118+
///
119+
/// The underlying dispatcher is leaked to satisfy the `Handle` lifetime; use [`HandleSet`] directly
120+
/// when you need ownership.
118121
pub fn dispatching_handle(handles: &[Handle]) -> Handle {
119122
let executors = handles.iter().map(|h| h.runtime()).collect::<Vec<_>>();
120-
let set = HandleSet::new(executors);
121-
set.dispatching_handle()
123+
let set = Box::leak(Box::new(HandleSet::new(executors)));
124+
set.handle()
122125
}
123126

124127
/// Messages sent to a per-core runtime thread.
@@ -225,7 +228,7 @@ impl AbortHandle for NoopAbortHandle {
225228
#[allow(dead_code)]
226229
pub struct PerCoreUringPool {
227230
_runtimes: Vec<Arc<UringRuntime>>,
228-
handle: Handle,
231+
handle_set: HandleSet,
229232
}
230233

231234
#[allow(dead_code)]
@@ -238,23 +241,20 @@ impl PerCoreUringPool {
238241
let runtimes: Vec<_> = (0..core_count)
239242
.map(|_| Arc::new(UringRuntime::new()))
240243
.collect();
241-
let handles: Vec<_> = runtimes
244+
let executors: Vec<Arc<dyn Executor>> = runtimes
242245
.iter()
243-
.map(|rt| {
244-
let exec: Arc<dyn Executor> = rt.clone();
245-
Handle::new(Arc::downgrade(&exec))
246-
})
246+
.cloned()
247+
.map(|rt| rt as Arc<dyn Executor>)
247248
.collect();
248-
249-
let handle = dispatching_handle(&handles);
249+
let handle_set = HandleSet::new(executors);
250250

251251
Self {
252252
_runtimes: runtimes,
253-
handle,
253+
handle_set,
254254
}
255255
}
256256

257257
pub fn handle(&self) -> Handle {
258-
self.handle.clone()
258+
self.handle_set.handle()
259259
}
260260
}

0 commit comments

Comments
 (0)