Skip to content

Commit

Permalink
pick more clear names for the types
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Oct 14, 2024
1 parent 9265a6e commit ba95d52
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/tools/miri/src/shims/unix/macos/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use crate::*;

struct LockData {
struct MacOsUnfairLock {
id: MutexId,
}

Expand All @@ -25,11 +25,11 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
// that's just implicitly creating a new lock at the new location.
let (alloc, offset, _) = this.ptr_get_alloc_id(lock.ptr(), 0)?;
let (alloc_extra, machine) = this.get_alloc_extra_mut(alloc)?;
if let Some(data) = alloc_extra.get_sync::<LockData>(offset) {
if let Some(data) = alloc_extra.get_sync::<MacOsUnfairLock>(offset) {
interp_ok(data.id)
} else {
let id = machine.sync.mutex_create();
alloc_extra.sync.insert(offset, Box::new(LockData { id }));
alloc_extra.sync.insert(offset, Box::new(MacOsUnfairLock { id }));
interp_ok(id)
}
}
Expand Down
29 changes: 13 additions & 16 deletions src/tools/miri/src/shims/unix/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ enum MutexKind {
}

#[derive(Debug, Clone, Copy)]
/// Additional data that we attach with each mutex instance.
struct MutexData {
struct PthreadMutex {
id: MutexId,
kind: MutexKind,
}
Expand Down Expand Up @@ -173,10 +172,10 @@ fn mutex_create<'tcx>(
ecx: &mut MiriInterpCx<'tcx>,
mutex_ptr: &OpTy<'tcx>,
kind: MutexKind,
) -> InterpResult<'tcx, MutexData> {
) -> InterpResult<'tcx, PthreadMutex> {
let mutex = ecx.deref_pointer(mutex_ptr)?;
let id = ecx.machine.sync.mutex_create();
let data = MutexData { id, kind };
let data = PthreadMutex { id, kind };
lazy_sync_init(ecx, &mutex, mutex_init_offset(ecx)?, data)?;
interp_ok(data)
}
Expand All @@ -188,12 +187,12 @@ fn mutex_create<'tcx>(
fn mutex_get_data<'tcx, 'a>(
ecx: &'a mut MiriInterpCx<'tcx>,
mutex_ptr: &OpTy<'tcx>,
) -> InterpResult<'tcx, MutexData> {
) -> InterpResult<'tcx, PthreadMutex> {
let mutex = ecx.deref_pointer(mutex_ptr)?;
lazy_sync_get_data(ecx, &mutex, mutex_init_offset(ecx)?, "pthread_mutex_t", |ecx| {
let kind = mutex_kind_from_static_initializer(ecx, &mutex)?;
let id = ecx.machine.sync.mutex_create();
interp_ok(MutexData { id, kind })
interp_ok(PthreadMutex { id, kind })
})
}

Expand Down Expand Up @@ -228,8 +227,7 @@ fn mutex_kind_from_static_initializer<'tcx>(
// - init: u32

#[derive(Debug, Copy, Clone)]
/// Additional data that we attach with each rwlock instance.
struct RwLockData {
struct PthreadRwLock {
id: RwLockId,
}

Expand Down Expand Up @@ -261,7 +259,7 @@ fn rwlock_init_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, Size
fn rwlock_get_data<'tcx>(
ecx: &mut MiriInterpCx<'tcx>,
rwlock_ptr: &OpTy<'tcx>,
) -> InterpResult<'tcx, RwLockData> {
) -> InterpResult<'tcx, PthreadRwLock> {
let rwlock = ecx.deref_pointer(rwlock_ptr)?;
lazy_sync_get_data(ecx, &rwlock, rwlock_init_offset(ecx)?, "pthread_rwlock_t", |ecx| {
if !bytewise_equal_atomic_relaxed(
Expand All @@ -272,7 +270,7 @@ fn rwlock_get_data<'tcx>(
throw_unsup_format!("unsupported static initializer used for `pthread_rwlock_t`");
}
let id = ecx.machine.sync.rwlock_create();
interp_ok(RwLockData { id })
interp_ok(PthreadRwLock { id })
})
}

Expand Down Expand Up @@ -366,8 +364,7 @@ enum ClockId {
}

#[derive(Debug, Copy, Clone)]
/// Additional data that we attach with each cond instance.
struct CondData {
struct PthreadCondvar {
id: CondvarId,
clock: ClockId,
}
Expand All @@ -376,18 +373,18 @@ fn cond_create<'tcx>(
ecx: &mut MiriInterpCx<'tcx>,
cond_ptr: &OpTy<'tcx>,
clock: ClockId,
) -> InterpResult<'tcx, CondData> {
) -> InterpResult<'tcx, PthreadCondvar> {
let cond = ecx.deref_pointer(cond_ptr)?;
let id = ecx.machine.sync.condvar_create();
let data = CondData { id, clock };
let data = PthreadCondvar { id, clock };
lazy_sync_init(ecx, &cond, cond_init_offset(ecx)?, data)?;
interp_ok(data)
}

fn cond_get_data<'tcx>(
ecx: &mut MiriInterpCx<'tcx>,
cond_ptr: &OpTy<'tcx>,
) -> InterpResult<'tcx, CondData> {
) -> InterpResult<'tcx, PthreadCondvar> {
let cond = ecx.deref_pointer(cond_ptr)?;
lazy_sync_get_data(ecx, &cond, cond_init_offset(ecx)?, "pthread_cond_t", |ecx| {
if !bytewise_equal_atomic_relaxed(
Expand All @@ -399,7 +396,7 @@ fn cond_get_data<'tcx>(
}
// This used the static initializer. The clock there is always CLOCK_REALTIME.
let id = ecx.machine.sync.condvar_create();
interp_ok(CondData { id, clock: ClockId::Realtime })
interp_ok(PthreadCondvar { id, clock: ClockId::Realtime })
})
}

Expand Down
6 changes: 3 additions & 3 deletions src/tools/miri/src/shims/windows/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::concurrency::sync::lazy_sync_get_data;
use crate::*;

#[derive(Copy, Clone)]
struct InitOnceData {
struct WindowsInitOnce {
id: InitOnceId,
}

Expand All @@ -19,7 +19,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn init_once_get_data(
&mut self,
init_once_ptr: &OpTy<'tcx>,
) -> InterpResult<'tcx, InitOnceData> {
) -> InterpResult<'tcx, WindowsInitOnce> {
let this = self.eval_context_mut();

let init_once = this.deref_pointer(init_once_ptr)?;
Expand All @@ -28,7 +28,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
lazy_sync_get_data(this, &init_once, init_offset, "INIT_ONCE", |this| {
// TODO: check that this is still all-zero.
let id = this.machine.sync.init_once_create();
interp_ok(InitOnceData { id })
interp_ok(WindowsInitOnce { id })
})
}

Expand Down

0 comments on commit ba95d52

Please sign in to comment.