Пример #1
0
/* {{{ allocate state object */
pthreads_state pthreads_state_alloc(int mask TSRMLS_DC) {
	pthreads_state state = calloc(1, sizeof(*state));
	if (state != NULL) {
		state->bits |= mask;
		if (!(state->lock = pthreads_lock_alloc(TSRMLS_C)))
			return NULL;
		if (!(state->synchro = pthreads_synchro_alloc(TSRMLS_C)))
			return NULL;
		return state;
	}
	return NULL;
} /* }}} */
Пример #2
0
/* {{{ allocate (and initialize) a synchronization object */
pthreads_synchro pthreads_synchro_alloc(TSRMLS_D) {
	pthreads_synchro sync = (pthreads_synchro) calloc(1, sizeof(*sync));
	
	if (sync) {
		if ((sync->lock = pthreads_lock_alloc(TSRMLS_C))) {
			if (pthread_cond_init(&sync->notify, NULL)==SUCCESS) {
				return sync;
			}
			pthreads_lock_free(sync->lock TSRMLS_CC);
		}
		free(sync);
	}
	
	return NULL;
} /* }}} */
Пример #3
0
/* {{{ pthreads_globals_init */
zend_bool pthreads_globals_init(TSRMLS_D){
	if (!PTHREADS_G(init)&&!PTHREADS_G(failed)) {
		PTHREADS_G(init)=1;
		if (!(PTHREADS_G(lock)=pthreads_lock_alloc(PTHREADS_GTSRMLS_C)))
			PTHREADS_G(failed)=1;
		if (PTHREADS_G(failed)) {
		    PTHREADS_G(init)=0;
		} else {
		    zend_hash_init(
		        &PTHREADS_G(strings), 64, NULL, (dtor_func_t) pthreads_global_string_free, 1);
		}
			
		return PTHREADS_G(init);
	} else return 0;
} /* }}} */
Пример #4
0
/* {{{ allocate storage for an object */
pthreads_store pthreads_store_alloc(TSRMLS_D) {
    pthreads_store store = malloc(sizeof(*store));

    if (store) {
        if (zend_hash_init(&store->table, 8, NULL, (dtor_func_t) pthreads_store_storage_dtor, 1)==SUCCESS) {
            if ((store->lock = pthreads_lock_alloc(TSRMLS_C))) {
                store->next = 0L;

                return store;
            }
            zend_hash_destroy(&store->table);
        }
        free(store);
    }
    return NULL;
} /* }}} */