cvs: php4 /main main.c php_ticks.c php_ticks.h

From: Date: Tue, 29 Aug 2000 09:18:48 +0000
Subject: cvs: php4 /main main.c php_ticks.c php_ticks.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-1443@lists.php.net to get a copy of this message
ssb Tue Aug 29 02:18:48 2000 EDT Modified files: /php4/main main.c php_ticks.c php_ticks.h Log: @Added PHP API for Zend's ticks Added PHP API for registering tick functions. Ticks is a per-instruction callback in Zend that allows us to implement cooperative multitasking within PHP. Example: In extension code: php_add_tick_function(my_tick_func); void my_tick_func(int count) { php_printf("[tick %d]", count); } In PHP code: <?php declare(ticks = 1) { print "there should be two ticks here.\n"; } ?> Index: php4/main/main.c diff -u php4/main/main.c:1.303 php4/main/main.c:1.304 --- php4/main/main.c:1.303 Sun Aug 27 13:51:30 2000 +++ php4/main/main.c Tue Aug 29 02:18:48 2000 @@ -19,7 +19,7 @@ */ -/* $Id: main.c,v 1.303 2000/08/27 20:51:30 sas Exp $ */ +/* $Id: main.c,v 1.304 2000/08/29 09:18:48 ssb Exp $ */ #include <stdio.h> @@ -756,7 +756,6 @@ } return SUCCESS; } - int php_module_startup(sapi_module_struct *sf) { Index: php4/main/php_ticks.c diff -u php4/main/php_ticks.c:1.3 php4/main/php_ticks.c:1.4 --- php4/main/php_ticks.c:1.3 Mon Aug 21 02:50:53 2000 +++ php4/main/php_ticks.c Tue Aug 29 02:18:48 2000 @@ -16,14 +16,14 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_ticks.c,v 1.3 2000/08/21 09:50:53 sas Exp $ */ +/* $Id: php_ticks.c,v 1.4 2000/08/29 09:18:48 ssb Exp $ */ #include "php.h" #include "php_ticks.h" int php_startup_ticks(PLS_D) { - zend_llist_init(&PG(tick_functions), sizeof(PG(tick_functions)), NULL, 1); + zend_llist_init(&PG(tick_functions), sizeof(void(*)(int)), NULL, 1); return SUCCESS; } @@ -34,31 +34,33 @@ static int php_compare_tick_functions(void *elem1, void *elem2) { - return ((void (*)(int))elem1 == (void (*)(int))elem2); + void(*func1)(int); + void(*func2)(int); + memcpy(&func1, elem1, sizeof(void(*)(int))); + memcpy(&func2, elem2, sizeof(void(*)(int))); + return (func1 == func2); } -PHPAPI int php_add_tick_function(void (*func)(int)) +PHPAPI void php_add_tick_function(void (*func)(int)) { PLS_FETCH(); - zend_llist_add_element(&PG(tick_functions), func); - - return SUCCESS; + zend_llist_add_element(&PG(tick_functions), (void *)&func); } -PHPAPI int php_remove_tick_function(void (*func)(int)) +PHPAPI void php_remove_tick_function(void (*func)(int)) { PLS_FETCH(); zend_llist_del_element(&PG(tick_functions), func, (int(*)(void*,void*))php_compare_tick_functions); - return SUCCESS; } static void php_tick_iterator(void *data, void *arg) { void (*func)(int); - func = (void(*)(int))data; + + memcpy(&func, data, sizeof(void(*)(int))); func(*((int *)arg)); } Index: php4/main/php_ticks.h diff -u php4/main/php_ticks.h:1.3 php4/main/php_ticks.h:1.4 --- php4/main/php_ticks.h:1.3 Sun Jul 23 22:41:00 2000 +++ php4/main/php_ticks.h Tue Aug 29 02:18:48 2000 @@ -16,21 +16,16 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_ticks.h,v 1.3 2000/07/24 05:41:00 david Exp $ */ +/* $Id: php_ticks.h,v 1.4 2000/08/29 09:18:48 ssb Exp $ */ #ifndef PHP_TICKS_H #define PHP_TICKS_H -struct _php_tick_function_entry { - void (*func)(int count); - struct _php_tick_function_entry *next; -}; - int php_startup_ticks(PLS_D); void php_shutdown_ticks(PLS_D); void php_run_ticks(int count); -PHPAPI int php_add_tick_function(void (*func)(int count)); -PHPAPI int php_remove_tick_function(void (*func)(int count)); +PHPAPI void php_add_tick_function(void (*func)(int)); +PHPAPI void php_remove_tick_function(void (*func)(int)); #endif

« previous php.cvs (#1443) next »