@@ -211,10 +211,10 @@ fn eventfd_write<'tcx>(
211
211
eventfd. clock . borrow_mut ( ) . join ( clock) ;
212
212
} ) ;
213
213
214
- // When this function is called, the addition is guaranteed to not exceed u64::MAX - 1 .
214
+ // Store new counter value .
215
215
eventfd. counter . set ( new_count) ;
216
216
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
218
218
// types for current file description.
219
219
ecx. check_and_update_readiness ( & eventfd_ref) ?;
220
220
@@ -228,10 +228,11 @@ fn eventfd_write<'tcx>(
228
228
ecx. unblock_thread ( thread_id, BlockReason :: Eventfd ) ?;
229
229
}
230
230
231
- // Return how many bytes we wrote .
231
+ // Return how many bytes we consumed from the user-provided buffer .
232
232
return ecx. write_int ( buf_place. layout . size . bytes ( ) , dest) ;
233
233
}
234
234
None | Some ( u64:: MAX ) => {
235
+ // We can't update the state, so we have to block.
235
236
if eventfd. is_nonblock {
236
237
return ecx. set_last_error_and_return ( ErrorKind :: WouldBlock , dest) ;
237
238
}
@@ -251,6 +252,7 @@ fn eventfd_write<'tcx>(
251
252
weak_eventfd: WeakFileDescriptionRef ,
252
253
}
253
254
@unblock = |this| {
255
+ // When we get unblocked, try again.
254
256
eventfd_write( num, buf_place, & dest, weak_eventfd, this)
255
257
}
256
258
) ,
@@ -276,9 +278,10 @@ fn eventfd_read<'tcx>(
276
278
// an eventfd file description.
277
279
let eventfd = eventfd_ref. downcast :: < Event > ( ) . unwrap ( ) ;
278
280
279
- // Block when counter == 0 .
281
+ // Set counter to 0, get old value .
280
282
let counter = eventfd. counter . replace ( 0 ) ;
281
283
284
+ // Block when counter == 0.
282
285
if counter == 0 {
283
286
if eventfd. is_nonblock {
284
287
return ecx. set_last_error_and_return ( ErrorKind :: WouldBlock , dest) ;
@@ -297,6 +300,7 @@ fn eventfd_read<'tcx>(
297
300
weak_eventfd: WeakFileDescriptionRef ,
298
301
}
299
302
@unblock = |this| {
303
+ // When we get unblocked, try again.
300
304
eventfd_read( buf_place, & dest, weak_eventfd, this)
301
305
}
302
306
) ,
@@ -305,10 +309,10 @@ fn eventfd_read<'tcx>(
305
309
// Synchronize with all prior `write` calls to this FD.
306
310
ecx. acquire_clock ( & eventfd. clock . borrow ( ) ) ;
307
311
308
- // Give old counter value to userspace, and set counter value to 0 .
312
+ // Return old counter value into user-space buffer .
309
313
ecx. write_int ( counter, & buf_place) ?;
310
314
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
312
316
// types for current file description.
313
317
ecx. check_and_update_readiness ( & eventfd_ref) ?;
314
318
@@ -322,7 +326,7 @@ fn eventfd_read<'tcx>(
322
326
ecx. unblock_thread ( thread_id, BlockReason :: Eventfd ) ?;
323
327
}
324
328
325
- // Tell userspace how many bytes we read .
329
+ // Tell userspace how many bytes we put into the buffer .
326
330
return ecx. write_int ( buf_place. layout . size . bytes ( ) , dest) ;
327
331
}
328
332
interp_ok ( ( ) )
0 commit comments