ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.3
(Generate patch)

Comparing libev/ev.3 (file contents):
Revision 1.121 by root, Wed Mar 18 12:21:48 2020 UTC vs.
Revision 1.126 by root, Sat Jun 3 08:53:03 2023 UTC

1.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) 1.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43)
2.\" 2.\"
3.\" Standard preamble: 3.\" Standard preamble:
4.\" ======================================================================== 4.\" ========================================================================
5.de Sp \" Vertical space (when we can't use .PP) 5.de Sp \" Vertical space (when we can't use .PP)
6.if t .sp .5v 6.if t .sp .5v
131.\} 131.\}
132.rm #[ #] #H #V #F C 132.rm #[ #] #H #V #F C
133.\" ======================================================================== 133.\" ========================================================================
134.\" 134.\"
135.IX Title "LIBEV 3" 135.IX Title "LIBEV 3"
136.TH LIBEV 3 "2020-03-12" "libev-4.31" "libev - high performance full featured event loop" 136.TH LIBEV 3 "2023-05-15" "libev-4.33" "libev - high performance full featured event loop"
137.\" For nroff, turn off justification. Always turn off hyphenation; it makes 137.\" For nroff, turn off justification. Always turn off hyphenation; it makes
138.\" way too many mistakes in technical documents. 138.\" way too many mistakes in technical documents.
139.if n .ad l 139.if n .ad l
140.nh 140.nh
141.SH "NAME" 141.SH "NAME"
801and is not embeddable, which would limit the usefulness of this backend 801and is not embeddable, which would limit the usefulness of this backend
802immensely. 802immensely.
803.ie n .IP """EVBACKEND_PORT"" (value 32, Solaris 10)" 4 803.ie n .IP """EVBACKEND_PORT"" (value 32, Solaris 10)" 4
804.el .IP "\f(CWEVBACKEND_PORT\fR (value 32, Solaris 10)" 4 804.el .IP "\f(CWEVBACKEND_PORT\fR (value 32, Solaris 10)" 4
805.IX Item "EVBACKEND_PORT (value 32, Solaris 10)" 805.IX Item "EVBACKEND_PORT (value 32, Solaris 10)"
806This uses the Solaris 10 event port mechanism. As with everything on Solaris, 806This uses the Solaris 10 event port mechanism. As with everything on
807it's really slow, but it still scales very well (O(active_fds)). 807Solaris, it's really slow, but it still scales very well (O(active_fds)).
808.Sp 808.Sp
809While this backend scales well, it requires one system call per active 809While this backend scales well, it requires one system call per active
810file descriptor per loop iteration. For small and medium numbers of file 810file descriptor per loop iteration. For small and medium numbers of file
811descriptors a \*(L"slow\*(R" \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR backend 811descriptors a \*(L"slow\*(R" \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR backend
812might perform better. 812might perform better.
1087\& \- Queue all expired timers. 1087\& \- Queue all expired timers.
1088\& \- Queue all expired periodics. 1088\& \- Queue all expired periodics.
1089\& \- Queue all idle watchers with priority higher than that of pending events. 1089\& \- Queue all idle watchers with priority higher than that of pending events.
1090\& \- Queue all check watchers. 1090\& \- Queue all check watchers.
1091\& \- Call all queued watchers in reverse order (i.e. check watchers first). 1091\& \- Call all queued watchers in reverse order (i.e. check watchers first).
1092\& Signals and child watchers are implemented as I/O watchers, and will 1092\& Signals, async and child watchers are implemented as I/O watchers, and
1093\& be handled here by queueing them when their watcher gets executed. 1093\& will be handled here by queueing them when their watcher gets executed.
1094\& \- If ev_break has been called, or EVRUN_ONCE or EVRUN_NOWAIT 1094\& \- If ev_break has been called, or EVRUN_ONCE or EVRUN_NOWAIT
1095\& were used, or there are no active watchers, goto FINISH, otherwise 1095\& were used, or there are no active watchers, goto FINISH, otherwise
1096\& continue with step LOOP. 1096\& continue with step LOOP.
1097\& FINISH: 1097\& FINISH:
1098\& \- Reset the ev_break status iff it was EVBREAK_ONE. 1098\& \- Reset the ev_break status iff it was EVBREAK_ONE.
1532therefore a good idea to always call its \f(CW\*(C`ev_TYPE_stop\*(C'\fR function. 1532therefore a good idea to always call its \f(CW\*(C`ev_TYPE_stop\*(C'\fR function.
1533.IP "bool ev_is_active (ev_TYPE *watcher)" 4 1533.IP "bool ev_is_active (ev_TYPE *watcher)" 4
1534.IX Item "bool ev_is_active (ev_TYPE *watcher)" 1534.IX Item "bool ev_is_active (ev_TYPE *watcher)"
1535Returns a true value iff the watcher is active (i.e. it has been started 1535Returns a true value iff the watcher is active (i.e. it has been started
1536and not yet been stopped). As long as a watcher is active you must not modify 1536and not yet been stopped). As long as a watcher is active you must not modify
1537it. 1537it unless documented otherwise.
1538.Sp
1539Obviously, it is safe to call this on an active watcher, or actually any
1540watcher that is initialised.
1538.IP "bool ev_is_pending (ev_TYPE *watcher)" 4 1541.IP "bool ev_is_pending (ev_TYPE *watcher)" 4
1539.IX Item "bool ev_is_pending (ev_TYPE *watcher)" 1542.IX Item "bool ev_is_pending (ev_TYPE *watcher)"
1540Returns a true value iff the watcher is pending, (i.e. it has outstanding 1543Returns a true value iff the watcher is pending, (i.e. it has outstanding
1541events but its callback has not yet been invoked). As long as a watcher 1544events but its callback has not yet been invoked). As long as a watcher
1542is pending (but not active) you must not call an init function on it (but 1545is pending (but not active) you must not call an init function on it (but
1543\&\f(CW\*(C`ev_TYPE_set\*(C'\fR is safe), you must not change its priority, and you must 1546\&\f(CW\*(C`ev_TYPE_set\*(C'\fR is safe), you must not change its priority, and you must
1544make sure the watcher is available to libev (e.g. you cannot \f(CW\*(C`free ()\*(C'\fR 1547make sure the watcher is available to libev (e.g. you cannot \f(CW\*(C`free ()\*(C'\fR
1545it). 1548it).
1549.Sp
1550It is safe to call this on any watcher in any state as long as it is
1551initialised.
1546.IP "callback ev_cb (ev_TYPE *watcher)" 4 1552.IP "callback ev_cb (ev_TYPE *watcher)" 4
1547.IX Item "callback ev_cb (ev_TYPE *watcher)" 1553.IX Item "callback ev_cb (ev_TYPE *watcher)"
1548Returns the callback currently set on the watcher. 1554Returns the callback currently set on the watcher.
1549.IP "ev_set_cb (ev_TYPE *watcher, callback)" 4 1555.IP "ev_set_cb (ev_TYPE *watcher, callback)" 4
1550.IX Item "ev_set_cb (ev_TYPE *watcher, callback)" 1556.IX Item "ev_set_cb (ev_TYPE *watcher, callback)"
1563from being executed (except for \f(CW\*(C`ev_idle\*(C'\fR watchers). 1569from being executed (except for \f(CW\*(C`ev_idle\*(C'\fR watchers).
1564.Sp 1570.Sp
1565If you need to suppress invocation when higher priority events are pending 1571If you need to suppress invocation when higher priority events are pending
1566you need to look at \f(CW\*(C`ev_idle\*(C'\fR watchers, which provide this functionality. 1572you need to look at \f(CW\*(C`ev_idle\*(C'\fR watchers, which provide this functionality.
1567.Sp 1573.Sp
1568You \fImust not\fR change the priority of a watcher as long as it is active or 1574You \fImust not\fR change the priority of a watcher as long as it is active
1569pending. 1575or pending. Reading the priority with \f(CW\*(C`ev_priority\*(C'\fR is fine in any state.
1570.Sp 1576.Sp
1571Setting a priority outside the range of \f(CW\*(C`EV_MINPRI\*(C'\fR to \f(CW\*(C`EV_MAXPRI\*(C'\fR is 1577Setting a priority outside the range of \f(CW\*(C`EV_MINPRI\*(C'\fR to \f(CW\*(C`EV_MAXPRI\*(C'\fR is
1572fine, as long as you do not mind that the priority value you query might 1578fine, as long as you do not mind that the priority value you query might
1573or might not have been clamped to the valid range. 1579or might not have been clamped to the valid range.
1574.Sp 1580.Sp
1593callback to be invoked, which can be accomplished with this function. 1599callback to be invoked, which can be accomplished with this function.
1594.IP "ev_feed_event (loop, ev_TYPE *watcher, int revents)" 4 1600.IP "ev_feed_event (loop, ev_TYPE *watcher, int revents)" 4
1595.IX Item "ev_feed_event (loop, ev_TYPE *watcher, int revents)" 1601.IX Item "ev_feed_event (loop, ev_TYPE *watcher, int revents)"
1596Feeds the given event set into the event loop, as if the specified event 1602Feeds the given event set into the event loop, as if the specified event
1597had happened for the specified watcher (which must be a pointer to an 1603had happened for the specified watcher (which must be a pointer to an
1598initialised but not necessarily started event watcher). Obviously you must 1604initialised but not necessarily started event watcher, though it can be
1599not free the watcher as long as it has pending events. 1605active). Obviously you must not free the watcher as long as it has pending
1606events.
1600.Sp 1607.Sp
1601Stopping the watcher, letting libev invoke it, or calling 1608Stopping the watcher, letting libev invoke it, or calling
1602\&\f(CW\*(C`ev_clear_pending\*(C'\fR will clear the pending event, even if the watcher was 1609\&\f(CW\*(C`ev_clear_pending\*(C'\fR will clear the pending event, even if the watcher was
1603not started in the first place. 1610not started in the first place.
1604.Sp 1611.Sp
1625\&\f(CW\*(C`ev_TYPE_init\*(C'\fR again. 1632\&\f(CW\*(C`ev_TYPE_init\*(C'\fR again.
1626.IP "started/running/active" 4 1633.IP "started/running/active" 4
1627.IX Item "started/running/active" 1634.IX Item "started/running/active"
1628Once a watcher has been started with a call to \f(CW\*(C`ev_TYPE_start\*(C'\fR it becomes 1635Once a watcher has been started with a call to \f(CW\*(C`ev_TYPE_start\*(C'\fR it becomes
1629property of the event loop, and is actively waiting for events. While in 1636property of the event loop, and is actively waiting for events. While in
1630this state it cannot be accessed (except in a few documented ways), moved, 1637this state it cannot be accessed (except in a few documented ways, such as
1631freed or anything else \- the only legal thing is to keep a pointer to it, 1638stoping it), moved, freed or anything else \- the only legal thing is to
1632and call libev functions on it that are documented to work on active watchers. 1639keep a pointer to it, and call libev functions on it that are documented
1640to work on active watchers.
1641.Sp
1642As a rule of thumb, before accessing a member or calling any function on
1643a watcher, it should be stopped (or freshly initialised). If that is not
1644convenient, you can check the documentation for that function or member to
1645see if it is safe to use on an active watcher.
1633.IP "pending" 4 1646.IP "pending" 4
1634.IX Item "pending" 1647.IX Item "pending"
1635If a watcher is active and libev determines that an event it is interested 1648If a watcher is active and libev determines that an event it is interested
1636in has occurred (such as a timer expiring), it will become pending. It will 1649in has occurred (such as a timer expiring), it will become pending. It
1637stay in this pending state until either it is stopped or its callback is 1650will stay in this pending state until either it is explicitly stopped or
1638about to be invoked, so it is not normally pending inside the watcher 1651its callback is about to be invoked, so it is not normally pending inside
1639callback. 1652the watcher callback.
1640.Sp 1653.Sp
1641The watcher might or might not be active while it is pending (for example, 1654Generally, the watcher might or might not be active while it is pending
1642an expired non-repeating timer can be pending but no longer active). If it 1655(for example, an expired non-repeating timer can be pending but no longer
1643is stopped, it can be freely accessed (e.g. by calling \f(CW\*(C`ev_TYPE_set\*(C'\fR), 1656active). If it is pending but not active, it can be freely accessed (e.g.
1644but it is still property of the event loop at this time, so cannot be 1657by calling \f(CW\*(C`ev_TYPE_set\*(C'\fR), but it is still property of the event loop at
1645moved, freed or reused. And if it is active the rules described in the 1658this time, so cannot be moved, freed or reused. And if it is active the
1646previous item still apply. 1659rules described in the previous item still apply.
1660.Sp
1661Explicitly stopping a watcher will also clear the pending state
1662unconditionally, so it is safe to stop a watcher and then free it.
1647.Sp 1663.Sp
1648It is also possible to feed an event on a watcher that is not active (e.g. 1664It is also possible to feed an event on a watcher that is not active (e.g.
1649via \f(CW\*(C`ev_feed_event\*(C'\fR), in which case it becomes pending without being 1665via \f(CW\*(C`ev_feed_event\*(C'\fR), in which case it becomes pending without being
1650active. 1666active.
1651.IP "stopped" 4 1667.IP "stopped" 4
4002.PP 4018.PP
4003First, you need to associate some data with the event loop: 4019First, you need to associate some data with the event loop:
4004.PP 4020.PP
4005.Vb 6 4021.Vb 6
4006\& typedef struct { 4022\& typedef struct {
4007\& mutex_t lock; /* global loop lock */ 4023\& pthread_mutex_t lock; /* global loop lock */
4024\& pthread_t tid;
4025\& pthread_cond_t invoke_cv;
4008\& ev_async async_w; 4026\& ev_async async_w;
4009\& thread_t tid;
4010\& cond_t invoke_cv;
4011\& } userdata; 4027\& } userdata;
4012\& 4028\&
4013\& void prepare_loop (EV_P) 4029\& void prepare_loop (EV_P)
4014\& { 4030\& {
4015\& // for simplicity, we use a static userdata struct. 4031\& // for simplicity, we use a static userdata struct.
4016\& static userdata u; 4032\& static userdata u;
4017\& 4033\&
4018\& ev_async_init (&u\->async_w, async_cb); 4034\& ev_async_init (&u.async_w, async_cb);
4019\& ev_async_start (EV_A_ &u\->async_w); 4035\& ev_async_start (EV_A_ &u.async_w);
4020\& 4036\&
4021\& pthread_mutex_init (&u\->lock, 0); 4037\& pthread_mutex_init (&u.lock, 0);
4022\& pthread_cond_init (&u\->invoke_cv, 0); 4038\& pthread_cond_init (&u.invoke_cv, 0);
4023\& 4039\&
4024\& // now associate this with the loop 4040\& // now associate this with the loop
4025\& ev_set_userdata (EV_A_ u); 4041\& ev_set_userdata (EV_A_ &u);
4026\& ev_set_invoke_pending_cb (EV_A_ l_invoke); 4042\& ev_set_invoke_pending_cb (EV_A_ l_invoke);
4027\& ev_set_loop_release_cb (EV_A_ l_release, l_acquire); 4043\& ev_set_loop_release_cb (EV_A_ l_release, l_acquire);
4028\& 4044\&
4029\& // then create the thread running ev_run 4045\& // then create the thread running ev_run
4030\& pthread_create (&u\->tid, 0, l_run, EV_A); 4046\& pthread_create (&u.tid, 0, l_run, EV_A);
4031\& } 4047\& }
4032.Ve 4048.Ve
4033.PP 4049.PP
4034The callback for the \f(CW\*(C`ev_async\*(C'\fR watcher does nothing: the watcher is used 4050The callback for the \f(CW\*(C`ev_async\*(C'\fR watcher does nothing: the watcher is used
4035solely to wake up the event loop so it takes notice of any new watchers 4051solely to wake up the event loop so it takes notice of any new watchers
4421.Sp 4437.Sp
4422For \f(CW\*(C`ev::embed\*(C'\fR watchers this method is called \f(CW\*(C`set_embed\*(C'\fR, to avoid 4438For \f(CW\*(C`ev::embed\*(C'\fR watchers this method is called \f(CW\*(C`set_embed\*(C'\fR, to avoid
4423clashing with the \f(CW\*(C`set (loop)\*(C'\fR method. 4439clashing with the \f(CW\*(C`set (loop)\*(C'\fR method.
4424.Sp 4440.Sp
4425For \f(CW\*(C`ev::io\*(C'\fR watchers there is an additional \f(CW\*(C`set\*(C'\fR method that acepts a 4441For \f(CW\*(C`ev::io\*(C'\fR watchers there is an additional \f(CW\*(C`set\*(C'\fR method that acepts a
4426new event mask only, and internally calls \f(CW\*(C`ev_io_modfify\*(C'\fR. 4442new event mask only, and internally calls \f(CW\*(C`ev_io_modify\*(C'\fR.
4427.IP "w\->start ()" 4 4443.IP "w\->start ()" 4
4428.IX Item "w->start ()" 4444.IX Item "w->start ()"
4429Starts the watcher. Note that there is no \f(CW\*(C`loop\*(C'\fR argument, as the 4445Starts the watcher. Note that there is no \f(CW\*(C`loop\*(C'\fR argument, as the
4430constructor already stores the event loop. 4446constructor already stores the event loop.
4431.IP "w\->start ([arguments])" 4 4447.IP "w\->start ([arguments])" 4

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines