/src/php-src/main/php_ticks.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | +----------------------------------------------------------------------+ |
3 | | | Copyright (c) The PHP Group | |
4 | | +----------------------------------------------------------------------+ |
5 | | | This source file is subject to version 3.01 of the PHP license, | |
6 | | | that is bundled with this package in the file LICENSE, and is | |
7 | | | available through the world-wide-web at the following url: | |
8 | | | https://www.php.net/license/3_01.txt | |
9 | | | If you did not receive a copy of the PHP license and are unable to | |
10 | | | obtain it through the world-wide-web, please send a note to | |
11 | | | license@php.net so we can mail you a copy immediately. | |
12 | | +----------------------------------------------------------------------+ |
13 | | | Author: Stig Bakken <ssb@php.net> | |
14 | | +----------------------------------------------------------------------+ |
15 | | */ |
16 | | |
17 | | #include "php.h" |
18 | | #include "php_ticks.h" |
19 | | |
20 | | struct st_tick_function |
21 | | { |
22 | | void (*func)(int, void *); |
23 | | void *arg; |
24 | | }; |
25 | | |
26 | | void php_startup_ticks(void) |
27 | 16 | { |
28 | 16 | zend_llist_init(&PG(tick_functions), sizeof(struct st_tick_function), NULL, 1); |
29 | 16 | } |
30 | | |
31 | | void php_deactivate_ticks(void) |
32 | 300k | { |
33 | 300k | zend_llist_clean(&PG(tick_functions)); |
34 | 300k | } |
35 | | |
36 | | void php_shutdown_ticks(php_core_globals *core_globals) |
37 | 0 | { |
38 | 0 | zend_llist_destroy(&core_globals->tick_functions); |
39 | 0 | } |
40 | | |
41 | | static int php_compare_tick_functions(void *elem1, void *elem2) |
42 | 0 | { |
43 | 0 | struct st_tick_function *e1 = (struct st_tick_function *)elem1; |
44 | 0 | struct st_tick_function *e2 = (struct st_tick_function *)elem2; |
45 | 0 | return e1->func == e2->func && e1->arg == e2->arg; |
46 | 0 | } |
47 | | |
48 | | PHPAPI void php_add_tick_function(void (*func)(int, void*), void * arg) |
49 | 34 | { |
50 | 34 | struct st_tick_function tmp = {func, arg}; |
51 | 34 | zend_llist_add_element(&PG(tick_functions), (void *)&tmp); |
52 | 34 | } |
53 | | |
54 | | PHPAPI void php_remove_tick_function(void (*func)(int, void *), void * arg) |
55 | 0 | { |
56 | 0 | struct st_tick_function tmp = {func, arg}; |
57 | 0 | zend_llist_del_element(&PG(tick_functions), (void *)&tmp, (int(*)(void*, void*))php_compare_tick_functions); |
58 | 0 | } |
59 | | |
60 | | static void php_tick_iterator(void *d, void *arg) |
61 | 137 | { |
62 | 137 | struct st_tick_function *data = (struct st_tick_function *)d; |
63 | 137 | data->func(*((int *)arg), data->arg); |
64 | 137 | } |
65 | | |
66 | | void php_run_ticks(int count) |
67 | 257 | { |
68 | 257 | zend_llist_apply_with_argument(&PG(tick_functions), (llist_apply_with_arg_func_t) php_tick_iterator, &count); |
69 | 257 | } |