Skip to content

Commit 7d210d8

Browse files
committed
check thread feature
1 parent 5fea385 commit 7d210d8

File tree

2 files changed

+88
-10
lines changed

2 files changed

+88
-10
lines changed

php_uv.c

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "php_uv.h"
2121
#include "ext/standard/info.h"
2222

23+
2324
#ifndef PHP_UV_DEBUG
2425
#define PHP_UV_DEBUG 0
2526
#endif
@@ -1198,19 +1199,87 @@ static int php_uv_do_callback(zval **retval_ptr, zval *callback, zval ***params,
11981199
}
11991200

12001201

1202+
#define UV_FETCH_ALL(ls, id, type) ((type) (*((void ***) ls))[TSRM_UNSHUFFLE_RSRC_ID(id)])
1203+
#define UV_FETCH_CTX(ls, id, type, element) (((type) (*((void ***) ls))[TSRM_UNSHUFFLE_RSRC_ID(id)])->element)
1204+
#define UV_CG(ls, v) UV_FETCH_CTX(ls, compiler_globals_id, zend_compiler_globals*, v)
1205+
#define UV_CG_ALL(ls) UV_FETCH_ALL(ls, compiler_globals_id, zend_compiler_globals*)
1206+
#define UV_EG(ls, v) UV_FETCH_CTX(ls, executor_globals_id, zend_executor_globals*, v)
1207+
#define UV_SG(ls, v) UV_FETCH_CTX(ls, sapi_globals_id, sapi_globals_struct*, v)
1208+
#define UV_EG_ALL(ls) UV_FETCH_ALL(ls, executor_globals_id, zend_executor_globals*)
1209+
12011210
static int php_uv_do_callback2(zval **retval_ptr, php_uv_t *uv, zval ***params, int param_count, enum php_uv_callback_type type TSRMLS_DC)
12021211
{
12031212
int error = 0;
1204-
1213+
1214+
if (ZEND_FCI_INITIALIZED(uv->callback[type]->fci)) {
1215+
uv->callback[type]->fci.params = params;
1216+
uv->callback[type]->fci.retval_ptr_ptr = retval_ptr;
1217+
uv->callback[type]->fci.param_count = param_count;
1218+
uv->callback[type]->fci.no_separation = 1;
1219+
1220+
if (zend_call_function(&uv->callback[type]->fci, &uv->callback[type]->fcc TSRMLS_CC) != SUCCESS) {
1221+
error = -1;
1222+
}
1223+
} else {
1224+
error = -2;
1225+
}
1226+
1227+
//zend_fcall_info_args_clear(&uv->callback[type]->fci, 0);
1228+
1229+
return error;
1230+
}
1231+
1232+
static int php_uv_do_callback3(zval **retval_ptr, php_uv_t *uv, zval ***params, int param_count, enum php_uv_callback_type type)
1233+
{
1234+
int error = 0;
1235+
zend_executor_globals *ZEG = NULL;
1236+
void ***tsrm_ls, ***old;
1237+
12051238
if (ZEND_FCI_INITIALIZED(uv->callback[type]->fci)) {
1239+
tsrm_ls = tsrm_new_interpreter_context();
1240+
old = tsrm_set_interpreter_context(tsrm_ls);
1241+
1242+
PG(expose_php) = 0;
1243+
PG(auto_globals_jit) = 0;
1244+
1245+
php_request_startup(TSRMLS_C);
1246+
ZEG = UV_EG_ALL(TSRMLS_C);
1247+
ZEG->in_execution = 1;
1248+
ZEG->current_execute_data=NULL;
1249+
ZEG->current_module=phpext_uv_ptr;
1250+
ZEG->This = NULL;
1251+
12061252
uv->callback[type]->fci.params = params;
12071253
uv->callback[type]->fci.retval_ptr_ptr = retval_ptr;
12081254
uv->callback[type]->fci.param_count = param_count;
12091255
uv->callback[type]->fci.no_separation = 1;
1256+
uv->callback[type]->fci.object_ptr = ZEG->This;
1257+
uv->callback[type]->fcc.initialized = 1;
1258+
1259+
uv->callback[type]->fcc.calling_scope = NULL;
1260+
uv->callback[type]->fcc.called_scope = NULL;
1261+
uv->callback[type]->fcc.object_ptr = ZEG->This;
12101262

12111263
if (zend_call_function(&uv->callback[type]->fci, &uv->callback[type]->fcc TSRMLS_CC) != SUCCESS) {
12121264
error = -1;
12131265
}
1266+
1267+
{
1268+
zend_op_array *ops = &uv->callback[type]->fcc.function_handler->op_array;
1269+
if (ops) {
1270+
if (ops->run_time_cache) {
1271+
efree(ops->run_time_cache);
1272+
ops->run_time_cache = NULL;
1273+
}
1274+
}
1275+
}
1276+
if (retval_ptr != NULL) {
1277+
zval_ptr_dtor(retval_ptr);
1278+
}
1279+
1280+
php_request_shutdown(TSRMLS_C);
1281+
tsrm_set_interpreter_context(old);
1282+
tsrm_free_interpreter_context(tsrm_ls);
12141283
} else {
12151284
error = -2;
12161285
}
@@ -1628,7 +1697,7 @@ static void php_uv_async_cb(uv_async_t* handle, int status)
16281697

16291698
params[0] = &resource;
16301699
params[1] = &zstat;
1631-
1700+
16321701
php_uv_do_callback2(&retval_ptr, uv, params, 2, PHP_UV_ASYNC_CB TSRMLS_CC);
16331702

16341703
zval_ptr_dtor(&resource);
@@ -1650,11 +1719,8 @@ static void php_uv_work_cb(uv_work_t* req)
16501719

16511720
PHP_UV_DEBUG_PRINT("work_cb\n");
16521721

1653-
php_uv_do_callback2(&retval_ptr, uv, NULL, 0, PHP_UV_WORK_CB TSRMLS_CC);
1722+
php_uv_do_callback3(&retval_ptr, uv, NULL, 0, PHP_UV_WORK_CB);
16541723

1655-
if (retval_ptr != NULL) {
1656-
zval_ptr_dtor(&retval_ptr);
1657-
}
16581724
PHP_UV_DEBUG_RESOURCE_REFCOUNT(uv_work_cb, uv->resource_id);
16591725
}
16601726

@@ -1664,12 +1730,13 @@ static void php_uv_after_work_cb(uv_work_t* req, int status)
16641730
php_uv_t *uv = (php_uv_t*)req->data;
16651731
TSRMLS_FETCH_FROM_CTX(uv != NULL ? uv->thread_ctx : NULL);
16661732

1733+
uv = (php_uv_t*)req->data;
1734+
16671735
PHP_UV_DEBUG_PRINT("after_work_cb\n");
16681736

1669-
php_uv_do_callback2(&retval_ptr, uv, NULL, 0, PHP_UV_AFTER_WORK_CB TSRMLS_CC);
1737+
php_uv_do_callback3(&retval_ptr, uv, NULL, 0, PHP_UV_AFTER_WORK_CB);
16701738

1671-
zval_ptr_dtor(&retval_ptr);
1672-
PHP_UV_DEBUG_RESOURCE_REFCOUNT(uv_after_work_cb, uv->resource_id);
1739+
PHP_UV_DEBUG_RESOURCE_REFCOUNT(uv_work_cb, uv->resource_id);
16731740
}
16741741

16751742
static void php_uv_fs_cb(uv_fs_t* req)

php_uv.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,18 @@
4040
#include "ext/sockets/php_sockets.h"
4141
#endif
4242

43-
#include "zend_interfaces.h"
43+
#include <Zend/zend.h>
44+
#include <Zend/zend_compile.h>
45+
#include <Zend/zend_exceptions.h>
46+
#include <Zend/zend_extensions.h>
47+
#include <Zend/zend_globals.h>
48+
#include <Zend/zend_hash.h>
49+
#include <Zend/zend_ts_hash.h>
50+
#include <Zend/zend_interfaces.h>
51+
#include <Zend/zend_list.h>
52+
#include <Zend/zend_object_handlers.h>
53+
#include <Zend/zend_variables.h>
54+
#include <Zend/zend_vm.h>
4455

4556
/* Define the entry point symbol
4657
* Zend will use when loading this module

0 commit comments

Comments
 (0)