Add support for parameters to tick functions, on C level. This is only

for extensions that want to use register tick functions. Userland tick
functions are unaffected.
This commit is contained in:
Andrey Hristov 2015-09-28 11:21:17 +02:00
parent fef88b34e7
commit be6546fac9
4 changed files with 24 additions and 22 deletions

View file

@ -513,7 +513,7 @@ PHP_MINIT_FUNCTION(pcntl)
{
php_register_signal_constants(INIT_FUNC_ARGS_PASSTHRU);
php_pcntl_register_errno_constants(INIT_FUNC_ARGS_PASSTHRU);
php_add_tick_function(pcntl_signal_dispatch);
php_add_tick_function(pcntl_signal_dispatch, NULL);
return SUCCESS;
}

View file

@ -4968,9 +4968,8 @@ static void user_tick_function_call(user_tick_function_entry *tick_fe) /* {{{ */
}
/* }}} */
static void run_user_tick_functions(int tick_count) /* {{{ */
static void run_user_tick_functions(int tick_count, void *arg) /* {{{ */
{
zend_llist_apply(BG(user_tick_functions), (llist_apply_func_t) user_tick_function_call);
}
/* }}} */
@ -5680,7 +5679,7 @@ PHP_FUNCTION(register_tick_function)
zend_llist_init(BG(user_tick_functions),
sizeof(user_tick_function_entry),
(llist_dtor_func_t) user_tick_function_dtor, 0);
php_add_tick_function(run_user_tick_functions);
php_add_tick_function(run_user_tick_functions, NULL);
}
for (i = 0; i < tick_fe.arg_count; i++) {

View file

@ -21,9 +21,15 @@
#include "php.h"
#include "php_ticks.h"
struct st_tick_function
{
void (*func)(int, void *);
void *arg;
};
int php_startup_ticks(void)
{
zend_llist_init(&PG(tick_functions), sizeof(void(*)(int)), NULL, 1);
zend_llist_init(&PG(tick_functions), sizeof(struct st_tick_function), NULL, 1);
return SUCCESS;
}
@ -39,30 +45,27 @@ void php_shutdown_ticks(void)
static int php_compare_tick_functions(void *elem1, void *elem2)
{
void(*func1)(int);
void(*func2)(int);
memcpy(&func1, elem1, sizeof(void(*)(int)));
memcpy(&func2, elem2, sizeof(void(*)(int)));
return (func1 == func2);
struct st_tick_function *e1 = (struct st_tick_function *)elem1;
struct st_tick_function *e2 = (struct st_tick_function *)elem2;
return e1->func == e2->func && e1->arg == e2->arg;
}
PHPAPI void php_add_tick_function(void (*func)(int))
PHPAPI void php_add_tick_function(void (*func)(int, void*), void * arg)
{
zend_llist_add_element(&PG(tick_functions), (void *)&func);
struct st_tick_function tmp = {func, arg};
zend_llist_add_element(&PG(tick_functions), (void *)&tmp);
}
PHPAPI void php_remove_tick_function(void (*func)(int))
PHPAPI void php_remove_tick_function(void (*func)(int, void *), void * arg)
{
zend_llist_del_element(&PG(tick_functions), (void *)func,
(int(*)(void*, void*))php_compare_tick_functions);
struct st_tick_function tmp = {func, arg};
zend_llist_del_element(&PG(tick_functions), (void *)&tmp, (int(*)(void*, void*))php_compare_tick_functions);
}
static void php_tick_iterator(void *data, void *arg)
static void php_tick_iterator(void *d, void *arg)
{
void (*func)(int);
memcpy(&func, data, sizeof(void(*)(int)));
func(*((int *)arg));
struct st_tick_function *data = (struct st_tick_function *)d;
data->func(*((int *)arg), data->arg);
}
void php_run_ticks(int count)

View file

@ -27,8 +27,8 @@ void php_shutdown_ticks(void);
void php_run_ticks(int count);
BEGIN_EXTERN_C()
PHPAPI void php_add_tick_function(void (*func)(int));
PHPAPI void php_remove_tick_function(void (*func)(int));
PHPAPI void php_add_tick_function(void (*func)(int, void *), void *arg);
PHPAPI void php_remove_tick_function(void (*func)(int, void *), void * arg);
END_EXTERN_C()
#endif