On Thu, Dec 12, 2024 at 10:46 AM Zhao Liu <zhao1....@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