Skip to content

Commit c8d1aea

Browse files
Make Queue initialization lazy
1 parent 8979fa5 commit c8d1aea

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

oneapi-rs/src/event.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct EventFuture {
4343
event: Event,
4444
shared: SharedWaker,
4545
set_callback: bool,
46-
queue: Queue,
46+
queue: Option<Queue>,
4747
}
4848

4949
impl Future for EventFuture {
@@ -55,8 +55,10 @@ impl Future for EventFuture {
5555
// Set the callback on first Future poll (Futures can't be active until polled)
5656
if *this.set_callback == false {
5757
*this.set_callback = true;
58+
let mut queue = Queue::new_immediate();
5859
this.shared.waker.register(cx.waker());
59-
unsafe { ffi::register_callback(&mut this.queue.0, &this.event.0, this.shared) };
60+
unsafe { ffi::register_callback(&mut queue.0, &this.event.0, this.shared) };
61+
this.queue.replace(queue);
6062

6163
// Check the event again to avoid a race condition
6264
// https://docs.rs/futures/latest/futures/task/struct.AtomicWaker.html#examples
@@ -98,7 +100,7 @@ impl IntoFuture for Event {
98100
event: self,
99101
shared: SharedWaker::new(),
100102
set_callback: false,
101-
queue: Queue::new_immediate(),
103+
queue: None,
102104
}
103105
}
104106
}

0 commit comments

Comments
 (0)