Skip to content

Commit b562faa

Browse files
committed
more consistently talk about the 'active thread', not the 'current thread'
1 parent 465dcf1 commit b562faa

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

src/tools/miri/src/concurrency/data_race.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ impl VClockAlloc {
859859
| MiriMemoryKind::Mmap,
860860
)
861861
| MemoryKind::Stack => {
862-
let (alloc_index, clocks) = global.current_thread_state(thread_mgr);
862+
let (alloc_index, clocks) = global.active_thread_state(thread_mgr);
863863
let mut alloc_timestamp = clocks.clock[alloc_index];
864864
alloc_timestamp.span = current_span;
865865
(alloc_timestamp, alloc_index)
@@ -932,7 +932,7 @@ impl VClockAlloc {
932932
ptr_dbg: Pointer<AllocId>,
933933
ty: Option<Ty<'_>>,
934934
) -> InterpResult<'tcx> {
935-
let (current_index, current_clocks) = global.current_thread_state(thread_mgr);
935+
let (active_index, active_clocks) = global.active_thread_state(thread_mgr);
936936
let mut other_size = None; // if `Some`, this was a size-mismatch race
937937
let write_clock;
938938
let (other_access, other_thread, other_clock) =
@@ -941,30 +941,30 @@ impl VClockAlloc {
941941
// we are reporting races between two non-atomic reads.
942942
if !access.is_atomic() &&
943943
let Some(atomic) = mem_clocks.atomic() &&
944-
let Some(idx) = Self::find_gt_index(&atomic.write_vector, &current_clocks.clock)
944+
let Some(idx) = Self::find_gt_index(&atomic.write_vector, &active_clocks.clock)
945945
{
946946
(AccessType::AtomicStore, idx, &atomic.write_vector)
947947
} else if !access.is_atomic() &&
948948
let Some(atomic) = mem_clocks.atomic() &&
949-
let Some(idx) = Self::find_gt_index(&atomic.read_vector, &current_clocks.clock)
949+
let Some(idx) = Self::find_gt_index(&atomic.read_vector, &active_clocks.clock)
950950
{
951951
(AccessType::AtomicLoad, idx, &atomic.read_vector)
952952
// Then check races with non-atomic writes/reads.
953-
} else if mem_clocks.write.1 > current_clocks.clock[mem_clocks.write.0] {
953+
} else if mem_clocks.write.1 > active_clocks.clock[mem_clocks.write.0] {
954954
write_clock = mem_clocks.write();
955955
(AccessType::NaWrite(mem_clocks.write_type), mem_clocks.write.0, &write_clock)
956-
} else if let Some(idx) = Self::find_gt_index(&mem_clocks.read, &current_clocks.clock) {
956+
} else if let Some(idx) = Self::find_gt_index(&mem_clocks.read, &active_clocks.clock) {
957957
(AccessType::NaRead(mem_clocks.read[idx].read_type()), idx, &mem_clocks.read)
958958
// Finally, mixed-size races.
959959
} else if access.is_atomic() && let Some(atomic) = mem_clocks.atomic() && atomic.size != access_size {
960960
// This is only a race if we are not synchronized with all atomic accesses, so find
961961
// the one we are not synchronized with.
962962
other_size = Some(atomic.size);
963-
if let Some(idx) = Self::find_gt_index(&atomic.write_vector, &current_clocks.clock)
963+
if let Some(idx) = Self::find_gt_index(&atomic.write_vector, &active_clocks.clock)
964964
{
965965
(AccessType::AtomicStore, idx, &atomic.write_vector)
966966
} else if let Some(idx) =
967-
Self::find_gt_index(&atomic.read_vector, &current_clocks.clock)
967+
Self::find_gt_index(&atomic.read_vector, &active_clocks.clock)
968968
{
969969
(AccessType::AtomicLoad, idx, &atomic.read_vector)
970970
} else {
@@ -977,7 +977,7 @@ impl VClockAlloc {
977977
};
978978

979979
// Load elaborated thread information about the racing thread actions.
980-
let current_thread_info = global.print_thread_metadata(thread_mgr, current_index);
980+
let active_thread_info = global.print_thread_metadata(thread_mgr, active_index);
981981
let other_thread_info = global.print_thread_metadata(thread_mgr, other_thread);
982982
let involves_non_atomic = !access.is_atomic() || !other_access.is_atomic();
983983

@@ -1005,8 +1005,8 @@ impl VClockAlloc {
10051005
},
10061006
op2: RacingOp {
10071007
action: access.description(ty, other_size.map(|_| access_size)),
1008-
thread_info: current_thread_info,
1009-
span: current_clocks.clock.as_slice()[current_index.index()].span_data(),
1008+
thread_info: active_thread_info,
1009+
span: active_clocks.clock.as_slice()[active_index.index()].span_data(),
10101010
},
10111011
}))?
10121012
}
@@ -1028,7 +1028,7 @@ impl VClockAlloc {
10281028
let current_span = machine.current_span();
10291029
let global = machine.data_race.as_ref().unwrap();
10301030
if global.race_detecting() {
1031-
let (index, mut thread_clocks) = global.current_thread_state_mut(&machine.threads);
1031+
let (index, mut thread_clocks) = global.active_thread_state_mut(&machine.threads);
10321032
let mut alloc_ranges = self.alloc_ranges.borrow_mut();
10331033
for (mem_clocks_range, mem_clocks) in
10341034
alloc_ranges.iter_mut(access_range.start, access_range.size)
@@ -1071,7 +1071,7 @@ impl VClockAlloc {
10711071
let current_span = machine.current_span();
10721072
let global = machine.data_race.as_mut().unwrap();
10731073
if global.race_detecting() {
1074-
let (index, mut thread_clocks) = global.current_thread_state_mut(&machine.threads);
1074+
let (index, mut thread_clocks) = global.active_thread_state_mut(&machine.threads);
10751075
for (mem_clocks_range, mem_clocks) in
10761076
self.alloc_ranges.get_mut().iter_mut(access_range.start, access_range.size)
10771077
{
@@ -1520,7 +1520,7 @@ impl GlobalState {
15201520
thread: ThreadId,
15211521
current_span: Span,
15221522
) {
1523-
let current_index = self.current_index(thread_mgr);
1523+
let current_index = self.active_thread_index(thread_mgr);
15241524

15251525
// Enable multi-threaded execution, there are now at least two threads
15261526
// so data-races are now possible.
@@ -1644,7 +1644,7 @@ impl GlobalState {
16441644
/// `thread_joined`.
16451645
#[inline]
16461646
pub fn thread_terminated(&mut self, thread_mgr: &ThreadManager<'_, '_>, current_span: Span) {
1647-
let current_index = self.current_index(thread_mgr);
1647+
let current_index = self.active_thread_index(thread_mgr);
16481648

16491649
// Increment the clock to a unique termination timestamp.
16501650
let vector_clocks = self.vector_clocks.get_mut();
@@ -1682,9 +1682,9 @@ impl GlobalState {
16821682
op: impl FnOnce(VectorIdx, RefMut<'_, ThreadClockSet>) -> InterpResult<'tcx, bool>,
16831683
) -> InterpResult<'tcx> {
16841684
if self.multi_threaded.get() {
1685-
let (index, clocks) = self.current_thread_state_mut(thread_mgr);
1685+
let (index, clocks) = self.active_thread_state_mut(thread_mgr);
16861686
if op(index, clocks)? {
1687-
let (_, mut clocks) = self.current_thread_state_mut(thread_mgr);
1687+
let (_, mut clocks) = self.active_thread_state_mut(thread_mgr);
16881688
clocks.increment_clock(index, current_span);
16891689
}
16901690
}
@@ -1754,7 +1754,7 @@ impl GlobalState {
17541754
/// Load the current vector clock in use and the current set of thread clocks
17551755
/// in use for the vector.
17561756
#[inline]
1757-
pub(super) fn current_thread_state(
1757+
pub(super) fn active_thread_state(
17581758
&self,
17591759
thread_mgr: &ThreadManager<'_, '_>,
17601760
) -> (VectorIdx, Ref<'_, ThreadClockSet>) {
@@ -1764,7 +1764,7 @@ impl GlobalState {
17641764
/// Load the current vector clock in use and the current set of thread clocks
17651765
/// in use for the vector mutably for modification.
17661766
#[inline]
1767-
pub(super) fn current_thread_state_mut(
1767+
pub(super) fn active_thread_state_mut(
17681768
&self,
17691769
thread_mgr: &ThreadManager<'_, '_>,
17701770
) -> (VectorIdx, RefMut<'_, ThreadClockSet>) {
@@ -1774,20 +1774,20 @@ impl GlobalState {
17741774
/// Return the current thread, should be the same
17751775
/// as the data-race active thread.
17761776
#[inline]
1777-
fn current_index(&self, thread_mgr: &ThreadManager<'_, '_>) -> VectorIdx {
1777+
fn active_thread_index(&self, thread_mgr: &ThreadManager<'_, '_>) -> VectorIdx {
17781778
let active_thread_id = thread_mgr.get_active_thread_id();
17791779
self.thread_index(active_thread_id)
17801780
}
17811781

17821782
// SC ATOMIC STORE rule in the paper.
17831783
pub(super) fn sc_write(&self, thread_mgr: &ThreadManager<'_, '_>) {
1784-
let (index, clocks) = self.current_thread_state(thread_mgr);
1784+
let (index, clocks) = self.active_thread_state(thread_mgr);
17851785
self.last_sc_write.borrow_mut().set_at_index(&clocks.clock, index);
17861786
}
17871787

17881788
// SC ATOMIC READ rule in the paper.
17891789
pub(super) fn sc_read(&self, thread_mgr: &ThreadManager<'_, '_>) {
1790-
let (.., mut clocks) = self.current_thread_state_mut(thread_mgr);
1790+
let (.., mut clocks) = self.active_thread_state_mut(thread_mgr);
17911791
clocks.read_seqcst.join(&self.last_sc_fence.borrow());
17921792
}
17931793
}

src/tools/miri/src/concurrency/vector_clock.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const SMALL_VECTOR: usize = 4;
4949
/// a 32-bit unsigned integer which is the actual timestamp, and a `Span`
5050
/// so that diagnostics can report what code was responsible for an operation.
5151
#[derive(Clone, Copy, Debug)]
52-
pub struct VTimestamp {
52+
pub(super) struct VTimestamp {
5353
/// The lowest bit indicates read type, the rest is the time.
5454
/// `1` indicates a retag read, `0` a regular read.
5555
time_and_read_type: u32,
@@ -85,7 +85,7 @@ impl VTimestamp {
8585
}
8686

8787
#[inline]
88-
pub fn read_type(&self) -> NaReadType {
88+
pub(super) fn read_type(&self) -> NaReadType {
8989
if self.time_and_read_type & 1 == 0 { NaReadType::Read } else { NaReadType::Retag }
9090
}
9191

@@ -95,7 +95,7 @@ impl VTimestamp {
9595
}
9696

9797
#[inline]
98-
pub fn span_data(&self) -> SpanData {
98+
pub(super) fn span_data(&self) -> SpanData {
9999
self.span.data()
100100
}
101101
}

src/tools/miri/src/concurrency/weak_memory.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl<'mir, 'tcx: 'mir> StoreBuffer {
270270
) {
271271
let store_elem = self.buffer.back();
272272
if let Some(store_elem) = store_elem {
273-
let (index, clocks) = global.current_thread_state(thread_mgr);
273+
let (index, clocks) = global.active_thread_state(thread_mgr);
274274
store_elem.load_impl(index, &clocks, is_seqcst);
275275
}
276276
}
@@ -289,7 +289,7 @@ impl<'mir, 'tcx: 'mir> StoreBuffer {
289289
let (store_elem, recency) = {
290290
// The `clocks` we got here must be dropped before calling validate_atomic_load
291291
// as the race detector will update it
292-
let (.., clocks) = global.current_thread_state(thread_mgr);
292+
let (.., clocks) = global.active_thread_state(thread_mgr);
293293
// Load from a valid entry in the store buffer
294294
self.fetch_store(is_seqcst, &clocks, &mut *rng)
295295
};
@@ -300,7 +300,7 @@ impl<'mir, 'tcx: 'mir> StoreBuffer {
300300
// requires access to ThreadClockSet.clock, which is updated by the race detector
301301
validate()?;
302302

303-
let (index, clocks) = global.current_thread_state(thread_mgr);
303+
let (index, clocks) = global.active_thread_state(thread_mgr);
304304
let loaded = store_elem.load_impl(index, &clocks, is_seqcst);
305305
Ok((loaded, recency))
306306
}
@@ -312,7 +312,7 @@ impl<'mir, 'tcx: 'mir> StoreBuffer {
312312
thread_mgr: &ThreadManager<'_, '_>,
313313
is_seqcst: bool,
314314
) -> InterpResult<'tcx> {
315-
let (index, clocks) = global.current_thread_state(thread_mgr);
315+
let (index, clocks) = global.active_thread_state(thread_mgr);
316316

317317
self.store_impl(val, index, &clocks.clock, is_seqcst);
318318
Ok(())

0 commit comments

Comments
 (0)