mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-02-23 16:16:25 +00:00
ts/executor: clear the reactor instead of closing it...
... so that it can be reused on current thread for subsequent Scheduler instantiations (e.g. block_on) without the need to reallocate internal data structures.
This commit is contained in:
parent
61c62ee1e8
commit
af12bce141
2 changed files with 16 additions and 3 deletions
|
@ -123,9 +123,22 @@ impl Reactor {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close() {
|
/// Clears the `Reactor`.
|
||||||
|
///
|
||||||
|
/// It will be ready for reuse on current thread without reallocating.
|
||||||
|
pub fn clear() {
|
||||||
let _ = CURRENT_REACTOR.try_with(|cur_reactor| {
|
let _ = CURRENT_REACTOR.try_with(|cur_reactor| {
|
||||||
*cur_reactor.borrow_mut() = None;
|
cur_reactor.borrow_mut().as_mut().map(|reactor| {
|
||||||
|
reactor.ticker = AtomicUsize::new(0);
|
||||||
|
reactor.wakers.clear();
|
||||||
|
reactor.sources.clear();
|
||||||
|
reactor.events.clear();
|
||||||
|
reactor.timers.clear();
|
||||||
|
reactor.after_timers.clear();
|
||||||
|
while !reactor.timer_ops.is_empty() {
|
||||||
|
let _ = reactor.timer_ops.pop();
|
||||||
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -242,7 +242,7 @@ impl Scheduler {
|
||||||
context_name,
|
context_name,
|
||||||
);
|
);
|
||||||
|
|
||||||
Reactor::close();
|
Reactor::clear();
|
||||||
|
|
||||||
let _ = CURRENT_SCHEDULER.try_with(|cur_scheduler| {
|
let _ = CURRENT_SCHEDULER.try_with(|cur_scheduler| {
|
||||||
*cur_scheduler.borrow_mut() = None;
|
*cur_scheduler.borrow_mut() = None;
|
||||||
|
|
Loading…
Reference in a new issue