@@ -377,11 +377,14 @@ mod context {
377377
378378 static GLOBAL : spin:: Mutex < DeviceLocator > = spin:: Mutex :: new ( DeviceLocator { state : None } ) ;
379379
380+ #[ derive( Default ) ]
381+ struct DeviceLocatorState {
382+ device : HashMap < Key , DeviceStateLock > ,
383+ device_kind : HashMap < TypeId , Arc < ReentrantMutex < ( ) > > > ,
384+ }
385+
380386 struct DeviceLocator {
381- state : Option < (
382- HashMap < Key , DeviceStateLock > ,
383- HashMap < TypeId , Arc < ReentrantMutex < ( ) > > > ,
384- ) > ,
387+ state : Option < DeviceLocatorState > ,
385388 }
386389
387390 #[ derive( Clone ) ]
@@ -400,15 +403,15 @@ mod context {
400403 let key = ( id, TypeId :: of :: < D > ( ) ) ;
401404 let mut global = GLOBAL . lock ( ) ;
402405
403- let map = match & mut global. state {
406+ let locator_state = match & mut global. state {
404407 Some ( state) => state,
405408 None => {
406- global. state = Some ( ( HashMap :: default ( ) , HashMap :: new ( ) ) ) ;
409+ global. state = Some ( Default :: default ( ) ) ;
407410 global. state . as_mut ( ) . expect ( "Just created Option::Some" )
408411 }
409412 } ;
410413
411- let lock = match map . 0 . get ( & key) {
414+ let lock = match locator_state . device . get ( & key) {
412415 Some ( value) => value. clone ( ) ,
413416 None => {
414417 let state = DeviceStateMap :: new ( ) ;
@@ -417,18 +420,22 @@ mod context {
417420 lock : Arc :: new ( ReentrantMutex :: new ( state) ) ,
418421 } ;
419422
420- map. 0 . insert ( key, value) ;
421- map. 0
423+ locator_state. device . insert ( key, value) ;
424+ locator_state
425+ . device
422426 . get ( & key)
423427 . expect ( "Just inserted the key/value" )
424428 . clone ( )
425429 }
426430 } ;
427- let lock_kind = match map . 1 . get ( & kind) {
431+ let lock_kind = match locator_state . device_kind . get ( & kind) {
428432 Some ( value) => value. clone ( ) ,
429433 None => {
430- map. 1 . insert ( kind, Arc :: new ( ReentrantMutex :: new ( ( ) ) ) ) ;
431- map. 1
434+ locator_state
435+ . device_kind
436+ . insert ( kind, Arc :: new ( ReentrantMutex :: new ( ( ) ) ) ) ;
437+ locator_state
438+ . device_kind
432439 . get ( & kind)
433440 . expect ( "Just inserted the key/value" )
434441 . clone ( )
0 commit comments