about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2018-05-31 23:04:21 +0200
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2018-06-06 15:25:19 +0200
commit3e832484414e4b0b28682f9ae6c3607fd5db53f4 (patch)
tree4205619de99a3d0716d6e086b4410fdcc284d7e4
parentb2555bd5456ee12b24777a4eb65dd80fdc788923 (diff)
downloadrust-3e832484414e4b0b28682f9ae6c3607fd5db53f4.tar.gz
rust-3e832484414e4b0b28682f9ae6c3607fd5db53f4.zip
Add comments
-rw-r--r--src/librustc/ty/context.rs18
-rw-r--r--src/librustc/ty/maps/job.rs3
2 files changed, 19 insertions, 2 deletions
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs
index ef584774f69..e66ad242310 100644
--- a/src/librustc/ty/context.rs
+++ b/src/librustc/ty/context.rs
@@ -1737,20 +1737,28 @@ pub mod tls {
         pub task: &'a OpenTask,
     }
 
+    /// Sets Rayon's thread local variable which is preserved for Rayon jobs
+    /// to `value` during the call to `f`. It is restored to its previous value after.
+    /// This is used to set the pointer to the new ImplicitCtxt.
     #[cfg(parallel_queries)]
     fn set_tlv<F: FnOnce() -> R, R>(value: usize, f: F) -> R {
         rayon_core::tlv::with(value, f)
     }
 
+    /// Gets Rayon's thread local variable which is preserved for Rayon jobs.
+    /// This is used to get the pointer to the current ImplicitCtxt.
     #[cfg(parallel_queries)]
     fn get_tlv() -> usize {
         rayon_core::tlv::get()
     }
 
-    // A thread local value which stores a pointer to the current ImplicitCtxt
+    /// A thread local variable which stores a pointer to the current ImplicitCtxt
     #[cfg(not(parallel_queries))]
     thread_local!(static TLV: Cell<usize> = Cell::new(0));
 
+    /// Sets TLV to `value` during the call to `f`.
+    /// It is restored to its previous value after.
+    /// This is used to set the pointer to the new ImplicitCtxt.
     #[cfg(not(parallel_queries))]
     fn set_tlv<F: FnOnce() -> R, R>(value: usize, f: F) -> R {
         let old = get_tlv();
@@ -1759,6 +1767,7 @@ pub mod tls {
         f()
     }
 
+    /// This is used to get the pointer to the current ImplicitCtxt.
     #[cfg(not(parallel_queries))]
     fn get_tlv() -> usize {
         TLV.with(|tlv| tlv.get())
@@ -1828,9 +1837,11 @@ pub mod tls {
         where F: for<'a> FnOnce(TyCtxt<'a, 'gcx, 'gcx>) -> R
     {
         with_thread_locals(|| {
+            // Update GCX_PTR to indicate there's a GlobalCtxt available
             GCX_PTR.with(|lock| {
                 *lock.lock() = gcx as *const _ as usize;
             });
+            // Set GCX_PTR back to 0 when we exit
             let _on_drop = OnDrop(move || {
                 GCX_PTR.with(|lock| *lock.lock() = 0);
             });
@@ -1851,8 +1862,13 @@ pub mod tls {
         })
     }
 
+    /// Stores a pointer to the GlobalCtxt if one is available.
+    /// This is used to access the GlobalCtxt in the deadlock handler
+    /// given to Rayon.
     scoped_thread_local!(pub static GCX_PTR: Lock<usize>);
 
+    /// Creates a TyCtxt and ImplicitCtxt based on the GCX_PTR thread local.
+    /// This is used in the deadlock handler.
     pub unsafe fn with_global<F, R>(f: F) -> R
         where F: for<'a, 'gcx, 'tcx> FnOnce(TyCtxt<'a, 'gcx, 'tcx>) -> R
     {
diff --git a/src/librustc/ty/maps/job.rs b/src/librustc/ty/maps/job.rs
index 1a0347b86ab..e28435489bd 100644
--- a/src/librustc/ty/maps/job.rs
+++ b/src/librustc/ty/maps/job.rs
@@ -61,6 +61,7 @@ pub struct QueryJob<'tcx> {
     /// Diagnostic messages which are emitted while the query executes
     pub diagnostics: Lock<Vec<Diagnostic>>,
 
+    /// The latch which is used to wait on this job
     #[cfg(parallel_queries)]
     latch: QueryLatch<'tcx>,
 }
@@ -200,7 +201,7 @@ impl<'tcx> QueryLatch<'tcx> {
             // this thread.
             info.waiters.push(waiter.clone());
 
-            // If this detects a deadlock and the deadlock handler want to resume this thread
+            // If this detects a deadlock and the deadlock handler wants to resume this thread
             // we have to be in the `wait` call. This is ensured by the deadlock handler
             // getting the self.info lock.
             rayon_core::mark_blocked();