File Coverage

c/timeable.c
Criterion Covered Total %
statement 34 50 68.0
branch 16 28 57.1
condition n/a
subroutine n/a
pod n/a
total 50 78 64.1


line stmt bran cond sub pod time code
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 0         while (tm->ring.self) {
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 0         warn(" %.2f '%s'\n", tm->at, SvPV(wa->desc, n_a));
15 0           tm = next;
16             }
17 0           }
18              
19 69428           static void pe_timeables_check() {
20 69428           pe_timeable *tm = (pe_timeable*) Timeables.ring.next;
21 69428           NV now = NVtime() + IntervalEpsilon;
22             /*db_show_timeables();/**/
23 71104 100         while (tm->ring.self && now >= tm->at) {
    100          
24 1676           pe_watcher *ev = (pe_watcher*) tm->ring.self;
25 1676           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 1676 50         PE_RING_DETACH(&tm->ring);
35 1676           (*ev->vtbl->alarm)(ev, tm);
36 1676           tm = next;
37             }
38 69428           }
39              
40 68831           static NV timeTillTimer() {
41 68831           pe_timeable *tm = (pe_timeable*) Timeables.ring.next;
42 68831 100         if (!tm->ring.self)
43 129           return 3600;
44 68702           return tm->at - NVtime();
45             }
46              
47 5511           static void pe_timeable_start(pe_timeable *tm) {
48             /* OPTIMIZE! */
49 5511           pe_watcher *ev = (pe_watcher*) tm->ring.self;
50 5511           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 8061016 100         while (rg->ring.self && rg->at < tm->at) {
    100          
62 8055505           rg = (pe_timeable*) rg->ring.next;
63             }
64             /*warn("-- adding 0x%x:\n", ev); db_show_timeables();/**/
65 5511           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 5511           }
74              
75 3929           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 3929 100         PE_RING_DETACH(&tm->ring);
84 3929           }
85              
86 0           static void pe_timeable_adjust(NV delta) {
87 0           pe_timeable *rg = (pe_timeable*) Timeables.ring.next;
88 0 0         while (rg != &Timeables) {
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 50         if (nval) {
96 0 0         if (sv_true(nval)) WaHARD_on(ev); else WaHARD_off(ev);
97             }
98             {
99 1           dSP;
100 1 50         XPUSHs(boolSV(WaHARD(ev)));
    50          
101 1           PUTBACK;
102             }
103 1           }
104              
105 24           static void boot_timeable() {
106 24           PE_RING_INIT(&Timeables.ring, 0);
107 24           }