Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Commit

Permalink
better #481
Browse files Browse the repository at this point in the history
  • Loading branch information
krakjoe committed Sep 7, 2015
1 parent 75f813d commit 88791b3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
19 changes: 17 additions & 2 deletions src/monitor.c
Expand Up @@ -92,9 +92,24 @@ int pthreads_monitor_notify(pthreads_monitor_t *m) {
}

void pthreads_monitor_wait_until(pthreads_monitor_t *m, pthreads_monitor_state_t state) {
while (!pthreads_monitor_check(m, state)) {
pthreads_monitor_wait(m, 0);
if (!pthreads_monitor_lock(m)) {
return;
}

if (!pthreads_monitor_check(m, state)) {
if (pthreads_monitor_wait(m, 0) != 0) {
pthreads_monitor_unlock(m);
return;
}
pthreads_monitor_unlock(m);
pthreads_monitor_wait_until(m, state);
}

pthreads_monitor_unlock(m);
}

void pthreads_monitor_set(pthreads_monitor_t *m, pthreads_monitor_state_t state) {
m->state |= state;
}

void pthreads_monitor_add(pthreads_monitor_t *m, pthreads_monitor_state_t state) {
Expand Down
1 change: 1 addition & 0 deletions src/monitor.h
Expand Up @@ -37,6 +37,7 @@ int pthreads_monitor_wait(pthreads_monitor_t *m, long timeout);
int pthreads_monitor_notify(pthreads_monitor_t *m);
void pthreads_monitor_wait_until(pthreads_monitor_t *m, pthreads_monitor_state_t state);
void pthreads_monitor_add(pthreads_monitor_t *m, pthreads_monitor_state_t state);
void pthreads_monitor_set(pthreads_monitor_t *m, pthreads_monitor_state_t state);
void pthreads_monitor_remove(pthreads_monitor_t *m, pthreads_monitor_state_t state);
void pthreads_monitor_free(pthreads_monitor_t *m);
#endif
6 changes: 1 addition & 5 deletions src/object.c
Expand Up @@ -215,7 +215,7 @@ int pthreads_connect(pthreads_object_t* source, pthreads_object_t* destination)
destination->local.ls = source->local.ls;
destination->monitor = source->monitor;
destination->store = source->store;
destination->stack = source->stack;
destination->stack = source->stack;

return SUCCESS;
} else return FAILURE;
Expand Down Expand Up @@ -279,8 +279,6 @@ static void pthreads_base_ctor(pthreads_object_t* base, zend_class_entry *entry)
void pthreads_base_free(zend_object *object) {
pthreads_object_t* base = PTHREADS_FETCH_FROM(object);

HANDLE_BLOCK_INTERRUPTIONS();

if (PTHREADS_IS_NOT_CONNECTION(base)) {
if ((PTHREADS_IS_THREAD(base)||PTHREADS_IS_WORKER(base)) &&
!pthreads_monitor_check(base->monitor, PTHREADS_MONITOR_JOINED)) {
Expand All @@ -301,8 +299,6 @@ void pthreads_base_free(zend_object *object) {
zend_object_std_dtor(object);

pthreads_globals_object_delete(base);

HANDLE_UNBLOCK_INTERRUPTIONS();
} /* }}} */

/* {{{ */
Expand Down
4 changes: 3 additions & 1 deletion src/prepare.c
Expand Up @@ -575,9 +575,11 @@ static inline void pthreads_prepare_sapi(pthreads_object_t* thread) {
#ifdef PTHREADS_KILL_SIGNAL
static inline void pthreads_kill_handler(int signo) /* {{{ */
{
ZEND_TSRMLS_CACHE_UPDATE();

pthreads_object_t* current = PTHREADS_FETCH_FROM(Z_OBJ(PTHREADS_ZG(this)));

pthreads_monitor_add(
pthreads_monitor_set(
current->monitor, PTHREADS_MONITOR_ERROR);

PTHREADS_ZG(signal) = signo;
Expand Down
1 change: 0 additions & 1 deletion tests/killed-info.phpt
Expand Up @@ -17,7 +17,6 @@ class Test extends Thread
$t = new Test();
$t->start();
$t->kill();
$t->join();

var_dump($t->isTerminated());
?>
Expand Down

0 comments on commit 88791b3

Please sign in to comment.