Skip to content

Commit 9f9df49

Browse files
Merge pull request #61 from FrameworkComputer/smbios-deadlock
smbios: Fix config deadlock
2 parents 12482ad + 1d322b4 commit 9f9df49

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
@@ -266,7 +266,9 @@ pub fn get_platform() -> Option<Platform> {
266266
_ => None,
267267
};
268268

269-
if platform.is_none() {
269+
if let Some(platform) = platform {
270+
Config::set(platform);
271+
} else {
270272
println!("Failed to find PlatformFamily");
271273
}
272274

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)