@@ -1737,20 +1737,28 @@ pub mod tls {
1737
1737
pub task : & ' a OpenTask ,
1738
1738
}
1739
1739
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.
1740
1743
#[ cfg( parallel_queries) ]
1741
1744
fn set_tlv < F : FnOnce ( ) -> R , R > ( value : usize , f : F ) -> R {
1742
1745
rayon_core:: tlv:: with ( value, f)
1743
1746
}
1744
1747
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.
1745
1750
#[ cfg( parallel_queries) ]
1746
1751
fn get_tlv ( ) -> usize {
1747
1752
rayon_core:: tlv:: get ( )
1748
1753
}
1749
1754
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
1751
1756
#[ cfg( not( parallel_queries) ) ]
1752
1757
thread_local ! ( static TLV : Cell <usize > = Cell :: new( 0 ) ) ;
1753
1758
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.
1754
1762
#[ cfg( not( parallel_queries) ) ]
1755
1763
fn set_tlv < F : FnOnce ( ) -> R , R > ( value : usize , f : F ) -> R {
1756
1764
let old = get_tlv ( ) ;
@@ -1759,6 +1767,7 @@ pub mod tls {
1759
1767
f ( )
1760
1768
}
1761
1769
1770
+ /// This is used to get the pointer to the current ImplicitCtxt.
1762
1771
#[ cfg( not( parallel_queries) ) ]
1763
1772
fn get_tlv ( ) -> usize {
1764
1773
TLV . with ( |tlv| tlv. get ( ) )
@@ -1828,9 +1837,11 @@ pub mod tls {
1828
1837
where F : for < ' a > FnOnce ( TyCtxt < ' a , ' gcx , ' gcx > ) -> R
1829
1838
{
1830
1839
with_thread_locals ( || {
1840
+ // Update GCX_PTR to indicate there's a GlobalCtxt available
1831
1841
GCX_PTR . with ( |lock| {
1832
1842
* lock. lock ( ) = gcx as * const _ as usize ;
1833
1843
} ) ;
1844
+ // Set GCX_PTR back to 0 when we exit
1834
1845
let _on_drop = OnDrop ( move || {
1835
1846
GCX_PTR . with ( |lock| * lock. lock ( ) = 0 ) ;
1836
1847
} ) ;
@@ -1851,8 +1862,13 @@ pub mod tls {
1851
1862
} )
1852
1863
}
1853
1864
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.
1854
1868
scoped_thread_local ! ( pub static GCX_PTR : Lock <usize >) ;
1855
1869
1870
+ /// Creates a TyCtxt and ImplicitCtxt based on the GCX_PTR thread local.
1871
+ /// This is used in the deadlock handler.
1856
1872
pub unsafe fn with_global < F , R > ( f : F ) -> R
1857
1873
where F : for <' a , ' gcx , ' tcx > FnOnce ( TyCtxt < ' a , ' gcx , ' tcx > ) -> R
1858
1874
{
0 commit comments