… | |
… | |
551 | usually a better approach for this kind of thing. |
551 | usually a better approach for this kind of thing. |
552 | |
552 | |
553 | Here are the gory details of what C<ev_loop> does: |
553 | Here are the gory details of what C<ev_loop> does: |
554 | |
554 | |
555 | - Before the first iteration, call any pending watchers. |
555 | - Before the first iteration, call any pending watchers. |
556 | * If there are no active watchers (reference count is zero), return. |
556 | * If EVFLAG_FORKCHECK was used, check for a fork. |
557 | - Queue all prepare watchers and then call all outstanding watchers. |
557 | - If a fork was detected, queue and call all fork watchers. |
|
|
558 | - Queue and call all prepare watchers. |
558 | - If we have been forked, recreate the kernel state. |
559 | - If we have been forked, recreate the kernel state. |
559 | - Update the kernel state with all outstanding changes. |
560 | - Update the kernel state with all outstanding changes. |
560 | - Update the "event loop time". |
561 | - Update the "event loop time". |
561 | - Calculate for how long to block. |
562 | - Calculate for how long to sleep or block, if at all |
|
|
563 | (active idle watchers, EVLOOP_NONBLOCK or not having |
|
|
564 | any active watchers at all will result in not sleeping). |
|
|
565 | - Sleep if the I/O and timer collect interval say so. |
562 | - Block the process, waiting for any events. |
566 | - Block the process, waiting for any events. |
563 | - Queue all outstanding I/O (fd) events. |
567 | - Queue all outstanding I/O (fd) events. |
564 | - Update the "event loop time" and do time jump handling. |
568 | - Update the "event loop time" and do time jump handling. |
565 | - Queue all outstanding timers. |
569 | - Queue all outstanding timers. |
566 | - Queue all outstanding periodics. |
570 | - Queue all outstanding periodics. |
567 | - If no events are pending now, queue all idle watchers. |
571 | - If no events are pending now, queue all idle watchers. |
568 | - Queue all check watchers. |
572 | - Queue all check watchers. |
569 | - Call all queued watchers in reverse order (i.e. check watchers first). |
573 | - Call all queued watchers in reverse order (i.e. check watchers first). |
570 | Signals and child watchers are implemented as I/O watchers, and will |
574 | Signals and child watchers are implemented as I/O watchers, and will |
571 | be handled here by queueing them when their watcher gets executed. |
575 | be handled here by queueing them when their watcher gets executed. |
572 | - If ev_unloop has been called or EVLOOP_ONESHOT or EVLOOP_NONBLOCK |
576 | - If ev_unloop has been called, or EVLOOP_ONESHOT or EVLOOP_NONBLOCK |
573 | were used, return, otherwise continue with step *. |
577 | were used, or there are no active watchers, return, otherwise |
|
|
578 | continue with step *. |
574 | |
579 | |
575 | Example: Queue some jobs and then loop until no events are outsanding |
580 | Example: Queue some jobs and then loop until no events are outsanding |
576 | anymore. |
581 | anymore. |
577 | |
582 | |
578 | ... queue jobs here, make sure they register event watchers as long |
583 | ... queue jobs here, make sure they register event watchers as long |