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 13c7eb6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
2 changes: 2 additions & 0 deletions framework_lib/src/smbios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ pub fn get_platform() -> Option<Platform> {

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

assert!(cached_platform.is_none());
Expand Down
33 changes: 25 additions & 8 deletions framework_lib/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,36 @@ impl Config {
}

pub fn get() -> MutexGuard<'static, Option<Self>> {
#[cfg(feature = "std")]
let mut config = CONFIG.lock().unwrap();
#[cfg(not(feature = "std"))]
let mut config = CONFIG.lock();

if (*config).is_none() {
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
if let Some(platform) = smbios::get_platform() {
// TODO: Perhaps add Qemu or NonFramework as a platform
*config = Some(Config {
Some(Config {
verbose: false,
platform,
});
})
} else {
None
}
} else {
None
};

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

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 13c7eb6

Please sign in to comment.