| 1 |
|
| #ifndef DBIL_VT_H |
| 2 |
|
| #define DBIL_VT_H |
| 3 |
|
| |
| 4 |
|
| /* An RV to the bind list, for a bind AV that may be absent. newRV_inc on a |
| 5 |
|
| * freshly made AV would leave it at two references and leak it, so the two |
| 6 |
|
| * cases need different constructors. */ |
| 7 |
693 |
| static SV *dbil_bind_rv(pTHX_ AV *bind) { |
| 8 |
693 |
▶ | return bind ? newRV_inc((SV *)bind) : newRV_noinc((SV *)newAV()); |
Branch: 1 branch
| Branch | True | False | Total |
| return bind ? newRV_inc((SV *)bind) : newRV_noinc((SV *)newAV()); |
688 |
5 |
693 |
|
| 9 |
|
| } |
| 10 |
|
| |
| 11 |
|
| /* The pure-C loop seam. A loop adapter that can dispatch entirely in C (the |
| 12 |
|
| * Hyperman adapter, via Hyperman's hm_abi table) stores a dbil_vt pointer in |
| 13 |
|
| * its "_vt" hash slot; backends check dbil_vt_of() and, when present, call |
| 14 |
|
| * these instead of the Perl seam methods (add_reader/add_writer/remove/...). |
| 15 |
|
| * Readiness then reaches the backend with no Perl call frame. Nothing |
| 16 |
|
| * loop-specific appears here - backends see dbil_vt, never hm_abi. */ |
| 17 |
|
| |
| 18 |
|
| typedef void (*dbil_io_fn)(pTHX_ int fd, int mask, void *ud); |
| 19 |
|
| typedef void (*dbil_timer_fn)(pTHX_ void *ud); |
| 20 |
|
| |
| 21 |
|
| typedef struct dbil_vt { |
| 22 |
|
| void *ctx; /* adapter-owned; pass to every call */ |
| 23 |
|
| |
| 24 |
|
| /* persistent fd watchers; ud must outlive the watcher */ |
| 25 |
|
| void (*add_reader)(pTHX_ void *ctx, int fd, dbil_io_fn fn, void *ud); |
| 26 |
|
| void (*add_writer)(pTHX_ void *ctx, int fd, dbil_io_fn fn, void *ud); |
| 27 |
|
| void (*remove)(pTHX_ void *ctx, int fd); /* both directions */ |
| 28 |
|
| |
| 29 |
|
| /* one-shot timer; cancel only before it fires (handle freed on fire) */ |
| 30 |
|
| void *(*timer)(pTHX_ void *ctx, double secs, dbil_timer_fn fn, void *ud); |
| 31 |
|
| void (*timer_cancel)(pTHX_ void *ctx, void *timer); |
| 32 |
|
| |
| 33 |
|
| /* ecosystem-native pending future (+1, caller owns) */ |
| 34 |
|
| SV *(*new_future)(pTHX_ void *ctx); |
| 35 |
|
| |
| 36 |
|
| /* pump the loop until the future (native or DBIx::Loop::Future) settles */ |
| 37 |
|
| void (*await)(pTHX_ void *ctx, SV *future); |
| 38 |
|
| } dbil_vt; |
| 39 |
|
| |
| 40 |
|
| /* the C vtable of a loop adapter object, or NULL (a Perl-seam adapter) */ |
| 41 |
24 |
| static dbil_vt *dbil_vt_of(pTHX_ SV *adapter) { |
| 42 |
|
| HV *h; |
| 43 |
|
| SV **e; |
| 44 |
24 |
▶ | if (!(adapter && SvROK(adapter) && SvTYPE(SvRV(adapter)) == SVt_PVHV)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(adapter && SvROK(adapter) && SvTYPE(SvRV(adapter)) == SVt_PVHV)) |
24 |
0 |
24 |
| if (!(adapter && SvROK(adapter) && SvTYPE(SvRV(adapter)) == SVt_PVHV)) |
24 |
0 |
24 |
| if (!(adapter && SvROK(adapter) && SvTYPE(SvRV(adapter)) == SVt_PVHV)) |
0 |
24 |
24 |
|
| 45 |
0 |
| return NULL; |
| 46 |
24 |
| h = (HV *)SvRV(adapter); |
| 47 |
24 |
| e = hv_fetchs(h, "_vt", 0); |
| 48 |
24 |
▶ | return (e && *e && SvIOK(*e)) ? INT2PTR(dbil_vt *, SvIV(*e)) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| return (e && *e && SvIOK(*e)) ? INT2PTR(dbil_vt *, SvIV(*e)) : NULL; |
0 |
24 |
24 |
| return (e && *e && SvIOK(*e)) ? INT2PTR(dbil_vt *, SvIV(*e)) : NULL; |
0 |
0 |
0 |
| return (e && *e && SvIOK(*e)) ? INT2PTR(dbil_vt *, SvIV(*e)) : NULL; |
0 |
0 |
0 |
|
| 49 |
|
| } |
| 50 |
|
| |
| 51 |
|
| #endif /* DBIL_VT_H */ |