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

Commit

Permalink
add notifyOne, fix return value of notify/notifyOne
Browse files Browse the repository at this point in the history
  • Loading branch information
krakjoe committed Feb 8, 2016
1 parent ff9f872 commit 7870165
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
14 changes: 13 additions & 1 deletion classes/threaded.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
PHP_METHOD(Threaded, run);
PHP_METHOD(Threaded, wait);
PHP_METHOD(Threaded, notify);
PHP_METHOD(Threaded, notifyOne);
PHP_METHOD(Threaded, isRunning);
PHP_METHOD(Threaded, isTerminated);

Expand Down Expand Up @@ -96,6 +97,7 @@ zend_function_entry pthreads_threaded_methods[] = {
PHP_ME(Threaded, run, Threaded_run, ZEND_ACC_PUBLIC)
PHP_ME(Threaded, wait, Threaded_wait, ZEND_ACC_PUBLIC)
PHP_ME(Threaded, notify, Threaded_notify, ZEND_ACC_PUBLIC)
PHP_ME(Threaded, notifyOne, Threaded_notify, ZEND_ACC_PUBLIC)
PHP_ME(Threaded, isRunning, Threaded_isRunning, ZEND_ACC_PUBLIC)
PHP_ME(Threaded, isTerminated, Threaded_isTerminated, ZEND_ACC_PUBLIC)
PHP_ME(Threaded, synchronized, Threaded_synchronized, ZEND_ACC_PUBLIC)
Expand Down Expand Up @@ -141,7 +143,17 @@ PHP_METHOD(Threaded, notify)
{
pthreads_object_t* threaded = PTHREADS_FETCH;

RETURN_BOOL(pthreads_monitor_notify(threaded->monitor));
RETURN_BOOL(pthreads_monitor_notify(threaded->monitor) == SUCCESS);
} /* }}} */

/* {{{ proto boolean Threaded::notifyOne()
Send notification to one context waiting on the Threaded
Will return a boolean indication of success */
PHP_METHOD(Threaded, notifyOne)
{
pthreads_object_t* threaded = PTHREADS_FETCH;

RETURN_BOOL(pthreads_monitor_notify_one(threaded->monitor) == SUCCESS);
} /* }}} */

/* {{{ proto boolean Threaded::isRunning()
Expand Down
4 changes: 4 additions & 0 deletions src/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ int pthreads_monitor_notify(pthreads_monitor_t *m) {
return pthread_cond_broadcast(&m->cond);
}

int pthreads_monitor_notify_one(pthreads_monitor_t *m) {
return pthread_cond_signal(&m->cond);
}

void pthreads_monitor_wait_until(pthreads_monitor_t *m, pthreads_monitor_state_t state) {
if (pthreads_monitor_lock(m)) {
while (!pthreads_monitor_check(m, state)) {
Expand Down
1 change: 1 addition & 0 deletions src/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ zend_bool pthreads_monitor_unlock(pthreads_monitor_t *m);
pthreads_monitor_state_t pthreads_monitor_check(pthreads_monitor_t *m, pthreads_monitor_state_t state);
int pthreads_monitor_wait(pthreads_monitor_t *m, long timeout);
int pthreads_monitor_notify(pthreads_monitor_t *m);
int pthreads_monitor_notify_one(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);
Expand Down

0 comments on commit 7870165

Please sign in to comment.