diff --git a/include/study.h b/include/study.h new file mode 100644 index 0000000000000000000000000000000000000000..3180ae95af591d2a9ce0cbdd77ee6a5cf84a98a4 --- /dev/null +++ b/include/study.h @@ -0,0 +1,43 @@ +#ifndef STUDY_H_ +#define STUDY_H_ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +// include standard library +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif /* STUDY_H_ */ \ No newline at end of file diff --git a/php_study.h b/php_study.h index 70a13b1870a8a33c68c2377d1977cfacc0a11641..eab01b3e3b0ff86132fc77863391f9256f10d36d 100644 --- a/php_study.h +++ b/php_study.h @@ -12,20 +12,24 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: | + | Author: codinghuang | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_STUDY_H #define PHP_STUDY_H +#include "php.h" +#include "php_ini.h" +#include "ext/standard/info.h" + +#include "study.h" + +#define PHP_STUDY_VERSION "0.1.0" + extern zend_module_entry study_module_entry; #define phpext_study_ptr &study_module_entry -#define PHP_STUDY_VERSION "0.1.0" /* Replace with version number for your extension */ - #ifdef PHP_WIN32 # define PHP_STUDY_API __declspec(dllexport) #elif defined(__GNUC__) && __GNUC__ >= 4 @@ -38,34 +42,11 @@ extern zend_module_entry study_module_entry; #include "TSRM.h" #endif -/* - Declare any global variables you may need between the BEGIN - and END macros here: - +/** + * Declare any global variables you may need between the BEGIN and END macros here + */ ZEND_BEGIN_MODULE_GLOBALS(study) - zend_long global_value; - char *global_string; -ZEND_END_MODULE_GLOBALS(study) -*/ - -/* Always refer to the globals in your function as STUDY_G(variable). - You are encouraged to rename these macros something shorter, see - examples in any other php module directory. -*/ -#define STUDY_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(study, v) - -#if defined(ZTS) && defined(COMPILE_DL_STUDY) -ZEND_TSRMLS_CACHE_EXTERN() -#endif - -#endif /* PHP_STUDY_H */ +ZEND_END_MODULE_GLOBALS(study) -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ +#endif /* PHP_STUDY_H */ \ No newline at end of file diff --git a/study.c b/study.cc similarity index 53% rename from study.c rename to study.cc index e35c3b237eff20423d38ee4545aaa1553736d850..dac7d32b7dde974a2783f3588fbc461edfeacf54 100644 --- a/study.c +++ b/study.cc @@ -12,74 +12,11 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: | + | Author: codinghuang | +----------------------------------------------------------------------+ */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "php_study.h" -#include - -static void (*orig_interrupt_function)(zend_execute_data *execute_data); - -void schedule(); -static void create_scheduler_thread(); -static void new_interrupt_function(zend_execute_data *execute_data); - -void init() -{ - orig_interrupt_function = zend_interrupt_function; - zend_interrupt_function = new_interrupt_function; -} - -static void new_interrupt_function(zend_execute_data *execute_data) -{ - php_printf("yeild coroutine\n"); - if (orig_interrupt_function) - { - orig_interrupt_function(execute_data); - } -} - -void schedule() -{ - while (1) - { - EG(vm_interrupt) = 1; - usleep(5000); - } -} - -static void create_scheduler_thread() -{ - pthread_t pidt; - - if (pthread_create(&pidt, NULL, (void * (*)(void *)) schedule, NULL) < 0) - { - php_printf("pthread_create[PHPCoroutine Scheduler] failed"); - } -} - -PHP_FUNCTION(start_interrupt) { - init(); - create_scheduler_thread(); -}; - -PHP_FUNCTION(test) { - zend_string *str; - - str = zend_string_init("foo", strlen("foo"), 0); - php_printf("This is my string: %s\n", ZSTR_VAL(str)); - php_printf("It is %zd char long\n", ZSTR_LEN(str)); - - zend_string_release(str); -}; PHP_MINIT_FUNCTION(study) { @@ -93,9 +30,6 @@ PHP_MSHUTDOWN_FUNCTION(study) PHP_RINIT_FUNCTION(study) { -#if defined(COMPILE_DL_STUDY) && defined(ZTS) - ZEND_TSRMLS_CACHE_UPDATE(); -#endif return SUCCESS; } @@ -112,8 +46,6 @@ PHP_MINFO_FUNCTION(study) } const zend_function_entry study_functions[] = { - PHP_FE(start_interrupt, NULL) - PHP_FE(test, NULL) PHP_FE_END }; @@ -131,8 +63,5 @@ zend_module_entry study_module_entry = { }; #ifdef COMPILE_DL_STUDY -#ifdef ZTS -ZEND_TSRMLS_CACHE_DEFINE() -#endif ZEND_GET_MODULE(study) #endif