@@ -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 ( ( ) )
0 commit comments