[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
- [PATCH 26/26] rust: callbacks: allow passing optional callbacks as (), (continued)
[PATCH 23/26] rust: qom: add initial subset of methods on Object, Paolo Bonzini, 2024/12/09
[PATCH 21/26] rust: tests: allow writing more than one test, Paolo Bonzini, 2024/12/09
[PATCH 12/26] rust: qdev: move bridge for realize and reset functions out of pl011, Paolo Bonzini, 2024/12/09
[PATCH 18/26] rust: qom: add possibility of overriding unparent, Paolo Bonzini, 2024/12/09
[PATCH 25/26] rust: qemu-api: add a module to wrap functions and zero-sized closures, Paolo Bonzini, 2024/12/09
[PATCH 19/26] rust: rename qemu-api modules to follow C code a bit more, Paolo Bonzini, 2024/12/09