File tree Expand file tree Collapse file tree 2 files changed +23
-9
lines changed Expand file tree Collapse file tree 2 files changed +23
-9
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments