Skip to content

Commit

Permalink
smbios: Fix config deadlock
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Schaefer <[email protected]>
  • Loading branch information
JohnAZoidberg committed Oct 17, 2024
1 parent cc8d1ef commit 1d322b4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
4 changes: 3 additions & 1 deletion framework_lib/src/smbios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ pub fn get_platform() -> Option<Platform> {
_ => None,
};

if platform.is_none() {
if let Some(platform) = platform {
Config::set(platform);
} else {
println!("Failed to find PlatformFamily");
}

Expand Down
28 changes: 20 additions & 8 deletions framework_lib/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,31 @@ impl Config {
}

pub fn get() -> MutexGuard<'static, Option<Self>> {
let unset = {
#[cfg(feature = "std")]
let config = CONFIG.lock().unwrap();
#[cfg(not(feature = "std"))]
let config = CONFIG.lock();
(*config).is_none()
};
let new_config = if unset {
// get_platform will call Config::get() recursively,
// can't hold the lock when calling it
smbios::get_platform().map(|platform| Config {
verbose: false,
platform,
})
} else {
None
};

#[cfg(feature = "std")]
let mut config = CONFIG.lock().unwrap();
#[cfg(not(feature = "std"))]
let mut config = CONFIG.lock();

if (*config).is_none() {
if let Some(platform) = smbios::get_platform() {
// TODO: Perhaps add Qemu or NonFramework as a platform
*config = Some(Config {
verbose: false,
platform,
});
}
if new_config.is_some() {
*config = new_config;
}

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

0 comments on commit 1d322b4

Please sign in to comment.