From d11cc41bc7f00c61a3d45753c8b2c84c85e6e7fa Mon Sep 17 00:00:00 2001 From: Joe Watkins Date: Thu, 26 Nov 2015 09:50:59 +0000 Subject: [PATCH] fix inability to run gc, highlighted by polyfill --- classes/worker.h | 2 +- src/stack.c | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/classes/worker.h b/classes/worker.h index 2496c893..8cfebb97 100644 --- a/classes/worker.h +++ b/classes/worker.h @@ -165,7 +165,7 @@ static zend_bool pthreads_worker_running_function(zend_object *std, zval *value) zend_bool result = 0; if (pthreads_monitor_lock(worker->monitor)) { - if (worker->running) { + if (*worker->running) { running = PTHREADS_FETCH_FROM(*worker->running); checking = PTHREADS_FETCH_FROM(Z_OBJ_P(value)); diff --git a/src/stack.c b/src/stack.c index 3b249ee4..cc45b4fb 100644 --- a/src/stack.c +++ b/src/stack.c @@ -226,23 +226,24 @@ zend_long pthreads_stack_collect(zend_object *std, pthreads_stack_t *stack, pthr pthreads_monitor_state_t pthreads_stack_next(pthreads_stack_t *stack, zval *value, zend_object **running) { pthreads_monitor_state_t state = PTHREADS_MONITOR_RUNNING; if (pthreads_monitor_lock(stack->monitor)) { +#define SET_RUNNING_TO(t) *running = t do { if (!stack->head) { - if (pthreads_monitor_check(stack->monitor, PTHREADS_MONITOR_JOINED)) { state = PTHREADS_MONITOR_JOINED; + SET_RUNNING_TO(NULL); break; } - + + SET_RUNNING_TO(NULL); pthreads_monitor_wait(stack->monitor, 0); } else { pthreads_stack_remove(stack, stack->head, value, PTHREADS_STACK_GARBAGE); - *running = - Z_OBJ_P(value); + SET_RUNNING_TO(Z_OBJ_P(value)); break; } } while (state != PTHREADS_MONITOR_JOINED); - +#undef SET_RUNNING_TO pthreads_monitor_unlock(stack->monitor); }