Unverified Commit 3596c033 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: fix race condition in unit test (#82989)

parent 1029d059
......@@ -2,7 +2,7 @@
#![feature(arbitrary_self_types_pointers)]
#![allow(clippy::needless_return)] // tokio macro-generated code doesn't respect this
use std::sync::Mutex;
use std::{collections::HashSet, mem::take, sync::Mutex};
use anyhow::Result;
use turbo_tasks::{IntoTraitRef, Invalidator, TraitRef, Vc, get_invalidator};
......@@ -14,7 +14,7 @@ static REGISTRATION: Registration = register!();
async fn trait_ref() {
run(&REGISTRATION, || async {
let counter = Counter::cell(Counter {
value: Mutex::new((0, None)),
value: Mutex::new((0, Default::default())),
});
let counter_value = counter.get_value();
......@@ -64,14 +64,14 @@ struct CounterValue(usize);
#[turbo_tasks::value(serialization = "none", cell = "new", eq = "manual")]
struct Counter {
#[turbo_tasks(debug_ignore, trace_ignore)]
value: Mutex<(usize, Option<Invalidator>)>,
value: Mutex<(usize, HashSet<Invalidator>)>,
}
impl Counter {
fn incr(&self) {
let mut lock = self.value.lock().unwrap();
lock.0 += 1;
if let Some(i) = lock.1.take() {
for i in take(&mut lock.1) {
i.invalidate();
}
}
......@@ -90,7 +90,7 @@ impl CounterTrait for Counter {
#[turbo_tasks::function]
fn get_value(&self) -> Result<Vc<CounterValue>> {
let mut lock = self.value.lock().unwrap();
lock.1 = Some(get_invalidator());
lock.1.insert(get_invalidator());
Ok(Vc::cell(lock.0))
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment