Back to index

php5  5.3.10
php_ticks.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Author: Stig Bakken <ssb@php.net>                                    |
00016    +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: php_ticks.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #include "php.h"
00022 #include "php_ticks.h"
00023 
00024 int php_startup_ticks(TSRMLS_D)
00025 {
00026        zend_llist_init(&PG(tick_functions), sizeof(void(*)(int)), NULL, 1);
00027        return SUCCESS;
00028 }
00029 
00030 void php_deactivate_ticks(TSRMLS_D)
00031 {
00032        zend_llist_clean(&PG(tick_functions));
00033 }
00034 
00035 void php_shutdown_ticks(TSRMLS_D)
00036 {
00037        zend_llist_destroy(&PG(tick_functions));
00038 }
00039 
00040 static int php_compare_tick_functions(void *elem1, void *elem2)
00041 {
00042        void(*func1)(int);
00043        void(*func2)(int);
00044        memcpy(&func1, elem1, sizeof(void(*)(int)));
00045        memcpy(&func2, elem2, sizeof(void(*)(int)));
00046        return (func1 == func2);
00047 }
00048 
00049 PHPAPI void php_add_tick_function(void (*func)(int))
00050 {
00051        TSRMLS_FETCH();
00052 
00053        zend_llist_add_element(&PG(tick_functions), (void *)&func);
00054 }
00055 
00056 PHPAPI void php_remove_tick_function(void (*func)(int))
00057 {
00058        TSRMLS_FETCH();
00059 
00060        zend_llist_del_element(&PG(tick_functions), (void *)func,
00061                                              (int(*)(void*, void*))php_compare_tick_functions);
00062 }
00063 
00064 static void php_tick_iterator(void *data, void *arg TSRMLS_DC)
00065 {
00066        void (*func)(int);
00067 
00068        memcpy(&func, data, sizeof(void(*)(int)));
00069        func(*((int *)arg));
00070 }
00071 
00072 void php_run_ticks(int count)
00073 {
00074        TSRMLS_FETCH();
00075 
00076        zend_llist_apply_with_argument(&PG(tick_functions), (llist_apply_with_arg_func_t) php_tick_iterator, &count TSRMLS_CC);
00077 }
00078 
00079 /*
00080  * Local variables:
00081  * tab-width: 4
00082  * c-basic-offset: 4
00083  * End:
00084  * vim600: sw=4 ts=4 fdm=marker
00085  * vim<600: sw=4 ts=4
00086  */