Use a simpler atomic operation than the compare_exchange hammer

This commit is contained in:
Oli Scherer 2023-03-15 16:25:28 +00:00
parent 300901b705
commit 54214c8d8d
2 changed files with 9 additions and 3 deletions

View File

@ -107,6 +107,14 @@ cfg_if! {
} }
} }
impl Atomic<bool> {
pub fn fetch_or(&self, val: bool, _: Ordering) -> bool {
let result = self.0.get() | val;
self.0.set(val);
result
}
}
impl<T: Copy + PartialEq> Atomic<T> { impl<T: Copy + PartialEq> Atomic<T> {
#[inline] #[inline]
pub fn compare_exchange(&self, pub fn compare_exchange(&self,

View File

@ -1541,11 +1541,9 @@ pub(crate) fn make_unclosed_delims_error(
} }
pub fn emit_unclosed_delims(unclosed_delims: &mut Vec<UnmatchedDelim>, sess: &ParseSess) { pub fn emit_unclosed_delims(unclosed_delims: &mut Vec<UnmatchedDelim>, sess: &ParseSess) {
let _ = sess.reached_eof.compare_exchange( let _ = sess.reached_eof.fetch_or(
false,
unclosed_delims.iter().any(|unmatched_delim| unmatched_delim.found_delim.is_none()), unclosed_delims.iter().any(|unmatched_delim| unmatched_delim.found_delim.is_none()),
Ordering::Relaxed, Ordering::Relaxed,
Ordering::Relaxed,
); );
for unmatched in unclosed_delims.drain(..) { for unmatched in unclosed_delims.drain(..) {
if let Some(mut e) = make_unclosed_delims_error(unmatched, sess) { if let Some(mut e) = make_unclosed_delims_error(unmatched, sess) {