include/fetch/ft_loop.h

filter: Statementstmt 97.2% 143 / 147 Branchbran 63.2% 110 / 174 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 78.8% 253 / 321 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/fetch/ft_ws.h ↑ Summary include/fetch/ft_obs_perl.h »
1 #ifndef FT_LOOP_H
2 #define FT_LOOP_H
3  
4 /* Fetch's minimal event loop: a readiness backend plus per-fd read/write
5 * callbacks and timers, with run_until(future) for re-entrant awaiting. This
6 * supplies the hm_loop_run + hm_cur_loop hook that ft_future.h's await path
7 * calls. Far smaller than Hyperman's server loop - no connections, PSGI, or
8 * idle/timeout sweeps; just IO readiness and timers.
9 *
10 * Must be included AFTER ft_future.h (which forward-declares struct hm_loop,
11 * declares hm_loop_run, and defines the shared hm_cur_loop) and after the
12 * backend .c files. */
13  
14 #include <errno.h>
15  
16 typedef struct ft_timer {
17 SV *cb;
18 int oneshot;
19 UV id; /* the token the backend holds; never reused */
20 double secs; /* as requested, for re-arming an interval */
21 double due; /* monotonic deadline, for re-arming a oneshot */
22 struct ft_timer *next;
23 } ft_timer;
24  
25 /* the monotonic clock the deadline backends already keep */
26 #ifdef _WIN32
27 #define ft_loop_now() hm_sel_now()
28 #else
29 #define ft_loop_now() hm_poll_now()
30 #endif
31  
32 struct hm_loop { /* name matches ft_future.h's forward decl */
33 hm_backend *be; /* NULL between a fork and the child's first need */
34 const char *be_name; /* the backend to rebuild with (a static string) */
35 IV pid; /* the process whose kernel object `be` is */
36 SV **rcb; /* [HM_MAXFD] read-ready callbacks */
37 SV **wcb; /* [HM_MAXFD] write-ready callbacks */
38 ft_timer *timers; /* live timers, for dispatch + cleanup */
39 UV last_timer_id; /* monotonic; see ft_timer_token */
40 int stop;
41 int nio; /* live fd interests, for the idle check */
42 };
43  
44 /* What the backend is given to identify a timer, and gives back when one
45 * fires. It is a counter, not the ft_timer address, because a cancelled timer
46 * can still have an event in flight - queued in the kernel, or already in a
47 * completion ring - and the freed struct is exactly the right size to be
48 * handed straight back to the next ft_add_timer. Then the stale event names a
49 * live timer and takes that down instead: the next request fails on a deadline
50 * that was never its own. A counter is never reused, so the lookup below
51 * simply does not find it and the event is dropped. */
52 #define ft_timer_token(id) INT2PTR(void *, (UV)(id))
53  
54 typedef struct hm_loop ft_loop;
55 /* hm_cur_loop is defined (static) in ft_future.h; we only read/write it. */
56  
57 22 static ft_timer *ft_timer_of_token(ft_loop *l, void *token) {
58 22 UV id = PTR2UV(token);
59 ft_timer *t;
60 67 ▶ for (t = l->timers; t; t = t->next) if (t->id == id) return t;
Branch: 2 branches
BranchTrueFalseTotal
for (t = l->timers; t; t = t->next) if (t->id == id) return t; 22 45 67
for (t = l->timers; t; t = t->next) if (t->id == id) return t; 67 0 67
61 0 return NULL;
62 }
63  
64 43 static ft_loop *ft_loop_new(pTHX_ const char *name) {
65 43 ft_loop *l = (ft_loop *)calloc(1, sizeof(ft_loop));
66 43 ▶ if (!l) croak("Fetch::Loop: out of memory");
Branch: 1 branch
BranchTrueFalseTotal
if (!l) croak("Fetch::Loop: out of memory"); 0 43 43
67 43 ▶ l->be = hm_backend_create(name && *name ? name : NULL);
Branch: 2 branches
BranchTrueFalseTotal
l->be = hm_backend_create(name && *name ? name : NULL); 0 43 43
l->be = hm_backend_create(name && *name ? name : NULL); 0 0 0
68 43 ▶ if (!l->be) { free(l); croak("Fetch::Loop: no event backend available"); }
Branch: 1 branch
BranchTrueFalseTotal
if (!l->be) { free(l); croak("Fetch::Loop: no event backend available"); } 0 43 43
69 43 l->be_name = l->be->name;
70 43 l->pid = (IV)PerlProc_getpid();
71 43 l->rcb = (SV **)calloc(HM_MAXFD, sizeof(SV *));
72 43 l->wcb = (SV **)calloc(HM_MAXFD, sizeof(SV *));
73 43 ▶ if (!l->rcb || !l->wcb) croak("Fetch::Loop: out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!l->rcb || !l->wcb) croak("Fetch::Loop: out of memory"); 43 0 43
if (!l->rcb || !l->wcb) croak("Fetch::Loop: out of memory"); 0 43 43
74 43 return l;
75 }
76  
77 /* A loop inherited across a fork must never reach its backend again.
78 *
79 * The backend's kernel object is SHARED with the parent, not copied. An epoll
80 * instance is one interest list for both processes, so a child "cleaning up"
81 * its inherited watchers deregisters the parent's sockets and the parent
82 * waits on an empty set forever. An io_uring is worse: the submission ring is
83 * shared memory, while liburing's cursors are per-process copies that stop
84 * agreeing the moment the parent submits again. The child's first
85 * io_uring_submit then hands the kernel a wrapped-negative count, the kernel
86 * pushes a full ring of stale entries, and the parent - now equally out of
87 * step - loops on io_uring_enter submitting 1024 dead requests per call
88 * until the machine runs out of memory. That is exactly what a forked test
89 * server did at exit, through global destruction of a Fetch it never used.
90 *
91 * So the first call that finds the pid changed disowns the loop: the
92 * inherited backend is released with `foreign` set (memory only, no
93 * descriptor, no ring) and a fresh one is built only if this process goes
94 * on to need one. A child that merely exits, running DESTROY on the way,
95 * never creates a ring just to tear it down. The watcher and timer tables
96 * are KEPT and mirrored onto the new backend when it is built: they are
97 * the child's copies of live connections, and a parked connection revived
98 * from the pool sends without re-arming, trusting that it is still
99 * READ-armed exactly as it was parked. */
100 #define FT_LOOP_INHERITED(l) ((l)->pid != (IV)PerlProc_getpid())
101  
102 5 static void ft_loop_disown(pTHX_ ft_loop *l) {
103 5 l->pid = (IV)PerlProc_getpid();
104 5 ▶ if (l->be) { l->be->foreign = 1; l->be->destroy(l->be); l->be = NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (l->be) { l->be->foreign = 1; l->be->destroy(l->be); l->be = NULL; } 5 0 5
105 5 }
106  
107 /* Called on every entry that can reach the backend: hands back a backend
108 * this process owns, building one after a fork the first time it is needed.
109 * NULL only when nothing is needed (need == 0) and there is none. */
110 814 static hm_backend *ft_loop_be(pTHX_ ft_loop *l, int need) {
111 814 ▶ if (FT_LOOP_INHERITED(l)) ft_loop_disown(aTHX_ l);
Branch: 1 branch
BranchTrueFalseTotal
if (FT_LOOP_INHERITED(l)) ft_loop_disown(aTHX_ l); 5 809 814
112 814 ▶ if (!l->be && need) {
Branch: 2 branches
BranchTrueFalseTotal
if (!l->be && need) { 5 809 814
if (!l->be && need) { 3 2 5
113 int fd;
114 ft_timer *t;
115 double now;
116 3 l->be = hm_backend_create(l->be_name);
117 3 ▶ if (!l->be) l->be = hm_backend_create(NULL);
Branch: 1 branch
BranchTrueFalseTotal
if (!l->be) l->be = hm_backend_create(NULL); 0 3 3
118 3 ▶ if (!l->be) croak("Fetch::Loop: no event backend available");
Branch: 1 branch
BranchTrueFalseTotal
if (!l->be) croak("Fetch::Loop: no event backend available"); 0 3 3
119 196611 ▶ for (fd = 0; fd < HM_MAXFD; fd++) {
Branch: 1 branch
BranchTrueFalseTotal
for (fd = 0; fd < HM_MAXFD; fd++) { 196608 3 196611
120 196608 ▶ int mask = (l->rcb[fd] ? HM_EV_READ : 0) | (l->wcb[fd] ? HM_EV_WRITE : 0);
Branch: 1 branch
BranchTrueFalseTotal
int mask = (l->rcb[fd] ? HM_EV_READ : 0) | (l->wcb[fd] ? HM_EV_WRITE : 0); 0 196608 196608
121 196608 ▶ if (mask) l->be->add_io(l->be, fd, mask, 0);
Branch: 1 branch
BranchTrueFalseTotal
if (mask) l->be->add_io(l->be, fd, mask, 0); 3 196605 196608
122 }
123 3 now = ft_loop_now();
124 3 ▶ for (t = l->timers; t; t = t->next) {
Branch: 1 branch
BranchTrueFalseTotal
for (t = l->timers; t; t = t->next) { 0 3 3
125 0 ▶ double left = t->oneshot ? t->due - now : t->secs;
Branch: 1 branch
BranchTrueFalseTotal
double left = t->oneshot ? t->due - now : t->secs; 0 0 0
126 0 ▶ if (left < 0) left = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (left < 0) left = 0; 0 0 0
127 0 l->be->add_timer(l->be, left, t->oneshot, ft_timer_token(t->id));
128 }
129 }
130 814 return l->be;
131 }
132  
133 43 static void ft_loop_free(pTHX_ ft_loop *l) {
134 int fd;
135 ft_timer *t;
136 43 ▶ if (!l) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!l) return; 0 43 43
137 43 ▶ if (FT_LOOP_INHERITED(l)) ft_loop_disown(aTHX_ l);
Branch: 1 branch
BranchTrueFalseTotal
if (FT_LOOP_INHERITED(l)) ft_loop_disown(aTHX_ l); 0 43 43
138 43 ▶ if (l->rcb) {
Branch: 1 branch
BranchTrueFalseTotal
if (l->rcb) { 43 0 43
139 2818091 ▶ for (fd = 0; fd < HM_MAXFD; fd++) {
Branch: 1 branch
BranchTrueFalseTotal
for (fd = 0; fd < HM_MAXFD; fd++) { 2818048 43 2818091
140 2818048 SV *cb = l->rcb[fd];
141 2818048 ▶ if (cb) { l->rcb[fd] = NULL; SvREFCNT_dec(cb); }
Branch: 1 branch
BranchTrueFalseTotal
if (cb) { l->rcb[fd] = NULL; SvREFCNT_dec(cb); } 7 2818041 2818048
142 }
143 }
144 43 ▶ if (l->wcb) {
Branch: 1 branch
BranchTrueFalseTotal
if (l->wcb) { 43 0 43
145 2818091 ▶ for (fd = 0; fd < HM_MAXFD; fd++) {
Branch: 1 branch
BranchTrueFalseTotal
for (fd = 0; fd < HM_MAXFD; fd++) { 2818048 43 2818091
146 2818048 SV *cb = l->wcb[fd];
147 2818048 ▶ if (cb) { l->wcb[fd] = NULL; SvREFCNT_dec(cb); }
Branch: 1 branch
BranchTrueFalseTotal
if (cb) { l->wcb[fd] = NULL; SvREFCNT_dec(cb); } 0 2818048 2818048
148 }
149 }
150 43 t = l->timers;
151 43 l->timers = NULL;
152 43 ▶ while (t) { ft_timer *n = t->next; if (t->cb) SvREFCNT_dec(t->cb); free(t); t = n; }
Branch: 2 branches
BranchTrueFalseTotal
while (t) { ft_timer *n = t->next; if (t->cb) SvREFCNT_dec(t->cb); free(t); t = n; } 0 0 0
while (t) { ft_timer *n = t->next; if (t->cb) SvREFCNT_dec(t->cb); free(t); t = n; } 0 43 43
153 43 ▶ if (l->be) l->be->destroy(l->be);
Branch: 1 branch
BranchTrueFalseTotal
if (l->be) l->be->destroy(l->be); 41 2 43
154 43 free(l->rcb);
155 43 free(l->wcb);
156 43 free(l);
157 }
158  
159 /* call $cb->() discarding the result, trapping death into a warning */
160 314 static void ft_call0(pTHX_ SV *cb) {
161 /* Fast path: the loop's own watchers are C closures (hm_closure XSUBs
162 * carrying hm_clos magic) - call the XSUB body directly, skipping
163 * pp_entersub, the eval frame and the Perl stack dance. These callbacks
164 * do not die; any user Perl code they reach (future on_ready callbacks)
165 * is eval-guarded where it runs, in hmf_pump. */
166 314 ▶ if (SvROK(cb)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(cb)) { 314 0 314
167 314 CV *cv = (CV *)SvRV(cb);
168 314 ▶ if (SvTYPE((SV *)cv) == SVt_PVCV && CvISXSUB(cv)
Branch: 2 branches
BranchTrueFalseTotal
if (SvTYPE((SV *)cv) == SVt_PVCV && CvISXSUB(cv) 314 0 314
if (SvTYPE((SV *)cv) == SVt_PVCV && CvISXSUB(cv) 293 21 314
169 293 ▶ && hm_clos_of(aTHX_ cv)) {
Branch: 1 branch
BranchTrueFalseTotal
&& hm_clos_of(aTHX_ cv)) { 293 0 293
170 293 dSP;
171 293 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 293 293
172 293 PUTBACK;
173 293 (CvXSUB(cv))(aTHX_ cv);
174 293 return;
175 }
176 }
177 {
178 21 dSP;
179 21 ▶ ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK;
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK; 0 21 21
180 21 call_sv(cb, G_DISCARD | G_EVAL);
181 17 ▶ if (SvTRUE(ERRSV)) warn("Fetch: loop callback died: %s", SvPV_nolen(ERRSV));
Branch: 3 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) warn("Fetch: loop callback died: %s", SvPV_nolen(ERRSV)); 17 0 17
if (SvTRUE(ERRSV)) warn("Fetch: loop callback died: %s", SvPV_nolen(ERRSV)); 0 17 17
if (SvTRUE(ERRSV)) warn("Fetch: loop callback died: %s", SvPV_nolen(ERRSV)); 0 0 0
182 17 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 0 17 17
183 }
184 }
185  
186 236 static void ft_watch_io(pTHX_ ft_loop *l, int fd, int mask, SV *cb) {
187 236 hm_backend *be = ft_loop_be(aTHX_ l, 1);
188 236 ▶ if (fd < 0 || fd >= HM_MAXFD) croak("watch_io: fd %d out of range", fd);
Branch: 2 branches
BranchTrueFalseTotal
if (fd < 0 || fd >= HM_MAXFD) croak("watch_io: fd %d out of range", fd); 236 0 236
if (fd < 0 || fd >= HM_MAXFD) croak("watch_io: fd %d out of range", fd); 0 236 236
189 236 ▶ if (mask & HM_EV_READ) { if (l->rcb[fd]) SvREFCNT_dec(l->rcb[fd]); else l->nio++; l->rcb[fd] = SvREFCNT_inc(cb); }
Branch: 2 branches
BranchTrueFalseTotal
if (mask & HM_EV_READ) { if (l->rcb[fd]) SvREFCNT_dec(l->rcb[fd]); else l->nio++; l->rcb[fd] = SvREFCNT_inc(cb); } 117 119 236
if (mask & HM_EV_READ) { if (l->rcb[fd]) SvREFCNT_dec(l->rcb[fd]); else l->nio++; l->rcb[fd] = SvREFCNT_inc(cb); } 0 117 117
190 236 ▶ if (mask & HM_EV_WRITE) { if (l->wcb[fd]) SvREFCNT_dec(l->wcb[fd]); else l->nio++; l->wcb[fd] = SvREFCNT_inc(cb); }
Branch: 2 branches
BranchTrueFalseTotal
if (mask & HM_EV_WRITE) { if (l->wcb[fd]) SvREFCNT_dec(l->wcb[fd]); else l->nio++; l->wcb[fd] = SvREFCNT_inc(cb); } 119 117 236
if (mask & HM_EV_WRITE) { if (l->wcb[fd]) SvREFCNT_dec(l->wcb[fd]); else l->nio++; l->wcb[fd] = SvREFCNT_inc(cb); } 0 119 119
191 236 be->add_io(be, fd, mask, 0);
192 236 }
193  
194 229 static void ft_unwatch_io(pTHX_ ft_loop *l, int fd, int mask) {
195 229 hm_backend *be = ft_loop_be(aTHX_ l, 0);
196 229 ▶ if (fd < 0 || fd >= HM_MAXFD) return;
Branch: 2 branches
BranchTrueFalseTotal
if (fd < 0 || fd >= HM_MAXFD) return; 229 0 229
if (fd < 0 || fd >= HM_MAXFD) return; 0 229 229
197 229 ▶ if (mask & HM_EV_READ) { if (l->rcb[fd]) { SvREFCNT_dec(l->rcb[fd]); l->rcb[fd] = NULL; l->nio--; } }
Branch: 2 branches
BranchTrueFalseTotal
if (mask & HM_EV_READ) { if (l->rcb[fd]) { SvREFCNT_dec(l->rcb[fd]); l->rcb[fd] = NULL; l->nio--; } } 110 119 229
if (mask & HM_EV_READ) { if (l->rcb[fd]) { SvREFCNT_dec(l->rcb[fd]); l->rcb[fd] = NULL; l->nio--; } } 110 0 110
198 229 ▶ if (mask & HM_EV_WRITE) { if (l->wcb[fd]) { SvREFCNT_dec(l->wcb[fd]); l->wcb[fd] = NULL; l->nio--; } }
Branch: 2 branches
BranchTrueFalseTotal
if (mask & HM_EV_WRITE) { if (l->wcb[fd]) { SvREFCNT_dec(l->wcb[fd]); l->wcb[fd] = NULL; l->nio--; } } 119 110 229
if (mask & HM_EV_WRITE) { if (l->wcb[fd]) { SvREFCNT_dec(l->wcb[fd]); l->wcb[fd] = NULL; l->nio--; } } 119 0 119
199 229 ▶ if (be) be->remove_io(be, fd, mask);
Branch: 1 branch
BranchTrueFalseTotal
if (be) be->remove_io(be, fd, mask); 227 2 229
200 }
201  
202 38 static ft_timer *ft_add_timer(pTHX_ ft_loop *l, double secs, SV *cb, int oneshot) {
203 38 hm_backend *be = ft_loop_be(aTHX_ l, 1);
204 38 ft_timer *t = (ft_timer *)calloc(1, sizeof(ft_timer));
205 38 ▶ if (!t) croak("Fetch: out of memory");
Branch: 1 branch
BranchTrueFalseTotal
if (!t) croak("Fetch: out of memory"); 0 38 38
206 38 t->cb = SvREFCNT_inc(cb);
207 38 t->oneshot = oneshot ? 1 : 0;
208 38 t->secs = secs;
209 38 t->due = ft_loop_now() + secs;
210 38 t->id = ++l->last_timer_id;
211 38 t->next = l->timers;
212 38 l->timers = t;
213 38 be->add_timer(be, secs, oneshot, ft_timer_token(t->id));
214 38 return t;
215 }
216  
217 38 static void ft_timer_unlink(pTHX_ ft_loop *l, ft_timer *dead) {
218 38 ft_timer **pp = &l->timers;
219 85 ▶ while (*pp) {
Branch: 1 branch
BranchTrueFalseTotal
while (*pp) { 85 0 85
220 85 ▶ if (*pp == dead) {
Branch: 1 branch
BranchTrueFalseTotal
if (*pp == dead) { 38 47 85
221 38 *pp = dead->next;
222 38 ▶ if (dead->cb) SvREFCNT_dec(dead->cb);
Branch: 1 branch
BranchTrueFalseTotal
if (dead->cb) SvREFCNT_dec(dead->cb); 38 0 38
223 38 free(dead);
224 38 return;
225 }
226 47 pp = &(*pp)->next;
227 }
228 }
229  
230 /* Cancel a still-pending timer: drop it from the backend so it never fires,
231 * then unlink+free. (The fire path in hm_loop_run unlinks without del_timer,
232 * since a oneshot the backend has already dropped.) */
233 16 static void ft_del_timer(pTHX_ ft_loop *l, ft_timer *t) {
234 16 hm_backend *be = ft_loop_be(aTHX_ l, 0);
235 ft_timer *p;
236 16 ▶ if (!t) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!t) return; 0 16 16
237 /* Only a timer still linked is ours to read: a connection copied into a
238 * forked child still points at a timer the disown above has freed. */
239 18 ▶ for (p = l->timers; p && p != t; p = p->next) ;
Branch: 2 branches
BranchTrueFalseTotal
for (p = l->timers; p && p != t; p = p->next) ; 18 0 18
for (p = l->timers; p && p != t; p = p->next) ; 2 16 18
240 16 ▶ if (!p) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!p) return; 0 16 16
241 16 ▶ if (be) be->del_timer(be, ft_timer_token(t->id));
Branch: 1 branch
BranchTrueFalseTotal
if (be) be->del_timer(be, ft_timer_token(t->id)); 16 0 16
242 16 ft_timer_unlink(aTHX_ l, t);
243 }
244  
245 /* Pump until `until` (a Fetch::Future SV) resolves, ->stop is set, or forever
246 * when until == NULL. Re-entrant: saves/restores hm_cur_loop and ->stop. */
247 141 static void hm_loop_run(pTHX_ struct hm_loop *l, SV *until) {
248 141 ft_loop *saved = hm_cur_loop;
249 141 int saved_stop = l->stop;
250 141 hm_cur_loop = l;
251 141 l->stop = 0;
252  
253 431 ▶ while (!l->stop) {
Branch: 1 branch
BranchTrueFalseTotal
while (!l->stop) { 295 136 431
254 hm_event evs[HM_MAXEV];
255 hm_backend *be;
256 int n, i;
257  
258 /* Per turn, not per call: a callback may fork, and the child that
259 * carries on from inside it must not pump the parent's backend. */
260 295 be = ft_loop_be(aTHX_ l, 1);
261  
262 295 hmf_pump(aTHX); /* drain future continuations */
263 295 ▶ if (until && hmf_state(aTHX_ until) != HMF_PENDING) break;
Branch: 2 branches
BranchTrueFalseTotal
if (until && hmf_state(aTHX_ until) != HMF_PENDING) break; 288 7 295
if (until && hmf_state(aTHX_ until) != HMF_PENDING) break; 0 288 288
264  
265 /* Nothing armed and nothing timed means nothing can ever wake us:
266 * wait_ev below blocks in the kernel with no deadline, which is not
267 * a stall a Perl-level alarm can even interrupt. Awaiting a future
268 * this loop was never going to resolve is the way to get here, so
269 * say that rather than hanging the process. */
270 295 ▶ if (until && !l->nio && !l->timers) {
Branch: 3 branches
BranchTrueFalseTotal
if (until && !l->nio && !l->timers) { 288 7 295
if (until && !l->nio && !l->timers) { 14 274 288
if (until && !l->nio && !l->timers) { 1 13 14
271 1 l->stop = saved_stop;
272 1 hm_cur_loop = saved;
273 1 croak("Fetch::Future: awaited on a loop with no watchers - the "
274 "future belongs to a different loop");
275 }
276  
277 294 n = be->wait_ev(be, evs, HM_MAXEV, -1.0);
278 294 ▶ if (n < 0) { if (errno == EINTR) continue; break; }
Branch: 2 branches
BranchTrueFalseTotal
if (n < 0) { if (errno == EINTR) continue; break; } 0 294 294
if (n < 0) { if (errno == EINTR) continue; break; } 0 0 0
279  
280 471 ▶ for (i = 0; i < n && !l->stop; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < n && !l->stop; i++) { 314 157 471
for (i = 0; i < n && !l->stop; i++) { 314 0 314
281 314 hm_event *e = &evs[i];
282 314 ▶ if (e->kind & HM_EV_TIMER) {
Branch: 1 branch
BranchTrueFalseTotal
if (e->kind & HM_EV_TIMER) { 22 292 314
283 22 ft_timer *t = ft_timer_of_token(l, e->udata);
284 22 ▶ if (t && t->cb) {
Branch: 2 branches
BranchTrueFalseTotal
if (t && t->cb) { 22 0 22
if (t && t->cb) { 22 0 22
285 22 SV *cb = SvREFCNT_inc(t->cb);
286 22 int one = t->oneshot;
287 22 ▶ if (one) ft_timer_unlink(aTHX_ l, t); /* backend already dropped it */
Branch: 1 branch
BranchTrueFalseTotal
if (one) ft_timer_unlink(aTHX_ l, t); /* backend already dropped it */ 22 0 22
288 22 ft_call0(aTHX_ cb);
289 18 SvREFCNT_dec(cb);
290 }
291 } else {
292 292 ▶ if ((e->kind & HM_EV_READ) && e->fd >= 0 && e->fd < HM_MAXFD && l->rcb[e->fd]) {
Branch: 4 branches
BranchTrueFalseTotal
if ((e->kind & HM_EV_READ) && e->fd >= 0 && e->fd < HM_MAXFD && l->rcb[e->fd]) { 173 119 292
if ((e->kind & HM_EV_READ) && e->fd >= 0 && e->fd < HM_MAXFD && l->rcb[e->fd]) { 173 0 173
if ((e->kind & HM_EV_READ) && e->fd >= 0 && e->fd < HM_MAXFD && l->rcb[e->fd]) { 173 0 173
if ((e->kind & HM_EV_READ) && e->fd >= 0 && e->fd < HM_MAXFD && l->rcb[e->fd]) { 173 0 173
293 173 SV *cb = SvREFCNT_inc(l->rcb[e->fd]);
294 173 ft_call0(aTHX_ cb);
295 173 SvREFCNT_dec(cb);
296 }
297 292 ▶ if ((e->kind & HM_EV_WRITE) && e->fd >= 0 && e->fd < HM_MAXFD && l->wcb[e->fd]) {
Branch: 4 branches
BranchTrueFalseTotal
if ((e->kind & HM_EV_WRITE) && e->fd >= 0 && e->fd < HM_MAXFD && l->wcb[e->fd]) { 119 173 292
if ((e->kind & HM_EV_WRITE) && e->fd >= 0 && e->fd < HM_MAXFD && l->wcb[e->fd]) { 119 0 119
if ((e->kind & HM_EV_WRITE) && e->fd >= 0 && e->fd < HM_MAXFD && l->wcb[e->fd]) { 119 0 119
if ((e->kind & HM_EV_WRITE) && e->fd >= 0 && e->fd < HM_MAXFD && l->wcb[e->fd]) { 119 0 119
298 119 SV *cb = SvREFCNT_inc(l->wcb[e->fd]);
299 119 ft_call0(aTHX_ cb);
300 119 SvREFCNT_dec(cb);
301 }
302 }
303 310 hmf_pump(aTHX);
304 310 ▶ if (until && hmf_state(aTHX_ until) != HMF_PENDING) { l->stop = 1; break; }
Branch: 2 branches
BranchTrueFalseTotal
if (until && hmf_state(aTHX_ until) != HMF_PENDING) { l->stop = 1; break; } 307 3 310
if (until && hmf_state(aTHX_ until) != HMF_PENDING) { l->stop = 1; break; } 133 174 307
305 }
306 }
307  
308 136 l->stop = saved_stop;
309 136 hm_cur_loop = saved;
310 136 }
311  
312 #endif /* FT_LOOP_H */
« include/fetch/ft_ws.h ↑ Summary include/fetch/ft_obs_perl.h »