Skip to content

Commit edf8f7f

Browse files
committed
add note
1 parent 6af6b98 commit edf8f7f

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,9 +2129,12 @@ send async callback immidiately
21292129
##### *Example*
21302130

21312131

2132-
21332132
### void uv_queue_work(resource $loop, callable $callback, callable $after_callback)
21342133

2134+
##### *Description*
2135+
2136+
execute callbacks in another thread (requires Thread Safe enabled PHP)
2137+
21352138

21362139
### resource uv_fs_open(resource $loop, string $path, long $flag, long $mode, callable $callback)
21372140

@@ -2835,8 +2838,7 @@ $poll = uv_poll_init(uv_default_loop(), $fd);
28352838
##### *Note*
28362839

28372840
* if you want to use a socket. please use uv_poll_init_socket instead of this. Windows can't handle socket with this function.
2838-
2839-
2841+
* some platform doesn't support file descriptor on these method.
28402842

28412843
### uv uv_poll_init_socket([resource $uv_loop], zval fd)
28422844

php_uv.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0
169169
#define PHP_UV_DEBUG_RESOURCE_REFCOUNT(name, resource_id)
170170
#endif
171171

172+
#ifdef ZTS
173+
#define UV_FETCH_ALL(ls, id, type) ((type) (*((void ***) ls))[TSRM_UNSHUFFLE_RSRC_ID(id)])
174+
#define UV_FETCH_CTX(ls, id, type, element) (((type) (*((void ***) ls))[TSRM_UNSHUFFLE_RSRC_ID(id)])->element)
175+
#define UV_CG(ls, v) UV_FETCH_CTX(ls, compiler_globals_id, zend_compiler_globals*, v)
176+
#define UV_CG_ALL(ls) UV_FETCH_ALL(ls, compiler_globals_id, zend_compiler_globals*)
177+
#define UV_EG(ls, v) UV_FETCH_CTX(ls, executor_globals_id, zend_executor_globals*, v)
178+
#define UV_SG(ls, v) UV_FETCH_CTX(ls, sapi_globals_id, sapi_globals_struct*, v)
179+
#define UV_EG_ALL(ls) UV_FETCH_ALL(ls, executor_globals_id, zend_executor_globals*)
180+
#endif
181+
172182

173183
extern void php_uv_init(TSRMLS_D);
174184

@@ -1198,15 +1208,6 @@ static int php_uv_do_callback(zval **retval_ptr, zval *callback, zval ***params,
11981208
return error;
11991209
}
12001210

1201-
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-
12101211
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)
12111212
{
12121213
int error = 0;
@@ -1229,6 +1230,7 @@ static int php_uv_do_callback2(zval **retval_ptr, php_uv_t *uv, zval ***params,
12291230
return error;
12301231
}
12311232

1233+
#ifdef ZTS
12321234
static int php_uv_do_callback3(zval **retval_ptr, php_uv_t *uv, zval ***params, int param_count, enum php_uv_callback_type type)
12331235
{
12341236
int error = 0;
@@ -1288,6 +1290,11 @@ static int php_uv_do_callback3(zval **retval_ptr, php_uv_t *uv, zval ***params,
12881290

12891291
return error;
12901292
}
1293+
#else
1294+
static int php_uv_do_callback3(zval **retval_ptr, php_uv_t *uv, zval ***params, int param_count, enum php_uv_callback_type type)
1295+
{
1296+
}
1297+
#endif
12911298

12921299
static void php_uv_tcp_connect_cb(uv_connect_t *req, int status)
12931300
{
@@ -5604,6 +5611,7 @@ PHP_FUNCTION(uv_async_send)
56045611
*/
56055612
PHP_FUNCTION(uv_queue_work)
56065613
{
5614+
#ifdef ZTS
56075615
int r;
56085616
zval *zloop = NULL;
56095617
uv_loop_t *loop;
@@ -5631,6 +5639,9 @@ PHP_FUNCTION(uv_queue_work)
56315639
php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_queue_work failed");
56325640
return;
56335641
}
5642+
#else
5643+
php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_queue_work doesn't support this PHP. please rebuild with --enable-maintainer-zts");
5644+
#endif
56345645
}
56355646
/* }}} */
56365647

tests/800-uv_queue_work.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
--TEST--
22
Check for uv_queue_work
3+
--SKIPIF--
4+
<?php
5+
ob_start();
6+
phpinfo();
7+
$data = ob_get_clean();
8+
if (!preg_match("/Thread Safety.+?enabled/", $data)) {
9+
echo "skip";
10+
}
311
--FILE--
412
<?php
513
$loop = uv_default_loop();

0 commit comments

Comments
 (0)