Skip to content

Commit 1d322b4

Browse files
committed
smbios: Fix config deadlock
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent cc8d1ef commit 1d322b4

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

framework_lib/src/smbios.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ pub fn get_platform() -> Option<Platform> {
261261
_ => None,
262262
};
263263

264-
if platform.is_none() {
264+
if let Some(platform) = platform {
265+
Config::set(platform);
266+
} else {
265267
println!("Failed to find PlatformFamily");
266268
}
267269

framework_lib/src/util.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,31 @@ impl Config {
6464
}
6565

6666
pub fn get() -> MutexGuard<'static, Option<Self>> {
67+
let unset = {
68+
#[cfg(feature = "std")]
69+
let config = CONFIG.lock().unwrap();
70+
#[cfg(not(feature = "std"))]
71+
let config = CONFIG.lock();
72+
(*config).is_none()
73+
};
74+
let new_config = if unset {
75+
// get_platform will call Config::get() recursively,
76+
// can't hold the lock when calling it
77+
smbios::get_platform().map(|platform| Config {
78+
verbose: false,
79+
platform,
80+
})
81+
} else {
82+
None
83+
};
84+
6785
#[cfg(feature = "std")]
6886
let mut config = CONFIG.lock().unwrap();
6987
#[cfg(not(feature = "std"))]
7088
let mut config = CONFIG.lock();
7189

72-
if (*config).is_none() {
73-
if let Some(platform) = smbios::get_platform() {
74-
// TODO: Perhaps add Qemu or NonFramework as a platform
75-
*config = Some(Config {
76-
verbose: false,
77-
platform,
78-
});
79-
}
90+
if new_config.is_some() {
91+
*config = new_config;
8092
}
8193

8294
// TODO: See if we can map the Option::unwrap before returning

0 commit comments

Comments
 (0)