diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2018-04-13 19:33:31 +0200 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2018-04-16 02:23:55 +0200 |
| commit | fe636373505b610447b952200d91ae2708ce5947 (patch) | |
| tree | 75f45c52082c647fc9f97787d1da89e0972a3126 | |
| parent | 274169090214a37ea17ec21ae6241733de1ff2e9 (diff) | |
| download | rust-fe636373505b610447b952200d91ae2708ce5947.tar.gz rust-fe636373505b610447b952200d91ae2708ce5947.zip | |
Use locks for Session.lint_store and Session.buffered_lints
| -rw-r--r-- | src/librustc/lint/context.rs | 8 | ||||
| -rw-r--r-- | src/librustc/session/mod.rs | 10 |
2 files changed, 9 insertions, 9 deletions
diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 9f8cc2f8699..d5849ea22b1 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -27,6 +27,7 @@ use self::TargetLint::*; use std::slice; +use rustc_data_structures::sync::{RwLock, ReadGuard}; use lint::{EarlyLintPassObject, LateLintPassObject}; use lint::{Level, Lint, LintId, LintPass, LintBuffer}; use lint::builtin::BuiltinLintDiagnostics; @@ -39,7 +40,6 @@ use ty::layout::{LayoutError, LayoutOf, TyLayout}; use util::nodemap::FxHashMap; use std::default::Default as StdDefault; -use std::cell::{Ref, RefCell}; use syntax::ast; use syntax::edition; use syntax_pos::{MultiSpan, Span}; @@ -78,7 +78,7 @@ pub struct LintStore { pub struct LintSession<'a, PassObject> { /// Reference to the store of registered lints. - lints: Ref<'a, LintStore>, + lints: ReadGuard<'a, LintStore>, /// Trait objects for each lint pass. passes: Option<Vec<PassObject>>, @@ -336,7 +336,7 @@ impl<'a, PassObject: LintPassObject> LintSession<'a, PassObject> { /// Creates a new `LintSession`, by moving out the `LintStore`'s initial /// lint levels and pass objects. These can be restored using the `restore` /// method. - fn new(store: &'a RefCell<LintStore>) -> LintSession<'a, PassObject> { + fn new(store: &'a RwLock<LintStore>) -> LintSession<'a, PassObject> { let mut s = store.borrow_mut(); let passes = PassObject::take_passes(&mut *s); drop(s); @@ -347,7 +347,7 @@ impl<'a, PassObject: LintPassObject> LintSession<'a, PassObject> { } /// Restores the levels back to the original lint store. - fn restore(self, store: &RefCell<LintStore>) { + fn restore(self, store: &RwLock<LintStore>) { drop(self.lints); let mut s = store.borrow_mut(); PassObject::restore_passes(&mut *s, self.passes); diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 8f2043fdfc6..77dff0950ee 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -26,7 +26,7 @@ use util::nodemap::{FxHashSet}; use util::common::{duration_to_secs_str, ErrorReported}; use util::common::ProfileQueriesMsg; -use rustc_data_structures::sync::{Lrc, Lock, LockCell, OneThread, Once}; +use rustc_data_structures::sync::{Lrc, Lock, LockCell, OneThread, Once, RwLock}; use syntax::ast::NodeId; use errors::{self, DiagnosticBuilder, DiagnosticId}; @@ -83,8 +83,8 @@ pub struct Session { // FIXME: lint_store and buffered_lints are not thread-safe, // but are only used in a single thread - pub lint_store: OneThread<RefCell<lint::LintStore>>, - pub buffered_lints: OneThread<RefCell<Option<lint::LintBuffer>>>, + pub lint_store: RwLock<lint::LintStore>, + pub buffered_lints: Lock<Option<lint::LintBuffer>>, /// Set of (DiagnosticId, Option<Span>, message) tuples tracking /// (sub)diagnostics that have been set once, but should not be set again, @@ -1091,8 +1091,8 @@ pub fn build_session_( default_sysroot, local_crate_source_file, working_dir, - lint_store: OneThread::new(RefCell::new(lint::LintStore::new())), - buffered_lints: OneThread::new(RefCell::new(Some(lint::LintBuffer::new()))), + lint_store: RwLock::new(lint::LintStore::new()), + buffered_lints: Lock::new(Some(lint::LintBuffer::new())), one_time_diagnostics: RefCell::new(FxHashSet()), plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())), plugin_attributes: OneThread::new(RefCell::new(Vec::new())), |
