Skip to content

Commit fa93f35

Browse files
authored
Merge pull request rust-lang#4047 from RalfJung/eventfd-comments
eventfd: comment tweaks
2 parents 76f27aa + 33f4d2e commit fa93f35

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/tools/miri/src/shims/unix/linux/epoll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
539539
)?;
540540
if is_updated {
541541
// Edge-triggered notification only notify one thread even if there are
542-
// multiple threads block on the same epfd.
542+
// multiple threads blocked on the same epfd.
543543

544544
// This unwrap can never fail because if the current epoll instance were
545545
// closed, the upgrade of weak_epoll_interest

src/tools/miri/src/shims/unix/linux/eventfd.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ fn eventfd_write<'tcx>(
211211
eventfd.clock.borrow_mut().join(clock);
212212
});
213213

214-
// When this function is called, the addition is guaranteed to not exceed u64::MAX - 1.
214+
// Store new counter value.
215215
eventfd.counter.set(new_count);
216216

217-
// When any of the event happened, we check and update the status of all supported event
217+
// The state changed; we check and update the status of all supported event
218218
// types for current file description.
219219
ecx.check_and_update_readiness(&eventfd_ref)?;
220220

@@ -228,10 +228,11 @@ fn eventfd_write<'tcx>(
228228
ecx.unblock_thread(thread_id, BlockReason::Eventfd)?;
229229
}
230230

231-
// Return how many bytes we wrote.
231+
// Return how many bytes we consumed from the user-provided buffer.
232232
return ecx.write_int(buf_place.layout.size.bytes(), dest);
233233
}
234234
None | Some(u64::MAX) => {
235+
// We can't update the state, so we have to block.
235236
if eventfd.is_nonblock {
236237
return ecx.set_last_error_and_return(ErrorKind::WouldBlock, dest);
237238
}
@@ -251,6 +252,7 @@ fn eventfd_write<'tcx>(
251252
weak_eventfd: WeakFileDescriptionRef,
252253
}
253254
@unblock = |this| {
255+
// When we get unblocked, try again.
254256
eventfd_write(num, buf_place, &dest, weak_eventfd, this)
255257
}
256258
),
@@ -276,9 +278,10 @@ fn eventfd_read<'tcx>(
276278
// an eventfd file description.
277279
let eventfd = eventfd_ref.downcast::<Event>().unwrap();
278280

279-
// Block when counter == 0.
281+
// Set counter to 0, get old value.
280282
let counter = eventfd.counter.replace(0);
281283

284+
// Block when counter == 0.
282285
if counter == 0 {
283286
if eventfd.is_nonblock {
284287
return ecx.set_last_error_and_return(ErrorKind::WouldBlock, dest);
@@ -297,6 +300,7 @@ fn eventfd_read<'tcx>(
297300
weak_eventfd: WeakFileDescriptionRef,
298301
}
299302
@unblock = |this| {
303+
// When we get unblocked, try again.
300304
eventfd_read(buf_place, &dest, weak_eventfd, this)
301305
}
302306
),
@@ -305,10 +309,10 @@ fn eventfd_read<'tcx>(
305309
// Synchronize with all prior `write` calls to this FD.
306310
ecx.acquire_clock(&eventfd.clock.borrow());
307311

308-
// Give old counter value to userspace, and set counter value to 0.
312+
// Return old counter value into user-space buffer.
309313
ecx.write_int(counter, &buf_place)?;
310314

311-
// When any of the events happened, we check and update the status of all supported event
315+
// The state changed; we check and update the status of all supported event
312316
// types for current file description.
313317
ecx.check_and_update_readiness(&eventfd_ref)?;
314318

@@ -322,7 +326,7 @@ fn eventfd_read<'tcx>(
322326
ecx.unblock_thread(thread_id, BlockReason::Eventfd)?;
323327
}
324328

325-
// Tell userspace how many bytes we read.
329+
// Tell userspace how many bytes we put into the buffer.
326330
return ecx.write_int(buf_place.layout.size.bytes(), dest);
327331
}
328332
interp_ok(())

src/tools/miri/tests/fail-dep/libc/eventfd_block_read_twice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::thread;
1414
// 2. Thread 2 blocks.
1515
// 3. Thread 3 unblocks both thread 1 and thread 2.
1616
// 4. Thread 1 reads.
17-
// 5. Thread 2's `read` deadlocked.
17+
// 5. Thread 2's `read` can never complete -> deadlocked.
1818

1919
fn main() {
2020
// eventfd write will block when EFD_NONBLOCK flag is clear

src/tools/miri/tests/fail-dep/libc/eventfd_block_write_twice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::thread;
1414
// 2. Thread 2 blocks.
1515
// 3. Thread 3 unblocks both thread 1 and thread 2.
1616
// 4. Thread 1 writes u64::MAX.
17-
// 5. Thread 2's `write` deadlocked.
17+
// 5. Thread 2's `write` can never complete -> deadlocked.
1818
fn main() {
1919
// eventfd write will block when EFD_NONBLOCK flag is clear
2020
// and the addition caused counter to exceed u64::MAX - 1.

0 commit comments

Comments
 (0)