Properties are initialized lazily but always accessed within the big QEMU lock.

There is no need to have a OnceLock around them, and also OnceCell/OnceLock
were only stabilized in 1.70.0; so remove it.

Signed-off-by: Paolo Bonzini <pbonz...@redhat.com>
---
 rust/qemu-api/src/device_class.rs | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/rust/qemu-api/src/device_class.rs 
b/rust/qemu-api/src/device_class.rs
index b6b68cf9ce2..87892b50c63 100644
--- a/rust/qemu-api/src/device_class.rs
+++ b/rust/qemu-api/src/device_class.rs
@@ -2,8 +2,6 @@
 // Author(s): Manos Pitsidianakis <manos.pitsidiana...@linaro.org>
 // SPDX-License-Identifier: GPL-2.0-or-later
 
-use std::sync::OnceLock;
-
 use crate::bindings::Property;
 
 #[macro_export]
@@ -73,12 +71,15 @@ macro_rules! define_property {
 }
 
 #[repr(C)]
-pub struct Properties<const N: usize>(pub OnceLock<[Property; N]>, pub fn() -> 
[Property; N]);
+pub struct Properties<const N: usize>(pub Option<[Property; N]>, pub fn() -> 
[Property; N]);
 
 impl<const N: usize> Properties<N> {
     pub fn as_mut_ptr(&mut self) -> *mut Property {
-        _ = self.0.get_or_init(self.1);
-        self.0.get_mut().unwrap().as_mut_ptr()
+        match self.0 {
+            None => { self.0 = Some(self.1()); },
+            Some(_) => {},
+        }
+        self.0.as_mut().unwrap().as_mut_ptr()
     }
 }
 
@@ -104,7 +105,7 @@ const fn _calc_prop_len() -> usize {
         }
 
         #[no_mangle]
-        pub static mut $ident: $crate::device_class::Properties<PROP_LEN> = 
$crate::device_class::Properties(::std::sync::OnceLock::new(), 
_make_properties);
+        pub static mut $ident: $crate::device_class::Properties<PROP_LEN> = 
$crate::device_class::Properties(None, _make_properties);
     };
 }
 
-- 
2.46.2


Reply via email to