Esempio n. 1
0
/* {{{ set state bits on a thread, timeout where appropriate/required */
zend_bool pthreads_set_state_ex(PTHREAD thread, int mask, long timeout TSRMLS_DC) {
    zend_bool locked, dowait, result;
    if (mask & PTHREADS_ST_WAITING) {
        if (pthreads_state_lock(thread->state, &locked TSRMLS_CC)) {
            dowait = !pthreads_state_check(thread->state, PTHREADS_ST_JOINED TSRMLS_CC);
            if (dowait)
                pthreads_state_set_locked(thread->state, PTHREADS_ST_WAITING TSRMLS_CC);
            if (locked)
                pthreads_state_unlock(thread->state, locked TSRMLS_CC);
            if (dowait) {
                result = pthreads_synchro_wait_ex(
                             thread->synchro, timeout TSRMLS_CC
                         );
            } else result = 0;
        } else result = 0;
    } else result = pthreads_state_set(thread->state, mask TSRMLS_CC);
    return result;
} /* }}} */
Esempio n. 2
0
/* {{{ set state bits on a thread, timeout where appropriate/required */
int pthreads_set_state_ex(PTHREAD thread, int mask, long timeout TSRMLS_DC) {
	int result = 0;
	
	if (mask & PTHREADS_ST_WAITING) {
		int slocked = pthreads_state_lock(thread->state TSRMLS_CC);
		int dowait = 0;
		if (slocked == SUCCESS ||slocked == EDEADLK) {
			dowait = !pthreads_state_check(thread->state, PTHREADS_ST_JOINED TSRMLS_CC);
			if (dowait)
				pthreads_state_set_locked(thread->state, PTHREADS_ST_WAITING TSRMLS_CC);
			if (slocked != EDEADLK)
				pthreads_state_unlock(thread->state TSRMLS_CC);
			if (dowait) {
				result = pthreads_synchro_wait_ex(
					thread->synchro, timeout TSRMLS_CC
				);
			} else result = 0;
		} else result = 0;
	} else result = pthreads_state_set(thread->state, mask TSRMLS_CC);
	return result;
} /* }}} */