提交 ae2c1d54 编写于 作者: C codinghuang

Modify: 修改php_study.h、study.cc、study.h内容

上级 934c276c
#ifndef STUDY_H_
#define STUDY_H_
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
// include standard library
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#include <poll.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/select.h>
#include <sys/mman.h>
#include <sys/ipc.h>
#include <sys/wait.h>
#include <sys/un.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/stat.h>
#endif /* STUDY_H_ */
\ No newline at end of file
......@@ -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
......@@ -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 <pthread.h>
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册