… | |
… | |
486 | libev watchers. However, a pair of C<ev_prepare>/C<ev_check> watchers is |
486 | libev watchers. However, a pair of C<ev_prepare>/C<ev_check> watchers is |
487 | usually a better approach for this kind of thing. |
487 | usually a better approach for this kind of thing. |
488 | |
488 | |
489 | Here are the gory details of what C<ev_loop> does: |
489 | Here are the gory details of what C<ev_loop> does: |
490 | |
490 | |
|
|
491 | - Before the first iteration, call any pending watchers. |
491 | * If there are no active watchers (reference count is zero), return. |
492 | * If there are no active watchers (reference count is zero), return. |
492 | - Queue prepare watchers and then call all outstanding watchers. |
493 | - Queue all prepare watchers and then call all outstanding watchers. |
493 | - If we have been forked, recreate the kernel state. |
494 | - If we have been forked, recreate the kernel state. |
494 | - Update the kernel state with all outstanding changes. |
495 | - Update the kernel state with all outstanding changes. |
495 | - Update the "event loop time". |
496 | - Update the "event loop time". |
496 | - Calculate for how long to block. |
497 | - Calculate for how long to block. |
497 | - Block the process, waiting for any events. |
498 | - Block the process, waiting for any events. |
… | |
… | |
1481 | with priority higher than or equal to the event loop and one coroutine |
1482 | with priority higher than or equal to the event loop and one coroutine |
1482 | of lower priority, but only once, using idle watchers to keep the event |
1483 | of lower priority, but only once, using idle watchers to keep the event |
1483 | loop from blocking if lower-priority coroutines are active, thus mapping |
1484 | loop from blocking if lower-priority coroutines are active, thus mapping |
1484 | low-priority coroutines to idle/background tasks). |
1485 | low-priority coroutines to idle/background tasks). |
1485 | |
1486 | |
|
|
1487 | It is recommended to give C<ev_check> watchers highest (C<EV_MAXPRI>) |
|
|
1488 | priority, to ensure that they are being run before any other watchers |
|
|
1489 | after the poll. Also, C<ev_check> watchers (and C<ev_prepare> watchers, |
|
|
1490 | too) should not activate ("feed") events into libev. While libev fully |
|
|
1491 | supports this, they will be called before other C<ev_check> watchers did |
|
|
1492 | their job. As C<ev_check> watchers are often used to embed other event |
|
|
1493 | loops those other event loops might be in an unusable state until their |
|
|
1494 | C<ev_check> watcher ran (always remind yourself to coexist peacefully with |
|
|
1495 | others). |
|
|
1496 | |
1486 | =over 4 |
1497 | =over 4 |
1487 | |
1498 | |
1488 | =item ev_prepare_init (ev_prepare *, callback) |
1499 | =item ev_prepare_init (ev_prepare *, callback) |
1489 | |
1500 | |
1490 | =item ev_check_init (ev_check *, callback) |
1501 | =item ev_check_init (ev_check *, callback) |