Coverage Report

Created: 2022-10-14 11:20

/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
   | http://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
int php_startup_ticks(void)
27
3.54k
{
28
3.54k
  zend_llist_init(&PG(tick_functions), sizeof(struct st_tick_function), NULL, 1);
29
3.54k
  return SUCCESS;
30
3.54k
}
31
32
void php_deactivate_ticks(void)
33
383k
{
34
383k
  zend_llist_clean(&PG(tick_functions));
35
383k
}
36
37
void php_shutdown_ticks(void)
38
0
{
39
0
  zend_llist_destroy(&PG(tick_functions));
40
0
}
41
42
static int php_compare_tick_functions(void *elem1, void *elem2)
43
0
{
44
0
  struct st_tick_function *e1 = (struct st_tick_function *)elem1;
45
0
  struct st_tick_function *e2 = (struct st_tick_function *)elem2;
46
0
  return e1->func == e2->func && e1->arg == e2->arg;
47
0
}
48
49
PHPAPI void php_add_tick_function(void (*func)(int, void*), void * arg)
50
0
{
51
0
  struct st_tick_function tmp = {func, arg};
52
0
  zend_llist_add_element(&PG(tick_functions), (void *)&tmp);
53
0
}
54
55
PHPAPI void php_remove_tick_function(void (*func)(int, void *), void * arg)
56
0
{
57
0
  struct st_tick_function tmp = {func, arg};
58
0
  zend_llist_del_element(&PG(tick_functions), (void *)&tmp, (int(*)(void*, void*))php_compare_tick_functions);
59
0
}
60
61
static void php_tick_iterator(void *d, void *arg)
62
0
{
63
0
  struct st_tick_function *data = (struct st_tick_function *)d;
64
0
  data->func(*((int *)arg), data->arg);
65
0
}
66
67
void php_run_ticks(int count)
68
0
{
69
0
  zend_llist_apply_with_argument(&PG(tick_functions), (llist_apply_with_arg_func_t) php_tick_iterator, &count);
70
0
}