Skip to content

Commit 9ba3ef2

Browse files
author
Vytautas Astrauskas
committed
Change representation and conversion of ThreadId and BlockSetId.
1 parent 174adad commit 9ba3ef2

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/shims/sync.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ fn mutex_get_or_create_blockset<'mir, 'tcx: 'mir>(
158158
mutex_set_blockset(ecx, mutex_op, blockset.to_u32_scalar())?;
159159
Ok(blockset)
160160
} else {
161-
Ok(blockset.into())
161+
Ok(BlockSetId::new(blockset))
162162
}
163163
}
164164

@@ -233,7 +233,7 @@ fn rwlock_get_or_create_writer_blockset<'mir, 'tcx: 'mir>(
233233
rwlock_set_writer_blockset(ecx, rwlock_op, blockset.to_u32_scalar())?;
234234
Ok(blockset)
235235
} else {
236-
Ok(blockset.into())
236+
Ok(BlockSetId::new(blockset))
237237
}
238238
}
239239

@@ -264,7 +264,7 @@ fn rwlock_get_or_create_reader_blockset<'mir, 'tcx: 'mir>(
264264
rwlock_set_reader_blockset(ecx, rwlock_op, blockset.to_u32_scalar())?;
265265
Ok(blockset)
266266
} else {
267-
Ok(blockset.into())
267+
Ok(BlockSetId::new(blockset))
268268
}
269269
}
270270

src/thread.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub enum SchedulingAction {
3030

3131
/// A thread identifier.
3232
#[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)]
33-
pub struct ThreadId(usize);
33+
pub struct ThreadId(u32);
3434

3535
/// The main thread. When it terminates, the whole application terminates.
3636
const MAIN_THREAD: ThreadId = ThreadId(0);
@@ -43,22 +43,22 @@ impl ThreadId {
4343

4444
impl Idx for ThreadId {
4545
fn new(idx: usize) -> Self {
46-
ThreadId(idx)
46+
ThreadId(u32::try_from(idx).unwrap())
4747
}
4848
fn index(self) -> usize {
49-
self.0
49+
usize::try_from(self.0).unwrap()
5050
}
5151
}
5252

5353
impl From<u64> for ThreadId {
5454
fn from(id: u64) -> Self {
55-
Self(usize::try_from(id).unwrap())
55+
Self(u32::try_from(id).unwrap())
5656
}
5757
}
5858

5959
impl From<u32> for ThreadId {
6060
fn from(id: u32) -> Self {
61-
Self(usize::try_from(id).unwrap())
61+
Self(u32::try_from(id).unwrap())
6262
}
6363
}
6464

@@ -73,13 +73,11 @@ impl ThreadId {
7373
#[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)]
7474
pub struct BlockSetId(NonZeroU32);
7575

76-
impl From<u32> for BlockSetId {
77-
fn from(id: u32) -> Self {
76+
impl BlockSetId {
77+
/// Panics if `id` is 0.
78+
pub fn new(id: u32) -> Self {
7879
Self(NonZeroU32::new(id).expect("0 is not a valid blockset id"))
7980
}
80-
}
81-
82-
impl BlockSetId {
8381
pub fn to_u32_scalar<'tcx>(&self) -> Scalar<Tag> {
8482
Scalar::from_u32(self.0.get())
8583
}
@@ -325,7 +323,7 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
325323
/// Allocate a new blockset id.
326324
fn create_blockset(&mut self) -> BlockSetId {
327325
self.blockset_counter = self.blockset_counter.checked_add(1).unwrap();
328-
self.blockset_counter.into()
326+
BlockSetId::new(self.blockset_counter)
329327
}
330328

331329
/// Block the currently active thread and put it into the given blockset.

0 commit comments

Comments
 (0)