Skip to content

Commit 40c7f09

Browse files
author
Jason Greene
committed
Fully implement new thread safe model.
Fix ws.
1 parent 3b7bc25 commit 40c7f09

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

ext/pcntl/pcntl.c

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,32 +151,44 @@ void php_register_signal_constants(INIT_FUNC_ARGS)
151151
REGISTER_LONG_CONSTANT("SIGSYS", (long) SIGSYS, CONST_CS | CONST_PERSISTENT);
152152
}
153153

154-
PHP_MINIT_FUNCTION(pcntl)
154+
static void php_pcntl_init_globals(zend_pcntl_globals *pcntl_globals)
155155
{
156-
PCNTL_LS_FETCH();
157-
158-
php_register_signal_constants(INIT_FUNC_ARGS_PASSTHRU);
159-
zend_hash_init(&PCNTL_G(php_signal_table), 16, NULL, NULL, 1);
156+
zend_hash_init(&pcntl_globals->php_signal_table, 16, NULL, NULL, 1);
160157

161158
/* Just in case ... */
162-
memset(&PCNTL_G(php_signal_queue),0,sizeof(PCNTL_G(php_signal_queue)));
159+
memset(&pcntl_globals->php_signal_queue,0,sizeof(pcntl_globals->php_signal_queue));
163160

164-
zend_llist_init(&PCNTL_G(php_signal_queue), sizeof (long), NULL, 1);
165-
PCNTL_G(signal_queue_ready)=0;
166-
PCNTL_G(processing_signal_queue)=0;
161+
zend_llist_init(&pcntl_globals->php_signal_queue, sizeof (long), NULL, 1);
162+
pcntl_globals->signal_queue_ready=0;
163+
pcntl_globals->processing_signal_queue=0;
164+
}
165+
166+
static void php_pcntl_shutdown_globals(zend_pcntl_globals *pcntl_globals)
167+
{
168+
zend_hash_destroy(&pcntl_globals->php_signal_table);
169+
zend_llist_destroy(&pcntl_globals->php_signal_queue);
170+
}
171+
172+
PHP_MINIT_FUNCTION(pcntl)
173+
{
174+
php_register_signal_constants(INIT_FUNC_ARGS_PASSTHRU);
175+
ZEND_INIT_MODULE_GLOBALS(pcntl, php_pcntl_init_globals, php_pcntl_shutdown_globals);
167176
if (zend_register_extension(&pcntl_extension_entry, 0)==FAILURE)
168177
return FAILURE;
169178
return SUCCESS;
170179
}
180+
171181
PHP_MSHUTDOWN_FUNCTION(pcntl)
172182
{
173-
PCNTL_LS_FETCH();
174-
183+
175184
zend_hash_destroy(&PCNTL_G(php_signal_table));
176185
zend_llist_destroy(&PCNTL_G(php_signal_queue));
177186
return SUCCESS;
178187
}
179188

189+
190+
191+
180192
PHP_MINFO_FUNCTION(pcntl)
181193
{
182194
php_info_print_table_start();
@@ -355,7 +367,6 @@ PHP_FUNCTION(pcntl_signal)
355367
{
356368
zval **signo, **handle;
357369
char *func_name;
358-
PCNTL_LS_FETCH();
359370

360371
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &signo, &handle) == FAILURE) {
361372
WRONG_PARAM_COUNT;
@@ -404,10 +415,9 @@ static void old_pcntl_signal_handler(int signo)
404415
{
405416
char *func_name;
406417
zval *param, *call_name, *retval;
407-
PCNTL_LS_FETCH();
408418
TSRMLS_FETCH();
409419

410-
DEBUG_OUT("Caught signal: %d\n", signo);
420+
DEBUG_OUT("Caught signal: %d\n", signo);
411421
if (zend_hash_index_find(&PCNTL_G(php_signal_table), (long) signo, (void *) &func_name)==FAILURE) {
412422
DEBUG_OUT("Signl handler not fount");
413423
return;
@@ -434,7 +444,7 @@ static void old_pcntl_signal_handler(int signo)
434444
static void pcntl_signal_handler(int signo)
435445
{
436446
long signal_num=signo;
437-
PCNTL_LS_FETCH();
447+
TSRMLS_FETCH();
438448

439449
DEBUG_OUT("Caught signo %d\n", signo);
440450
if (! PCNTL_G(processing_signal_queue) && pcntl_zend_extension_active ) {
@@ -450,6 +460,8 @@ static void pcntl_signal_handler(int signo)
450460

451461
int pcntl_zend_extension_startup(zend_extension *extension)
452462
{
463+
TSRMLS_FETCH();
464+
453465
DEBUG_OUT("Statup Called\n");
454466
pcntl_zend_extension_active=1;
455467
CG(extended_info) = 1;
@@ -464,6 +476,8 @@ void pcntl_zend_extension_shutdown(zend_extension *extension)
464476

465477
void pcntl_zend_extension_activate(void)
466478
{
479+
TSRMLS_FETCH();
480+
467481
DEBUG_OUT("Activate Called\n");
468482
pcntl_zend_extension_active=1;
469483
CG(extended_info) = 1;
@@ -483,7 +497,6 @@ void pcntl_zend_extension_statement_handler(zend_op_array *op_array)
483497
zend_llist_element *element;
484498
zval *param, *call_name, *retval;
485499
char *func_name;
486-
PCNTL_LS_FETCH();
487500
TSRMLS_FETCH();
488501

489502
/* Bail if the queue is empty or if we are already playing the queue*/

ext/pcntl/php_pcntl.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,10 @@ ZEND_BEGIN_MODULE_GLOBALS(pcntl)
6363
int signal_queue_ready;
6464
int processing_signal_queue;
6565
ZEND_END_MODULE_GLOBALS(pcntl)
66-
6766
#ifdef ZTS
68-
#define PCNTL_G(v) (pcntl_globals->v)
69-
#define PCNTL_LS_FETCH() zend_pcntl_globals *pcntl_globals = ts_resource(pcntl_globals_id)
67+
# define PCNTL_G(v) TSRMG(pcntl_globals_id, zend_pcntl_globals *, v)
7068
#else
71-
#define PCNTL_G(v) (pcntl_globals.v)
72-
#define PCNTL_LS_FETCH()
69+
# define PCNTL_G(v) (pcntl_globals.v)
7370
#endif
7471

7572
#endif /* PHP_PCNTL_H */

0 commit comments

Comments
 (0)