qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 21/26] rust: tests: allow writing more than one test


From: Paolo Bonzini
Subject: Re: [PATCH 21/26] rust: tests: allow writing more than one test
Date: Mon, 16 Dec 2024 16:07:38 +0100

On Thu, Dec 12, 2024 at 10:46 AM Zhao Liu <zhao1.liu@intel.com> wrote:
>
> > +fn init_qom() {
> > +    static ONCE: Mutex<Cell<bool>> = Mutex::new(Cell::new(false));
> > +
> > +    let g = ONCE.lock().unwrap();
> > +    if !g.get() {
> > +        unsafe {
> > +            module_call_init(module_init_type::MODULE_INIT_QOM);
> > +        }
> > +        g.set(true);
> > +    }
> > +}
>
> Only one question: what is the purpose of using a Mutex here?

Different #[test] functions can be run in parallel. For now there is
nothing that needs the BQL in the tests, so I used an independent
Mutex (which could become a LazyLock later when the minimum supported
Rust version is bumped).

It could also use unsafe { bql_lock(); } and a BqlCell. I left that
for when there will be a way to lock the BQL from safe Rust code, but
I can also do that now already.

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]