c/watcher.c

filter: Statementstmt 81.7% 215 / 263 Branchbran 54.0% 106 / 196 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 69.9% 321 / 459 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« c/unix.c ↑ Summary c/typemap.c »
1 static int NextID = 0;
2 static pe_ring AllWatchers;
3 static struct pe_watcher_vtbl pe_watcher_base_vtbl;
4  
5 5043 static void pe_watcher_init(pe_watcher *ev, HV *stash, SV *temple) {
6 STRLEN n_a;
7 assert(ev);
8 assert(ev->vtbl);
9 5043 ▶ if (!ev->vtbl->stash)
Branch: 1 branch
BranchTrueFalseTotal
if (!ev->vtbl->stash) 0 5043 5043
10 0 croak("sub-class VTBL must have a stash (doesn't!)");
11 5043 ▶ if (!ev->vtbl->did_require) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ev->vtbl->did_require) { 36 5007 5043
12 SV *tmp;
13 36 ▶ char *name = HvNAME(ev->vtbl->stash);
Branch: 6 branches
BranchTrueFalseTotal
char *name = HvNAME(ev->vtbl->stash); 36 0 36
char *name = HvNAME(ev->vtbl->stash); 36 0 36
char *name = HvNAME(ev->vtbl->stash); 0 36 36
char *name = HvNAME(ev->vtbl->stash); 0 0 0
char *name = HvNAME(ev->vtbl->stash); 36 0 36
char *name = HvNAME(ev->vtbl->stash); 0 36 36
14 dTHX;
15 36 ▶ if (memEQ(name, "Event::", 7))
Branch: 1 branch
BranchTrueFalseTotal
if (memEQ(name, "Event::", 7)) 36 0 36
16 36 name += 7;
17 36 tmp = sv_2mortal(newSVpvf("Event/%s.pm", name));
18 36 perl_require_pv(SvPV(tmp, n_a));
19 36 ▶ if (sv_true(ERRSV))
Branch: 2 branches
BranchTrueFalseTotal
if (sv_true(ERRSV)) 36 0 36
if (sv_true(ERRSV)) 0 36 36
20 0 croak("Event: could not load perl support code for Event::%s: %s",
21 0 ▶ name, SvPV(ERRSV,n_a));
Branch: 1 branch
BranchTrueFalseTotal
name, SvPV(ERRSV,n_a)); 0 0 0
22 36 ++ev->vtbl->did_require;
23 }
24 /* if we have a non-default stash then we need to save it! */
25 5043 ▶ ev->mysv = stash || temple ? wrap_watcher(ev, stash, temple) : 0;
Branch: 2 branches
BranchTrueFalseTotal
ev->mysv = stash || temple ? wrap_watcher(ev, stash, temple) : 0; 0 5043 5043
ev->mysv = stash || temple ? wrap_watcher(ev, stash, temple) : 0; 0 0 0
26 5042 PE_RING_INIT(&ev->all, ev);
27 5042 PE_RING_INIT(&ev->events, 0);
28  
29 /* no exceptions after this point */
30  
31 5042 PE_RING_UNSHIFT(&ev->all, &AllWatchers);
32 5042 WaFLAGS(ev) = 0;
33 5042 WaINVOKE1_on(ev);
34 5042 WaREENTRANT_on(ev);
35 5042 ev->FALLBACK = 0;
36 5042 NextID = (NextID+1) & 0x7fff; /* make it look like the kernel :-, */
37 5042 ev->refcnt = 0;
38 5042 ev->desc = newSVpvn("??",2);
39 5042 ev->running = 0;
40 5042 ev->max_cb_tm = 1; /* make default configurable? */
41 5042 ev->cbtime = 0;
42 5042 ev->prio = PE_QUEUES;
43 5042 ev->callback = 0;
44 5042 ev->ext_data = 0;
45 5042 ev->stats = 0;
46 5042 }
47  
48 5000 static void pe_watcher_cancel_events(pe_watcher *wa) {
49 pe_event *ev;
50 5730 ▶ while (!PE_RING_EMPTY(&wa->events)) {
Branch: 1 branch
BranchTrueFalseTotal
while (!PE_RING_EMPTY(&wa->events)) { 730 5000 5730
51 730 pe_ring *lk = wa->events.prev;
52 730 ev = (pe_event*) lk->self;
53 730 dequeEvent(ev);
54 730 pe_event_release(ev);
55 }
56 5000 }
57  
58 5042 static void pe_watcher_dtor(pe_watcher *wa) {
59 STRLEN n_a;
60 assert(WaCANDESTROY(wa));
61 5042 ▶ if (WaDESTROYED(wa)) {
Branch: 1 branch
BranchTrueFalseTotal
if (WaDESTROYED(wa)) { 0 5042 5042
62 0 warn("Attempt to destroy watcher 0x%x again (ignored)", wa);
63 0 return;
64 }
65 5042 WaDESTROYED_on(wa);
66 if (WaDEBUGx(wa) >= 3)
67 warn("Watcher '%s' destroyed", SvPV(wa->desc, n_a));
68 assert(PE_RING_EMPTY(&wa->events));
69 5042 ▶ if (WaPERLCB(wa))
Branch: 1 branch
BranchTrueFalseTotal
if (WaPERLCB(wa)) 5028 14 5042
70 5028 SvREFCNT_dec(wa->callback);
71 5042 ▶ if (wa->FALLBACK)
Branch: 1 branch
BranchTrueFalseTotal
if (wa->FALLBACK) 0 5042 5042
72 0 SvREFCNT_dec(wa->FALLBACK);
73 5042 ▶ if (wa->desc)
Branch: 1 branch
BranchTrueFalseTotal
if (wa->desc) 5042 0 5042
74 5042 SvREFCNT_dec(wa->desc);
75 5042 ▶ if (wa->stats)
Branch: 1 branch
BranchTrueFalseTotal
if (wa->stats) 0 5042 5042
76 0 Estat.dtor(wa->stats);
77 /* safefree(wa); do it yourself */
78 }
79  
80 /********************************** *******************************/
81  
82 5036 WKEYMETH(_watcher_callback) {
83 5036 ▶ if (nval) {
Branch: 1 branch
BranchTrueFalseTotal
if (nval) { 5033 3 5036
84 AV *av;
85 SV *sv;
86 5033 SV *old=0;
87 5033 ▶ if (WaPERLCB(ev))
Branch: 1 branch
BranchTrueFalseTotal
if (WaPERLCB(ev)) 4 5029 5033
88 4 old = (SV*) ev->callback;
89 5033 ▶ if (!SvOK(nval)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(nval)) { 0 5033 5033
90 0 WaPERLCB_off(ev);
91 0 ev->callback = 0;
92 0 ev->ext_data = 0;
93 0 pe_watcher_stop(ev, 0);
94 5033 ▶ } else if (SvROK(nval) && (SvTYPE(sv=SvRV(nval)) == SVt_PVCV)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (SvROK(nval) && (SvTYPE(sv=SvRV(nval)) == SVt_PVCV)) { 5033 0 5033
} else if (SvROK(nval) && (SvTYPE(sv=SvRV(nval)) == SVt_PVCV)) { 5028 5 5033
95 5028 WaPERLCB_on(ev);
96 5028 ev->callback = SvREFCNT_inc(nval);
97 5 ▶ } else if (SvROK(nval) &&
Branch: 1 branch
BranchTrueFalseTotal
} else if (SvROK(nval) && 5 0 5
98 10 (SvTYPE(av=(AV*)SvRV(nval)) == SVt_PVAV) &&
99 5 av_len(av) == 1) {
100 /* method lookup code adapted from universal.c */
101 STRLEN n_a;
102 4 SV *pkgsv = *av_fetch(av, 0, 0);
103 4 HV *pkg = NULL;
104 4 SV *namesv = *av_fetch(av, 1, 0);
105 4 char *name = SvPV(namesv, n_a);
106 4 int ok=0;
107 4 ▶ if(SvROK(pkgsv)) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvROK(pkgsv)) { 2 2 4
108 2 pkgsv = (SV*)SvRV(pkgsv);
109 2 ▶ if(SvOBJECT(pkgsv))
Branch: 1 branch
BranchTrueFalseTotal
if(SvOBJECT(pkgsv)) 2 0 2
110 2 pkg = SvSTASH(pkgsv);
111 }
112 else {
113 2 pkg = gv_stashsv(pkgsv, FALSE);
114 }
115 4 ▶ if (pkg) {
Branch: 1 branch
BranchTrueFalseTotal
if (pkg) { 4 0 4
116 4 GV *gv = gv_fetchmethod_autoload(pkg, name, FALSE);
117 4 ▶ if (gv && isGV(gv))
Branch: 2 branches
BranchTrueFalseTotal
if (gv && isGV(gv)) 3 1 4
if (gv && isGV(gv)) 3 0 3
118 3 ok=1;
119 }
120 else {
121 0 warn("Event: package '%s' doesn't exist (creating)",
122 SvPV(pkgsv, n_a));
123 0 pkg = gv_stashsv(pkgsv, 1);
124 }
125 4 ▶ if (!ok) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ok) { 1 3 4
126 1 warn("Event: callback method %s->%s doesn't exist",
127 1 ▶ HvNAME(pkg), name);
Branch: 6 branches
BranchTrueFalseTotal
HvNAME(pkg), name); 1 0 1
HvNAME(pkg), name); 1 0 1
HvNAME(pkg), name); 0 1 1
HvNAME(pkg), name); 0 0 0
HvNAME(pkg), name); 1 0 1
HvNAME(pkg), name); 0 1 1
128 }
129 4 WaPERLCB_on(ev);
130 4 ev->callback = SvREFCNT_inc(nval);
131 } else {
132 1 ▶ if (SvIV(DebugLevel) >= 2)
Branch: 1 branch
BranchTrueFalseTotal
if (SvIV(DebugLevel) >= 2) 0 1 1
133 0 sv_dump(sv);
134 1 croak("Callback must be a code ref or [$object, $method_name]");
135 }
136 5032 ▶ if (old)
Branch: 1 branch
BranchTrueFalseTotal
if (old) 4 5028 5032
137 4 SvREFCNT_dec(old);
138 }
139 {
140 10070 SV *ret = (WaPERLCB(ev)?
141 5036 ▶ (SV*) ev->callback :
Branch: 1 branch
BranchTrueFalseTotal
(SV*) ev->callback : 5034 1 5035
142 1 (ev->callback?
143 0 sv_2mortal(newSVpvf("<FPTR=0x%p EXT=0x%p>",
144 1 ▶ ev->callback, ev->ext_data)) :
Branch: 1 branch
BranchTrueFalseTotal
ev->callback, ev->ext_data)) : 0 1 1
145 &PL_sv_undef));
146 5035 dSP;
147 5035 ▶ XPUSHs(ret);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(ret); 0 5035 5035
148 5035 PUTBACK;
149 }
150 5035 }
151  
152 2 WKEYMETH(_watcher_cbtime) {
153 2 ▶ if (!nval) {
Branch: 1 branch
BranchTrueFalseTotal
if (!nval) { 2 0 2
154 2 dSP;
155 2 ▶ XPUSHs(sv_2mortal(newSVnv(ev->cbtime)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVnv(ev->cbtime))); 0 2 2
156 2 PUTBACK;
157 } else
158 0 croak("'e_cbtime' is read-only");
159 2 }
160  
161 5056 WKEYMETH(_watcher_desc) {
162 5056 ▶ if (nval) {
Branch: 1 branch
BranchTrueFalseTotal
if (nval) { 5042 14 5056
163 5042 sv_setsv(ev->desc, nval);
164 }
165 {
166 5056 dSP;
167 5056 ▶ XPUSHs(ev->desc);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(ev->desc); 0 5056 5056
168 5056 PUTBACK;
169 }
170 5056 }
171  
172 1 WKEYMETH(_watcher_debug) {
173 1 ▶ if (nval) {
Branch: 1 branch
BranchTrueFalseTotal
if (nval) { 0 1 1
174 0 ▶ if (sv_true(nval)) WaDEBUG_on(ev); else WaDEBUG_off(ev);
Branch: 1 branch
BranchTrueFalseTotal
if (sv_true(nval)) WaDEBUG_on(ev); else WaDEBUG_off(ev); 0 0 0
175 }
176 {
177 1 dSP;
178 1 ▶ XPUSHs(boolSV(WaDEBUG(ev)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(boolSV(WaDEBUG(ev))); 0 1 1
XPUSHs(boolSV(WaDEBUG(ev))); 0 1 1
179 1 PUTBACK;
180 }
181 1 }
182  
183 10011 WKEYMETH(_watcher_priority) {
184 10011 ▶ if (nval) {
Branch: 1 branch
BranchTrueFalseTotal
if (nval) { 10001 10 10011
185 10001 ev->prio = SvIV(nval);
186 }
187 {
188 10011 dSP;
189 10011 ▶ XPUSHs(sv_2mortal(newSViv(ev->prio)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(ev->prio))); 0 10011 10011
190 10011 PUTBACK;
191 }
192 10011 }
193  
194 2 WKEYMETH(_watcher_reentrant) {
195 2 ▶ if (nval) {
Branch: 1 branch
BranchTrueFalseTotal
if (nval) { 1 1 2
196 1 ▶ if (sv_true(nval))
Branch: 1 branch
BranchTrueFalseTotal
if (sv_true(nval)) 0 1 1
197 0 WaREENTRANT_on(ev);
198 else {
199 1 ▶ if (ev->running > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (ev->running > 1) 0 1 1
200 0 croak("'reentrant' cannot be turned off while nested %d times",
201 ev->running);
202 1 WaREENTRANT_off(ev);
203 }
204 }
205 {
206 2 dSP;
207 2 ▶ XPUSHs(boolSV(WaREENTRANT(ev)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(boolSV(WaREENTRANT(ev))); 0 2 2
XPUSHs(boolSV(WaREENTRANT(ev))); 1 1 2
208 2 PUTBACK;
209 }
210 2 }
211  
212 4961 WKEYMETH(_watcher_repeat) {
213 4961 ▶ if (nval) {
Branch: 1 branch
BranchTrueFalseTotal
if (nval) { 4960 1 4961
214 4960 ▶ if (sv_true(nval)) WaREPEAT_on(ev); else WaREPEAT_off(ev);
Branch: 1 branch
BranchTrueFalseTotal
if (sv_true(nval)) WaREPEAT_on(ev); else WaREPEAT_off(ev); 4958 2 4960
215 }
216 {
217 4961 dSP;
218 4961 ▶ XPUSHs(boolSV(WaREPEAT(ev)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(boolSV(WaREPEAT(ev))); 0 4961 4961
XPUSHs(boolSV(WaREPEAT(ev))); 4958 3 4961
219 4961 PUTBACK;
220 }
221 4961 }
222  
223 0 WKEYMETH(_watcher_suspend) {
224 0 ▶ if (nval) {
Branch: 1 branch
BranchTrueFalseTotal
if (nval) { 0 0 0
225 0 ▶ if (sv_true(nval))
Branch: 1 branch
BranchTrueFalseTotal
if (sv_true(nval)) 0 0 0
226 0 pe_watcher_suspend(ev);
227 else
228 0 pe_watcher_resume(ev);
229 }
230 {
231 0 dSP;
232 0 ▶ XPUSHs(boolSV(WaSUSPEND(ev)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(boolSV(WaSUSPEND(ev))); 0 0 0
XPUSHs(boolSV(WaSUSPEND(ev))); 0 0 0
233 0 PUTBACK;
234 }
235 0 }
236  
237 1 WKEYMETH(_watcher_max_cb_tm) {
238 1 ▶ if (nval) {
Branch: 1 branch
BranchTrueFalseTotal
if (nval) { 0 1 1
239 0 ▶ int tm = SvIOK(nval)? SvIV(nval) : 0;
Branch: 1 branch
BranchTrueFalseTotal
int tm = SvIOK(nval)? SvIV(nval) : 0; 0 0 0
240 0 ▶ if (tm < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (tm < 0) { 0 0 0
241 0 warn("e_max_cb_tm must be non-negative");
242 0 tm=0;
243 }
244 0 ev->max_cb_tm = tm;
245 }
246 {
247 1 dSP;
248 1 ▶ XPUSHs(sv_2mortal(newSViv(ev->max_cb_tm)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(ev->max_cb_tm))); 0 1 1
249 1 PUTBACK;
250 }
251 1 }
252  
253 /********************************** *******************************/
254  
255 0 static void pe_watcher_nomethod(pe_watcher *ev, char *meth) {
256 0 HV *stash = ev->vtbl->stash;
257 assert(stash);
258 0 ▶ croak("%s::%s is missing", HvNAME(stash), meth);
Branch: 6 branches
BranchTrueFalseTotal
croak("%s::%s is missing", HvNAME(stash), meth); 0 0 0
croak("%s::%s is missing", HvNAME(stash), meth); 0 0 0
croak("%s::%s is missing", HvNAME(stash), meth); 0 0 0
croak("%s::%s is missing", HvNAME(stash), meth); 0 0 0
croak("%s::%s is missing", HvNAME(stash), meth); 0 0 0
croak("%s::%s is missing", HvNAME(stash), meth); 0 0 0
259 0 }
260  
261 0 static char *pe_watcher_nostart(pe_watcher *ev, int repeat)
262 0 { pe_watcher_nomethod(ev,"start"); return 0; }
263 0 static void pe_watcher_nostop(pe_watcher *ev)
264 0 { pe_watcher_nomethod(ev,"stop"); }
265 0 static void pe_watcher_alarm(pe_watcher *ev, pe_timeable *tm)
266 0 { pe_watcher_nomethod(ev,"alarm"); }
267  
268 25 static void boot_pe_watcher() {
269 25 HV *stash = gv_stashpv("Event::Watcher", 1);
270 struct pe_watcher_vtbl *vt;
271 25 PE_RING_INIT(&AllWatchers, 0);
272 25 vt = &pe_watcher_base_vtbl;
273 25 vt->stash = 0;
274 25 vt->did_require = 0;
275 25 vt->dtor = 0;
276 25 vt->start = pe_watcher_nostart;
277 25 vt->stop = pe_watcher_nostop;
278 25 vt->alarm = pe_watcher_alarm;
279 25 newCONSTSUB(stash, "ACTIVE", newSViv(PE_ACTIVE));
280 25 newCONSTSUB(stash, "SUSPEND", newSViv(PE_SUSPEND));
281 25 newCONSTSUB(stash, "R", newSViv(PE_R));
282 25 newCONSTSUB(stash, "W", newSViv(PE_W));
283 25 newCONSTSUB(stash, "E", newSViv(PE_E));
284 25 newCONSTSUB(stash, "T", newSViv(PE_T));
285 25 }
286  
287 200 static void pe_register_vtbl(pe_watcher_vtbl *vt, HV *stash,
288 pe_event_vtbl *evt) {
289 200 vt->stash = stash;
290 200 vt->event_vtbl = evt;
291 200 vt->new_event = evt->new_event;
292 200 }
293  
294 16 static void pe_watcher_now(pe_watcher *wa) {
295 pe_event *ev;
296 16 ▶ if (WaSUSPEND(wa)) return;
Branch: 1 branch
BranchTrueFalseTotal
if (WaSUSPEND(wa)) return; 0 16 16
297 16 ▶ if (!wa->callback) {
Branch: 1 branch
BranchTrueFalseTotal
if (!wa->callback) { 1 15 16
298 STRLEN n_a;
299 2 croak("Event: attempt to invoke now() method with callback unset on watcher '%s'", SvPV(wa->desc,n_a));
300 }
301  
302 15 WaRUNNOW_on(wa); /* race condition XXX */
303 15 ev = (*wa->vtbl->new_event)(wa);
304 15 ++ev->hits;
305 15 queueEvent(ev);
306 }
307  
308 /*******************************************************************
309 The following methods change the status flags. This is the only
310 code that should be changing these flags!
311 */
312  
313 5044 static void pe_watcher_cancel(pe_watcher *wa) {
314 5044 ▶ if (WaCANCELLED(wa))
Branch: 1 branch
BranchTrueFalseTotal
if (WaCANCELLED(wa)) 2 5042 5044
315 2 return;
316 5042 WaSUSPEND_off(wa);
317 5042 pe_watcher_stop(wa, 1); /* peer */
318 5042 WaCANCELLED_on(wa);
319 5042 ▶ PE_RING_DETACH(&wa->all);
Branch: 1 branch
BranchTrueFalseTotal
PE_RING_DETACH(&wa->all); 5042 0 5042
320 5042 ▶ if (wa->mysv)
Branch: 1 branch
BranchTrueFalseTotal
if (wa->mysv) 5042 0 5042
321 5042 SvREFCNT_dec(wa->mysv); /* might destroy */
322 0 ▶ else if (WaCANDESTROY(wa))
Branch: 3 branches
BranchTrueFalseTotal
else if (WaCANDESTROY(wa)) 0 0 0
else if (WaCANDESTROY(wa)) 0 0 0
else if (WaCANDESTROY(wa)) 0 0 0
323 0 (*wa->vtbl->dtor)(wa);
324 }
325  
326 2 static void pe_watcher_suspend(pe_watcher *ev) {
327 STRLEN n_a;
328 assert(ev);
329 2 ▶ if (WaSUSPEND(ev))
Branch: 1 branch
BranchTrueFalseTotal
if (WaSUSPEND(ev)) 0 2 2
330 0 return;
331 if (WaDEBUGx(ev) >= 4)
332 warn("Event: suspend '%s'\n", SvPV(ev->desc,n_a));
333 2 pe_watcher_off(ev);
334 2 pe_watcher_cancel_events(ev);
335 2 WaSUSPEND_on(ev); /* must happen nowhere else!! */
336 }
337  
338 2 static void pe_watcher_resume(pe_watcher *ev) {
339 STRLEN n_a;
340 assert(ev);
341 2 ▶ if (!WaSUSPEND(ev))
Branch: 1 branch
BranchTrueFalseTotal
if (!WaSUSPEND(ev)) 0 2 2
342 0 return;
343 2 WaSUSPEND_off(ev);
344 if (WaDEBUGx(ev) >= 4)
345 warn("Event: resume '%s'%s\n", SvPV(ev->desc,n_a),
346 WaACTIVE(ev)?" ACTIVE":"");
347 2 ▶ if (WaACTIVE(ev))
Branch: 1 branch
BranchTrueFalseTotal
if (WaACTIVE(ev)) 2 0 2
348 2 pe_watcher_on(ev, 0);
349 }
350  
351 5089 static char *pe_watcher_on(pe_watcher *wa, int repeat) {
352 STRLEN n_a;
353 char *excuse;
354 5089 ▶ if (WaPOLLING(wa) || WaSUSPEND(wa))
Branch: 2 branches
BranchTrueFalseTotal
if (WaPOLLING(wa) || WaSUSPEND(wa)) 5086 3 5089
if (WaPOLLING(wa) || WaSUSPEND(wa)) 0 5086 5086
355 3 return 0;
356 5086 ▶ if (WaCANCELLED(wa))
Branch: 1 branch
BranchTrueFalseTotal
if (WaCANCELLED(wa)) 1 5085 5086
357 2 croak("Event: attempt to start cancelled watcher '%s'",
358 SvPV(wa->desc,n_a));
359 5085 excuse = (*wa->vtbl->start)(wa, repeat);
360 5085 ▶ if (excuse) {
Branch: 1 branch
BranchTrueFalseTotal
if (excuse) { 8 5077 5085
361 8 ▶ if (SvIV(DebugLevel))
Branch: 1 branch
BranchTrueFalseTotal
if (SvIV(DebugLevel)) 0 8 8
362 0 warn("Event: can't restart '%s' %s", SvPV(wa->desc, n_a), excuse);
363 8 pe_watcher_stop(wa, 1); /* update flags! */
364 } else
365 5077 WaPOLLING_on(wa); /* must happen nowhere else!! */
366 5085 return excuse;
367 }
368  
369 5079 static void pe_watcher_off(pe_watcher *wa) {
370 5079 ▶ if (!WaPOLLING(wa) || WaSUSPEND(wa)) return;
Branch: 2 branches
BranchTrueFalseTotal
if (!WaPOLLING(wa) || WaSUSPEND(wa)) return; 5077 2 5079
if (!WaPOLLING(wa) || WaSUSPEND(wa)) return; 0 5077 5077
371 5077 (*wa->vtbl->stop)(wa);
372 5077 WaPOLLING_off(wa);
373 }
374  
375 5037 static void pe_watcher_start(pe_watcher *ev, int repeat) {
376 char *excuse;
377 STRLEN n_a;
378 5037 ▶ if (WaACTIVE(ev))
Branch: 1 branch
BranchTrueFalseTotal
if (WaACTIVE(ev)) 1 5036 5037
379 1 return;
380 if (WaDEBUGx(ev) >= 4)
381 warn("Event: active ON '%s'\n", SvPV(ev->desc,n_a));
382 5036 excuse = pe_watcher_on(ev, repeat);
383 5035 ▶ if (excuse)
Branch: 1 branch
BranchTrueFalseTotal
if (excuse) 8 5027 5035
384 16 croak("Event: can't start '%s' %s", SvPV(ev->desc,n_a), excuse);
385 5027 WaACTIVE_on(ev); /* must happen nowhere else!! */
386 5027 ++ActiveWatchers;
387 }
388  
389 5085 static void pe_watcher_stop(pe_watcher *ev, int cancel_events) {
390 STRLEN n_a;
391 5085 ▶ if (!WaACTIVE(ev))
Branch: 1 branch
BranchTrueFalseTotal
if (!WaACTIVE(ev)) 58 5027 5085
392 58 return;
393 if (WaDEBUGx(ev) >= 4)
394 warn("Event: active OFF '%s'\n", SvPV(ev->desc,n_a));
395 5027 pe_watcher_off(ev);
396 5027 WaACTIVE_off(ev); /* must happen nowhere else!! */
397 5027 ▶ if (cancel_events) pe_watcher_cancel_events(ev);
Branch: 1 branch
BranchTrueFalseTotal
if (cancel_events) pe_watcher_cancel_events(ev); 4998 29 5027
398 5027 --ActiveWatchers;
399 }
« c/unix.c ↑ Summary c/typemap.c »