c/timeable.c

filter: Statementstmt 68.0% 34 / 50 Branchbran 61.5% 16 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 65.7% 50 / 76 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« c/idle.c ↑ Summary c/ev.c »
1 static pe_timeable Timeables;
2  
3 /*#define D_TIMEABLE(x) x /**/
4 #define D_TIMEABLE(x) /**/
5  
6 0 static void db_show_timeables()
7 {
8 0 pe_timeable *tm = (pe_timeable*) Timeables.ring.next;
9 0 warn("timeables at %.2f\n", NVtime() + IntervalEpsilon);
10 0 ▶ while (tm->ring.self) {
Branch: 1 branch
BranchTrueFalseTotal
while (tm->ring.self) { 0 0 0
11 STRLEN n_a;
12 0 pe_watcher *wa = (pe_watcher*) tm->ring.self;
13 0 pe_timeable *next = (pe_timeable*) tm->ring.next;
14 0 warn(" %.2f '%s'\n", tm->at, SvPV(wa->desc, n_a));
15 0 tm = next;
16 }
17 0 }
18  
19 203941 static void pe_timeables_check() {
20 203941 pe_timeable *tm = (pe_timeable*) Timeables.ring.next;
21 203941 NV now = NVtime() + IntervalEpsilon;
22 /*db_show_timeables();/**/
23 205612 ▶ while (tm->ring.self && now >= tm->at) {
Branch: 2 branches
BranchTrueFalseTotal
while (tm->ring.self && now >= tm->at) { 205460 152 205612
while (tm->ring.self && now >= tm->at) { 1671 203789 205460
24 1671 pe_watcher *ev = (pe_watcher*) tm->ring.self;
25 1671 pe_timeable *next = (pe_timeable*) tm->ring.next;
26 D_TIMEABLE({
27 if (WaDEBUGx(ev) >= 4) {
28 STRLEN n_a;
29 warn("Event: timeable expire '%s'\n", SvPV(ev->desc, n_a));
30 }
31 })
32 assert(!WaSUSPEND(ev));
33 assert(WaACTIVE(ev));
34 1671 ▶ PE_RING_DETACH(&tm->ring);
Branch: 1 branch
BranchTrueFalseTotal
PE_RING_DETACH(&tm->ring); 1671 0 1671
35 1671 (*ev->vtbl->alarm)(ev, tm);
36 1671 tm = next;
37 }
38 203941 }
39  
40 203165 static NV timeTillTimer() {
41 203165 pe_timeable *tm = (pe_timeable*) Timeables.ring.next;
42 203165 ▶ if (!tm->ring.self)
Branch: 1 branch
BranchTrueFalseTotal
if (!tm->ring.self) 129 203036 203165
43 129 return 3600;
44 203036 return tm->at - NVtime();
45 }
46  
47 6665 static void pe_timeable_start(pe_timeable *tm) {
48 /* OPTIMIZE! */
49 6665 pe_watcher *ev = (pe_watcher*) tm->ring.self;
50 6665 pe_timeable *rg = (pe_timeable*) Timeables.ring.next;
51 assert(!WaSUSPEND(ev));
52 assert(PE_RING_EMPTY(&tm->ring));
53 if (WaDEBUGx(ev)) {
54 NV left = tm->at - NVtime();
55 if (left < 0) {
56 STRLEN n_a;
57 warn("Event: timer for '%s' set to expire immediately (%.2f)",
58 SvPV(ev->desc, n_a), left);
59 }
60 }
61 11982221 ▶ while (rg->ring.self && rg->at < tm->at) {
Branch: 2 branches
BranchTrueFalseTotal
while (rg->ring.self && rg->at < tm->at) { 11981361 860 11982221
while (rg->ring.self && rg->at < tm->at) { 11975556 5805 11981361
62 11975556 rg = (pe_timeable*) rg->ring.next;
63 }
64 /*warn("-- adding 0x%x:\n", ev); db_show_timeables();/**/
65 6665 PE_RING_ADD_BEFORE(&tm->ring, &rg->ring);
66 /*warn("T:\n"); db_show_timeables();/**/
67 D_TIMEABLE({
68 if (WaDEBUGx(ev) >= 4) {
69 STRLEN n_a;
70 warn("Event: timeable start '%s'\n", SvPV(ev->desc, n_a));
71 }
72 })
73 6665 }
74  
75 5088 static void pe_timeable_stop(pe_timeable *tm) {
76 D_TIMEABLE({
77 pe_watcher *ev = (pe_watcher*) tm->ring.self;
78 if (WaDEBUGx(ev) >= 4) {
79 STRLEN n_a;
80 warn("Event: timeable stop '%s'\n", SvPV(ev->desc, n_a));
81 }
82 })
83 5088 ▶ PE_RING_DETACH(&tm->ring);
Branch: 1 branch
BranchTrueFalseTotal
PE_RING_DETACH(&tm->ring); 4994 94 5088
84 5088 }
85  
86 0 static void pe_timeable_adjust(NV delta) {
87 0 pe_timeable *rg = (pe_timeable*) Timeables.ring.next;
88 0 ▶ while (rg != &Timeables) {
Branch: 1 branch
BranchTrueFalseTotal
while (rg != &Timeables) { 0 0 0
89 0 rg->at += delta;
90 0 rg = (pe_timeable*) rg->ring.next;
91 }
92 0 }
93  
94 1 WKEYMETH(_timeable_hard) { /* applies to all timers in a watcher; is ok? */
95 1 ▶ if (nval) {
Branch: 1 branch
BranchTrueFalseTotal
if (nval) { 0 1 1
96 0 ▶ if (sv_true(nval)) WaHARD_on(ev); else WaHARD_off(ev);
Branch: 1 branch
BranchTrueFalseTotal
if (sv_true(nval)) WaHARD_on(ev); else WaHARD_off(ev); 0 0 0
97 }
98 {
99 1 dSP;
100 1 ▶ XPUSHs(boolSV(WaHARD(ev)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(boolSV(WaHARD(ev))); 0 1 1
XPUSHs(boolSV(WaHARD(ev))); 0 1 1
101 1 PUTBACK;
102 }
103 1 }
104  
105 25 static void boot_timeable() {
106 25 PE_RING_INIT(&Timeables.ring, 0);
107 25 }
« c/idle.c ↑ Summary c/ev.c »