Skip to content

Commit 3e83248

Browse files
committed
Add comments
1 parent b2555bd commit 3e83248

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/librustc/ty/context.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -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
{

src/librustc/ty/maps/job.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub struct QueryJob<'tcx> {
6161
/// Diagnostic messages which are emitted while the query executes
6262
pub diagnostics: Lock<Vec<Diagnostic>>,
6363

64+
/// The latch which is used to wait on this job
6465
#[cfg(parallel_queries)]
6566
latch: QueryLatch<'tcx>,
6667
}
@@ -200,7 +201,7 @@ impl<'tcx> QueryLatch<'tcx> {
200201
// this thread.
201202
info.waiters.push(waiter.clone());
202203

203-
// If this detects a deadlock and the deadlock handler want to resume this thread
204+
// If this detects a deadlock and the deadlock handler wants to resume this thread
204205
// we have to be in the `wait` call. This is ensured by the deadlock handler
205206
// getting the self.info lock.
206207
rayon_core::mark_blocked();

0 commit comments

Comments
 (0)