script: Unsilence all main thread TaskQueue errors (#34849)

No longer hide errors while queueing tasks on the main thread. This
requires creating two types of `TaskSource`s: one for the main thread
and one that can be sent to other threads. This makes queueing a bit
more efficient on the main thread and more importantly, no longer hides
task queue errors.

Fixes #25688.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This commit is contained in:
Martin Robinson 2025-01-07 04:36:39 +01:00 committed by GitHub
parent d252a631d2
commit fe8a22b72c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
48 changed files with 628 additions and 571 deletions

View file

@ -75,42 +75,31 @@ pub struct TaskCanceller {
impl TaskCanceller {
/// Returns a wrapped `task` that will be cancelled if the `TaskCanceller` says so.
pub(crate) fn wrap_task<T>(&self, task: T) -> impl TaskOnce
where
T: TaskOnce,
{
pub(crate) fn wrap_task(&self, task: impl TaskOnce) -> impl TaskOnce {
CancellableTask {
cancelled: self.cancelled.clone(),
canceller: self.clone(),
inner: task,
}
}
pub(crate) fn cancelled(&self) -> bool {
self.cancelled.load(Ordering::SeqCst)
}
}
/// A task that can be cancelled by toggling a shared flag.
pub struct CancellableTask<T: TaskOnce> {
cancelled: Arc<AtomicBool>,
canceller: TaskCanceller,
inner: T,
}
impl<T> CancellableTask<T>
where
T: TaskOnce,
{
fn is_cancelled(&self) -> bool {
self.cancelled.load(Ordering::SeqCst)
}
}
impl<T> TaskOnce for CancellableTask<T>
where
T: TaskOnce,
{
impl<T: TaskOnce> TaskOnce for CancellableTask<T> {
fn name(&self) -> &'static str {
self.inner.name()
}
fn run_once(self) {
if !self.is_cancelled() {
if !self.canceller.cancelled() {
self.inner.run_once()
}
}