Beispiel #1
0
/* {{{ push an item onto the work buffer */
int pthreads_stack_push(PTHREAD thread, PTHREAD work TSRMLS_DC) {
	int acquire = 0;
	int counted = -1;
	
	acquire = pthread_mutex_lock(thread->lock);
	if (acquire == SUCCESS || acquire == EDEADLK) {
		zend_llist *stack = &thread->stack->objects;
		if (stack) {
			zend_llist_add_element(
				stack, &work
			);
			counted = stack->count;
		} else counted = -1;
		if (acquire != EDEADLK)
			pthread_mutex_unlock(thread->lock);
	} else zend_error(E_ERROR, "pthreads has suffered an internal error and cannot continue: %d", acquire);
	
	if (counted > 0) {
		if (pthreads_state_isset(thread->state, PTHREADS_ST_WAITING TSRMLS_CC)) {
			pthreads_unset_state(thread, PTHREADS_ST_WAITING TSRMLS_CC);
		}
	}
	
	return counted;
} /* }}} */
Beispiel #2
0
/* {{{ push an item onto the work buffer */
size_t pthreads_stack_push(PTHREAD thread, PTHREAD work TSRMLS_DC) {
    zend_bool locked;
    size_t counted = 0L;

    if (pthreads_lock_acquire(thread->lock, &locked TSRMLS_CC)) {
        zend_llist *stack = &thread->stack->objects;
        if (stack) {
            zend_llist_add_element(
                stack, &work
            );
            counted = stack->count;
        }
        pthreads_lock_release(thread->lock, locked TSRMLS_CC);

        if (counted > 0L) {
            if (pthreads_state_isset(thread->state, PTHREADS_ST_WAITING TSRMLS_CC)) {
                pthreads_unset_state(thread, PTHREADS_ST_WAITING TSRMLS_CC);
            }
        }
    }

    return counted;
} /* }}} */