@@ -1737,20 +1737,28 @@ pub mod tls {
17371737 pub task : & ' a OpenTask ,
17381738 }
17391739
1740+ /// Sets Rayon's thread local variable which is preserved for Rayon jobs
1741+ /// to `value` during the call to `f`. It is restored to its previous value after.
1742+ /// This is used to set the pointer to the new ImplicitCtxt.
17401743 #[ cfg( parallel_queries) ]
17411744 fn set_tlv < F : FnOnce ( ) -> R , R > ( value : usize , f : F ) -> R {
17421745 rayon_core:: tlv:: with ( value, f)
17431746 }
17441747
1748+ /// Gets Rayon's thread local variable which is preserved for Rayon jobs.
1749+ /// This is used to get the pointer to the current ImplicitCtxt.
17451750 #[ cfg( parallel_queries) ]
17461751 fn get_tlv ( ) -> usize {
17471752 rayon_core:: tlv:: get ( )
17481753 }
17491754
1750- // A thread local value which stores a pointer to the current ImplicitCtxt
1755+ /// A thread local variable which stores a pointer to the current ImplicitCtxt
17511756 #[ cfg( not( parallel_queries) ) ]
17521757 thread_local ! ( static TLV : Cell <usize > = Cell :: new( 0 ) ) ;
17531758
1759+ /// Sets TLV to `value` during the call to `f`.
1760+ /// It is restored to its previous value after.
1761+ /// This is used to set the pointer to the new ImplicitCtxt.
17541762 #[ cfg( not( parallel_queries) ) ]
17551763 fn set_tlv < F : FnOnce ( ) -> R , R > ( value : usize , f : F ) -> R {
17561764 let old = get_tlv ( ) ;
@@ -1759,6 +1767,7 @@ pub mod tls {
17591767 f ( )
17601768 }
17611769
1770+ /// This is used to get the pointer to the current ImplicitCtxt.
17621771 #[ cfg( not( parallel_queries) ) ]
17631772 fn get_tlv ( ) -> usize {
17641773 TLV . with ( |tlv| tlv. get ( ) )
@@ -1828,9 +1837,11 @@ pub mod tls {
18281837 where F : for < ' a > FnOnce ( TyCtxt < ' a , ' gcx , ' gcx > ) -> R
18291838 {
18301839 with_thread_locals ( || {
1840+ // Update GCX_PTR to indicate there's a GlobalCtxt available
18311841 GCX_PTR . with ( |lock| {
18321842 * lock. lock ( ) = gcx as * const _ as usize ;
18331843 } ) ;
1844+ // Set GCX_PTR back to 0 when we exit
18341845 let _on_drop = OnDrop ( move || {
18351846 GCX_PTR . with ( |lock| * lock. lock ( ) = 0 ) ;
18361847 } ) ;
@@ -1851,8 +1862,13 @@ pub mod tls {
18511862 } )
18521863 }
18531864
1865+ /// Stores a pointer to the GlobalCtxt if one is available.
1866+ /// This is used to access the GlobalCtxt in the deadlock handler
1867+ /// given to Rayon.
18541868 scoped_thread_local ! ( pub static GCX_PTR : Lock <usize >) ;
18551869
1870+ /// Creates a TyCtxt and ImplicitCtxt based on the GCX_PTR thread local.
1871+ /// This is used in the deadlock handler.
18561872 pub unsafe fn with_global < F , R > ( f : F ) -> R
18571873 where F : for <' a , ' gcx , ' tcx > FnOnce ( TyCtxt < ' a , ' gcx , ' tcx > ) -> R
18581874 {
0 commit comments