@@ -192,7 +192,7 @@ macro_rules! __thread_local_inner {
192
192
static __KEY: $crate:: thread:: __OsLocalKeyInner<$t> =
193
193
$crate:: thread:: __OsLocalKeyInner:: new( ) ;
194
194
195
- unsafe fn __getit( ) -> & ' static Option <$t> { __KEY. get( ) }
195
+ unsafe fn __getit( ) -> & ' static $crate :: option :: Option <$t> { __KEY. get( ) }
196
196
197
197
unsafe fn __get_state( ) -> $crate:: thread:: LocalKeyState { __KEY. get_state( ) }
198
198
@@ -504,39 +504,33 @@ pub mod fast {
504
504
}
505
505
}
506
506
507
- pub fn get ( & self ) -> & ' static Option < T > {
508
- unsafe { & * self . inner . get ( ) }
507
+ pub unsafe fn get ( & self ) -> & ' static Option < T > {
508
+ & * self . inner . get ( )
509
509
}
510
510
511
- pub fn get_state ( & self ) -> LocalKeyState {
512
- unsafe { * self . state . get ( ) }
511
+ pub unsafe fn get_state ( & self ) -> LocalKeyState {
512
+ * self . state . get ( )
513
513
}
514
514
515
- pub fn pre_init ( & self ) {
516
- unsafe {
517
- // It's critical that we set the state to Initializing before
518
- // registering destructors - if registering destructors causes
519
- // allocation, and the global allocator uses TLS, then the
520
- // allocator needs to be able to detect that the TLS is in
521
- // the Initializing state and perform appropriate fallback
522
- // logic rather than recursing infinitely.
523
- * self . state . get ( ) = LocalKeyState :: Initializing ;
524
- self . register_dtor ( ) ;
525
- }
515
+ pub unsafe fn pre_init ( & self ) {
516
+ // It's critical that we set the state to Initializing before
517
+ // registering destructors - if registering destructors causes
518
+ // allocation, and the global allocator uses TLS, then the
519
+ // allocator needs to be able to detect that the TLS is in
520
+ // the Initializing state and perform appropriate fallback
521
+ // logic rather than recursing infinitely.
522
+ * self . state . get ( ) = LocalKeyState :: Initializing ;
523
+ self . register_dtor ( ) ;
526
524
}
527
525
528
- pub fn post_init ( & self , val : T ) {
529
- unsafe {
530
- * self . inner . get ( ) = Some ( val) ;
531
- * self . state . get ( ) = LocalKeyState :: Valid ;
532
- }
526
+ pub unsafe fn post_init ( & self , val : T ) {
527
+ * self . inner . get ( ) = Some ( val) ;
528
+ * self . state . get ( ) = LocalKeyState :: Valid ;
533
529
}
534
530
535
- pub fn rollback_init ( & self ) {
536
- unsafe {
537
- * self . inner . get ( ) = None ;
538
- * self . state . get ( ) = LocalKeyState :: Uninitialized ;
539
- }
531
+ pub unsafe fn rollback_init ( & self ) {
532
+ * self . inner . get ( ) = None ;
533
+ * self . state . get ( ) = LocalKeyState :: Uninitialized ;
540
534
}
541
535
542
536
unsafe fn register_dtor ( & self ) {
@@ -605,54 +599,46 @@ pub mod os {
605
599
}
606
600
}
607
601
608
- pub fn get ( & self ) -> & ' static Option < T > {
609
- unsafe {
610
- match * self . state . get ( ) {
611
- LocalKeyState :: Valid => {
612
- // Since the state is Valid, we know that os points to
613
- // an allocated Value<T>.
614
- let ptr = self . os . get ( ) as * mut Value < T > ;
615
- debug_assert ! ( !ptr. is_null( ) ) ;
616
- & * ( * ptr) . value . get ( )
617
- }
618
- _ => {
619
- // The dummy_value is guaranteed to always be None. This
620
- // allows us to avoid allocating if the state isn't Valid.
621
- // This is critical because it means that an allocator can
622
- // call try_with and detect that the key is in state
623
- // Initializing without recursing infinitely.
624
- & * self . dummy_value . get ( )
625
- }
602
+ pub unsafe fn get ( & self ) -> & ' static Option < T > {
603
+ match * self . state . get ( ) {
604
+ LocalKeyState :: Valid => {
605
+ // Since the state is Valid, we know that os points to
606
+ // an allocated Value<T>.
607
+ let ptr = self . os . get ( ) as * mut Value < T > ;
608
+ debug_assert ! ( !ptr. is_null( ) ) ;
609
+ & * ( * ptr) . value . get ( )
610
+ }
611
+ _ => {
612
+ // The dummy_value is guaranteed to always be None. This
613
+ // allows us to avoid allocating if the state isn't Valid.
614
+ // This is critical because it means that an allocator can
615
+ // call try_with and detect that the key is in state
616
+ // Initializing without recursing infinitely.
617
+ & * self . dummy_value . get ( )
626
618
}
627
619
}
628
620
}
629
621
630
- pub fn get_state ( & self ) -> LocalKeyState {
631
- unsafe { * self . state . get ( ) }
622
+ pub unsafe fn get_state ( & self ) -> LocalKeyState {
623
+ * self . state . get ( )
632
624
}
633
625
634
- pub fn pre_init ( & self ) {
635
- unsafe {
636
- * self . state . get ( ) = LocalKeyState :: Initializing ;
637
- }
626
+ pub unsafe fn pre_init ( & self ) {
627
+ * self . state . get ( ) = LocalKeyState :: Initializing ;
638
628
}
639
629
640
- pub fn rollback_init ( & self ) {
641
- unsafe {
642
- * self . state . get ( ) = LocalKeyState :: Uninitialized ;
643
- }
630
+ pub unsafe fn rollback_init ( & self ) {
631
+ * self . state . get ( ) = LocalKeyState :: Uninitialized ;
644
632
}
645
633
646
- pub fn post_init ( & self , val : T ) {
647
- unsafe {
648
- let ptr: Box < Value < T > > = box Value {
649
- key : & * ( self as * const _ ) ,
650
- value : UnsafeCell :: new ( Some ( val) ) ,
651
- } ;
652
- let ptr = Box :: into_raw ( ptr) ;
653
- self . os . set ( ptr as * mut u8 ) ;
654
- * self . state . get ( ) = LocalKeyState :: Valid ;
655
- }
634
+ pub unsafe fn post_init ( & self , val : T ) {
635
+ let ptr: Box < Value < T > > = box Value {
636
+ key : & * ( self as * const _ ) ,
637
+ value : UnsafeCell :: new ( Some ( val) ) ,
638
+ } ;
639
+ let ptr = Box :: into_raw ( ptr) ;
640
+ self . os . set ( ptr as * mut u8 ) ;
641
+ * self . state . get ( ) = LocalKeyState :: Valid ;
656
642
}
657
643
}
658
644
0 commit comments