| 1 |
|
| /* hm_workerhook.h - the v4 on_worker_start registry. |
| 2 |
|
| * |
| 3 |
|
| * Split out and included before hm_core.h because the two halves sit on |
| 4 |
|
| * opposite sides of the build: hm_core.h FIRES the callbacks, from inside |
| 5 |
|
| * hm_worker, while hm_abi_impl.h REGISTERS them, and it is compiled after. |
| 6 |
|
| * Only the storage and the two small functions are needed by both. |
| 7 |
|
| * |
| 8 |
|
| * Needs hm_abi.h (the hm_abi_worker_cb typedef) and nothing else. |
| 9 |
|
| */ |
| 10 |
|
| |
| 11 |
|
| #ifndef HM_WORKERHOOK_H |
| 12 |
|
| #define HM_WORKERHOOK_H |
| 13 |
|
| |
| 14 |
|
| #include "hm_abi.h" |
| 15 |
|
| |
| 16 |
|
| static struct { hm_abi_worker_cb cb; void *ud; } |
| 17 |
|
| HM_WORKER_CB[HM_ABI_MAX_WORKER_CB]; |
| 18 |
|
| static int HM_WORKER_CB_N = 0; |
| 19 |
|
| |
| 20 |
7 |
| static int hm_worker_hook_add(pTHX_ hm_abi_worker_cb cb, void *ud) { |
| 21 |
|
| PERL_UNUSED_CONTEXT; |
| 22 |
|
| /* |
| 23 |
|
| # uncoverable branch true class:ignore_covered_err |
| 24 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 25 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 26 |
7 |
▶ | if (!cb || HM_WORKER_CB_N >= HM_ABI_MAX_WORKER_CB) return 0; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!cb || HM_WORKER_CB_N >= HM_ABI_MAX_WORKER_CB) return 0; |
7 |
0 |
7 |
| if (!cb || HM_WORKER_CB_N >= HM_ABI_MAX_WORKER_CB) return 0; |
0 |
7 |
7 |
|
| 27 |
7 |
| HM_WORKER_CB[HM_WORKER_CB_N].cb = cb; |
| 28 |
7 |
| HM_WORKER_CB[HM_WORKER_CB_N].ud = ud; |
| 29 |
7 |
| HM_WORKER_CB_N++; |
| 30 |
7 |
| return 1; |
| 31 |
|
| } |
| 32 |
|
| |
| 33 |
|
| /* Fire, in registration order, with this worker's loop. Called from |
| 34 |
|
| * hm_worker once the loop exists and before it starts turning - which in a |
| 35 |
|
| * prefork server is in the child, after the fork. |
| 36 |
|
| * |
| 37 |
|
| * Registration happens in the parent, before run(), and the array is plain |
| 38 |
|
| * memory, so every child inherits the same list across fork() without any |
| 39 |
|
| * work. That is the reason this is an array of C pointers and not anything |
| 40 |
|
| * holding an SV: it has to survive a fork the consumer never sees. */ |
| 41 |
134 |
| static void hm_worker_hook_fire(pTHX_ void *loop) { |
| 42 |
|
| int i; |
| 43 |
142 |
▶ | for (i = 0; i < HM_WORKER_CB_N; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < HM_WORKER_CB_N; i++) |
8 |
134 |
142 |
|
| 44 |
8 |
| HM_WORKER_CB[i].cb(aTHX_ loop, HM_WORKER_CB[i].ud); |
| 45 |
134 |
| } |
| 46 |
|
| |
| 47 |
|
| #endif /* HM_WORKERHOOK_H */ |