… | |
… | |
634 | libev watchers. However, a pair of \f(CW\*(C`ev_prepare\*(C'\fR/\f(CW\*(C`ev_check\*(C'\fR watchers is |
634 | libev watchers. However, a pair of \f(CW\*(C`ev_prepare\*(C'\fR/\f(CW\*(C`ev_check\*(C'\fR watchers is |
635 | usually a better approach for this kind of thing. |
635 | usually a better approach for this kind of thing. |
636 | .Sp |
636 | .Sp |
637 | Here are the gory details of what \f(CW\*(C`ev_loop\*(C'\fR does: |
637 | Here are the gory details of what \f(CW\*(C`ev_loop\*(C'\fR does: |
638 | .Sp |
638 | .Sp |
639 | .Vb 18 |
639 | .Vb 19 |
|
|
640 | \& - Before the first iteration, call any pending watchers. |
640 | \& * If there are no active watchers (reference count is zero), return. |
641 | \& * If there are no active watchers (reference count is zero), return. |
641 | \& - Queue prepare watchers and then call all outstanding watchers. |
642 | \& - Queue all prepare watchers and then call all outstanding watchers. |
642 | \& - If we have been forked, recreate the kernel state. |
643 | \& - If we have been forked, recreate the kernel state. |
643 | \& - Update the kernel state with all outstanding changes. |
644 | \& - Update the kernel state with all outstanding changes. |
644 | \& - Update the "event loop time". |
645 | \& - Update the "event loop time". |
645 | \& - Calculate for how long to block. |
646 | \& - Calculate for how long to block. |
646 | \& - Block the process, waiting for any events. |
647 | \& - Block the process, waiting for any events. |
… | |
… | |
1634 | are ready to run (it's actually more complicated: it only runs coroutines |
1635 | are ready to run (it's actually more complicated: it only runs coroutines |
1635 | with priority higher than or equal to the event loop and one coroutine |
1636 | with priority higher than or equal to the event loop and one coroutine |
1636 | of lower priority, but only once, using idle watchers to keep the event |
1637 | of lower priority, but only once, using idle watchers to keep the event |
1637 | loop from blocking if lower-priority coroutines are active, thus mapping |
1638 | loop from blocking if lower-priority coroutines are active, thus mapping |
1638 | low-priority coroutines to idle/background tasks). |
1639 | low-priority coroutines to idle/background tasks). |
|
|
1640 | .PP |
|
|
1641 | It is recommended to give \f(CW\*(C`ev_check\*(C'\fR watchers highest (\f(CW\*(C`EV_MAXPRI\*(C'\fR) |
|
|
1642 | priority, to ensure that they are being run before any other watchers |
|
|
1643 | after the poll. Also, \f(CW\*(C`ev_check\*(C'\fR watchers (and \f(CW\*(C`ev_prepare\*(C'\fR watchers, |
|
|
1644 | too) should not activate (\*(L"feed\*(R") events into libev. While libev fully |
|
|
1645 | supports this, they will be called before other \f(CW\*(C`ev_check\*(C'\fR watchers did |
|
|
1646 | their job. As \f(CW\*(C`ev_check\*(C'\fR watchers are often used to embed other event |
|
|
1647 | loops those other event loops might be in an unusable state until their |
|
|
1648 | \&\f(CW\*(C`ev_check\*(C'\fR watcher ran (always remind yourself to coexist peacefully with |
|
|
1649 | others). |
1639 | .IP "ev_prepare_init (ev_prepare *, callback)" 4 |
1650 | .IP "ev_prepare_init (ev_prepare *, callback)" 4 |
1640 | .IX Item "ev_prepare_init (ev_prepare *, callback)" |
1651 | .IX Item "ev_prepare_init (ev_prepare *, callback)" |
1641 | .PD 0 |
1652 | .PD 0 |
1642 | .IP "ev_check_init (ev_check *, callback)" 4 |
1653 | .IP "ev_check_init (ev_check *, callback)" 4 |
1643 | .IX Item "ev_check_init (ev_check *, callback)" |
1654 | .IX Item "ev_check_init (ev_check *, callback)" |