File tree 2 files changed +23
-9
lines changed
2 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -266,7 +266,9 @@ pub fn get_platform() -> Option<Platform> {
266
266
_ => None ,
267
267
} ;
268
268
269
- if platform. is_none ( ) {
269
+ if let Some ( platform) = platform {
270
+ Config :: set ( platform) ;
271
+ } else {
270
272
println ! ( "Failed to find PlatformFamily" ) ;
271
273
}
272
274
Original file line number Diff line number Diff line change @@ -64,19 +64,31 @@ impl Config {
64
64
}
65
65
66
66
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
+
67
85
#[ cfg( feature = "std" ) ]
68
86
let mut config = CONFIG . lock ( ) . unwrap ( ) ;
69
87
#[ cfg( not( feature = "std" ) ) ]
70
88
let mut config = CONFIG . lock ( ) ;
71
89
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;
80
92
}
81
93
82
94
// TODO: See if we can map the Option::unwrap before returning
You can’t perform that action at this time.
0 commit comments