svn_error_t * svn_fs_initialize(apr_pool_t *pool) { #if APR_HAS_THREADS apr_status_t status; #endif /* Protect against multiple calls. */ if (common_pool) return SVN_NO_ERROR; common_pool = svn_pool_create(pool); #if APR_HAS_THREADS status = apr_thread_mutex_create(&common_pool_lock, APR_THREAD_MUTEX_DEFAULT, common_pool); if (status) return svn_error_wrap_apr(status, _("Can't allocate FS mutex")); #endif /* ### This won't work if POOL is NULL and libsvn_fs is loaded as a DSO ### (via libsvn_ra_local say) since the global common_pool will live ### longer than the DSO, which gets unloaded when the pool used to ### load it is cleared, and so when the handler runs it will refer to ### a function that no longer exists. libsvn_ra_local attempts to ### work around this by explicitly calling svn_fs_initialize. */ apr_pool_cleanup_register(common_pool, NULL, uninit, apr_pool_cleanup_null); return SVN_NO_ERROR; }
/* * Dynamic lock creation callback */ static struct CRYPTO_dynlock_value *ssl_dyn_create_function(const char *file, int line) { struct CRYPTO_dynlock_value *value; apr_pool_t *p; apr_status_t rv; /* * We need a pool to allocate our mutex. Since we can't clear * allocated memory from a pool, create a subpool that we can blow * away in the destruction callback. */ apr_pool_create(&p, dynlockpool); ap_log_perror(file, line, APLOG_MODULE_INDEX, APLOG_TRACE1, 0, p, "Creating dynamic lock"); value = apr_palloc(p, sizeof(struct CRYPTO_dynlock_value)); value->pool = p; /* Keep our own copy of the place from which we were created, using our own pool. */ value->file = apr_pstrdup(p, file); value->line = line; rv = apr_thread_mutex_create(&(value->mutex), APR_THREAD_MUTEX_DEFAULT, p); if (rv != APR_SUCCESS) { ap_log_perror(file, line, APLOG_MODULE_INDEX, APLOG_ERR, rv, p, APLOGNO(02186) "Failed to create thread mutex for dynamic lock"); apr_pool_destroy(p); return NULL; } return value; }
void ssl_util_thread_setup(apr_pool_t *p) { int i; lock_num_locks = CRYPTO_num_locks(); lock_cs = apr_palloc(p, lock_num_locks * sizeof(*lock_cs)); for (i = 0; i < lock_num_locks; i++) { apr_thread_mutex_create(&(lock_cs[i]), APR_THREAD_MUTEX_DEFAULT, p); } CRYPTO_set_id_callback(ssl_util_thr_id); CRYPTO_set_locking_callback(ssl_util_thr_lock); /* Set up dynamic locking scaffolding for OpenSSL to use at its * convenience. */ dynlockpool = p; CRYPTO_set_dynlock_create_callback(ssl_dyn_create_function); CRYPTO_set_dynlock_lock_callback(ssl_dyn_lock_function); CRYPTO_set_dynlock_destroy_callback(ssl_dyn_destroy_function); apr_pool_cleanup_register(p, NULL, ssl_util_thread_cleanup, apr_pool_cleanup_null); }
static apr_status_t wd_startup(ap_watchdog_t *w, apr_pool_t *p) { apr_status_t rc; /* Create thread startup mutex */ rc = apr_thread_mutex_create(&w->startup, APR_THREAD_MUTEX_UNNESTED, p); if (rc != APR_SUCCESS) return rc; if (w->singleton) { /* Initialize singleton mutex in child */ rc = apr_proc_mutex_child_init(&w->mutex, apr_proc_mutex_lockfile(w->mutex), p); if (rc != APR_SUCCESS) return rc; } /* This mutex fixes problems with a fast start/fast end, where the pool * cleanup was being invoked before the thread completely spawned. */ apr_thread_mutex_lock(w->startup); apr_pool_pre_cleanup_register(p, w, wd_worker_cleanup); /* Start the newly created watchdog */ rc = apr_thread_create(&w->thread, NULL, wd_worker, w, p); if (rc) { apr_pool_cleanup_kill(p, w, wd_worker_cleanup); } apr_thread_mutex_lock(w->startup); apr_thread_mutex_unlock(w->startup); apr_thread_mutex_destroy(w->startup); return rc; }
static void * dav_rainx_merge_server_config(apr_pool_t *p, void *base, void *overrides) { (void) base; dav_rainx_server_conf *child; dav_rainx_server_conf *newconf; DAV_XDEBUG_POOL(p, 0, "%s()", __FUNCTION__); child = overrides; newconf = apr_pcalloc(p, sizeof(*newconf)); newconf->pool = p; newconf->cleanup = NULL; newconf->hash_depth = child->hash_depth; newconf->hash_width = child->hash_width; newconf->fsync_on_close = child->fsync_on_close; newconf->headers_scheme = child->headers_scheme; newconf->FILE_buffer_size = child->FILE_buffer_size; memcpy(newconf->docroot, child->docroot, sizeof(newconf->docroot)); memcpy(newconf->ns_name, child->ns_name, sizeof(newconf->ns_name)); apr_thread_mutex_create(&(newconf->rainx_conf_lock), APR_THREAD_MUTEX_DEFAULT, newconf->pool); update_rainx_conf(p, &(newconf->rainx_conf), newconf->ns_name); DAV_DEBUG_POOL(p, 0, "Configuration merged!"); return newconf; }
MPF_DECLARE(struct mpf_dtmf_generator_t *) mpf_dtmf_generator_create_ex( const struct mpf_audio_stream_t *stream, enum mpf_dtmf_generator_band_e band, apr_uint32_t tone_ms, apr_uint32_t silence_ms, struct apr_pool_t *pool) { struct mpf_dtmf_generator_t *gen; apr_status_t status; int flg_band = band; if (!stream->rx_descriptor) flg_band &= ~MPF_DTMF_GENERATOR_INBAND; if (!stream->rx_event_descriptor) flg_band &= ~MPF_DTMF_GENERATOR_OUTBAND; if (!flg_band) return NULL; gen = apr_palloc(pool, sizeof(struct mpf_dtmf_generator_t)); if (!gen) return NULL; status = apr_thread_mutex_create(&gen->mutex, APR_THREAD_MUTEX_DEFAULT, pool); if (status != APR_SUCCESS) return NULL; gen->band = (enum mpf_dtmf_generator_band_e) flg_band; gen->queue[0] = 0; gen->state = DTMF_GEN_STATE_IDLE; if (stream->rx_descriptor) gen->sample_rate_audio = stream->rx_descriptor->sampling_rate; gen->sample_rate_events = stream->rx_event_descriptor ? stream->rx_event_descriptor->sampling_rate : gen->sample_rate_audio; gen->frame_duration = gen->sample_rate_events / 1000 * CODEC_FRAME_TIME_BASE; gen->tone_duration = gen->sample_rate_events / 1000 * tone_ms; gen->silence_duration = gen->sample_rate_events / 1000 * silence_ms; gen->events_ptime = CODEC_FRAME_TIME_BASE; /* Should be got from event_descriptor */ return gen; }
skiplist_t *create_skiplist_full(int maxlevels, double p, int allow_dups, skiplist_compare_t *compare, skiplist_key_t *(*dup)(skiplist_key_t *a), void (*key_free)(skiplist_key_t *a), void (*data_free)(skiplist_data_t *a)) { skiplist_t *sl = (skiplist_t *)malloc(sizeof(skiplist_t)); assert(sl != NULL); { int result = apr_pool_create(&(sl->pool), NULL); assert(result == APR_SUCCESS); } { int result = apr_thread_mutex_create(&(sl->lock), APR_THREAD_MUTEX_DEFAULT, sl->pool); assert(result == APR_SUCCESS); } sl->n_keys = 0; sl->n_ele = 0; sl->current_max = 0; sl->max_levels = maxlevels; sl->p = p; sl->allow_dups = allow_dups; sl->compare = compare; sl->dup = (dup == NULL) ? sl_passthru_dup : dup; sl->key_free = (key_free == NULL) ? sl_no_key_free : key_free; sl->data_free = (data_free == NULL) ? sl_no_data_free : data_free; sl->head = create_skiplist_node(maxlevels-1); return(sl); }
static apr_dbd_t *dbd_sqlite3_open(apr_pool_t *pool, const char *params) { apr_dbd_t *sql = NULL; sqlite3 *conn = NULL; apr_status_t res; int sqlres; if (!params) return NULL; sqlres = sqlite3_open(params, &conn); if (sqlres != SQLITE_OK) { sqlite3_close(conn); return NULL; } /* should we register rand or power functions to the sqlite VM? */ sql = apr_pcalloc(pool, sizeof(*sql)); sql->conn = conn; sql->pool = pool; sql->trans = NULL; #if APR_HAS_THREADS /* Create a mutex */ res = apr_thread_mutex_create(&sql->mutex, APR_THREAD_MUTEX_DEFAULT, pool); if (res != APR_SUCCESS) { return NULL; } #endif return sql; }
static apr_status_t impl_pollset_create(apr_pollset_t *pollset, apr_uint32_t size, apr_pool_t *p, apr_uint32_t flags) { apr_status_t rv; int fd; #ifdef HAVE_EPOLL_CREATE1 fd = epoll_create1(EPOLL_CLOEXEC); #else fd = epoll_create(size); #endif if (fd < 0) { pollset->p = NULL; return apr_get_netos_error(); } #ifndef HAVE_EPOLL_CREATE1 { int flags; if ((flags = fcntl(fd, F_GETFD)) == -1) return errno; flags |= FD_CLOEXEC; if (fcntl(fd, F_SETFD, flags) == -1) return errno; } #endif pollset->p = apr_palloc(p, sizeof(apr_pollset_private_t)); #if APR_HAS_THREADS if ((flags & APR_POLLSET_THREADSAFE) && !(flags & APR_POLLSET_NOCOPY) && ((rv = apr_thread_mutex_create(&pollset->p->ring_lock, APR_THREAD_MUTEX_DEFAULT, p)) != APR_SUCCESS)) { pollset->p = NULL; return rv; } #else if (flags & APR_POLLSET_THREADSAFE) { pollset->p = NULL; return APR_ENOTIMPL; } #endif pollset->p->epoll_fd = fd; pollset->p->pollset = apr_palloc(p, size * sizeof(struct epoll_event)); pollset->p->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); if (!(flags & APR_POLLSET_NOCOPY)) { APR_RING_INIT(&pollset->p->query_ring, pfd_elem_t, link); APR_RING_INIT(&pollset->p->free_ring, pfd_elem_t, link); APR_RING_INIT(&pollset->p->dead_ring, pfd_elem_t, link); } return APR_SUCCESS; }
void ll_init_apr() { if (!gAPRPoolp) { // Initialize APR and create the global pool apr_initialize(); apr_pool_create(&gAPRPoolp, NULL); // Initialize the logging mutex apr_thread_mutex_create(&gLogMutexp, APR_THREAD_MUTEX_UNNESTED, gAPRPoolp); apr_thread_mutex_create(&gCallStacksLogMutexp, APR_THREAD_MUTEX_UNNESTED, gAPRPoolp); } if(!LLAPRFile::sAPRFilePoolp) { LLAPRFile::sAPRFilePoolp = new LLVolatileAPRPool(FALSE) ; } }
void _log_init() { int n; atomic_init(); assert(apr_pool_create(&_log_mpool, NULL) == APR_SUCCESS); assert(apr_thread_mutex_create(&_log_lock, APR_THREAD_MUTEX_DEFAULT, _log_mpool) == APR_SUCCESS); for (n=0; n<_mlog_size; n++) { _mlog_table[n]=20; _mlog_file_table[n] = "";} }
tbx_ns_t *tbx_ns_new() { tbx_ns_t *ns = (tbx_ns_t *)malloc(sizeof(tbx_ns_t)); if (ns == NULL) { log_printf(0, "new_netstream: Failed malloc!!\n"); abort(); } assert_result(apr_pool_create(&(ns->mpool), NULL), APR_SUCCESS); apr_thread_mutex_create(&(ns->read_lock), APR_THREAD_MUTEX_DEFAULT,ns->mpool); apr_thread_mutex_create(&(ns->write_lock), APR_THREAD_MUTEX_DEFAULT,ns->mpool); _ns_init(ns, 0); ns->id = ns->cuid = -1; return(ns); }
APU_DECLARE(apr_status_t) apr_dbd_init(apr_pool_t *pool) { apr_status_t ret = APR_SUCCESS; apr_pool_t *parent; if (drivers != NULL) { return APR_SUCCESS; } /* Top level pool scope, need process-scope lifetime */ for (parent = pool; parent; parent = apr_pool_parent_get(pool)) pool = parent; #if APU_DSO_BUILD /* deprecate in 2.0 - permit implicit initialization */ apu_dso_init(pool); #endif drivers = apr_hash_make(pool); #if APR_HAS_THREADS ret = apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_DEFAULT, pool); /* This already registers a pool cleanup */ #endif #if !APU_DSO_BUILD /* Load statically-linked drivers: */ #if APU_HAVE_MYSQL DRIVER_LOAD("mysql", apr_dbd_mysql_driver, pool); #endif #if APU_HAVE_PGSQL DRIVER_LOAD("pgsql", apr_dbd_pgsql_driver, pool); #endif #if APU_HAVE_SQLITE3 DRIVER_LOAD("sqlite3", apr_dbd_sqlite3_driver, pool); #endif #if APU_HAVE_SQLITE2 DRIVER_LOAD("sqlite2", apr_dbd_sqlite2_driver, pool); #endif #if APU_HAVE_ORACLE DRIVER_LOAD("oracle", apr_dbd_oracle_driver, pool); #endif #if APU_HAVE_FREETDS DRIVER_LOAD("freetds", apr_dbd_freetds_driver, pool); #endif #if APU_HAVE_ODBC DRIVER_LOAD("odbc", apr_dbd_odbc_driver, pool); #endif #if APU_HAVE_SOME_OTHER_BACKEND DRIVER_LOAD("firebird", apr_dbd_other_driver, pool); #endif #endif /* APU_DSO_BUILD */ apr_pool_cleanup_register(pool, NULL, apr_dbd_term, apr_pool_cleanup_null); return ret; }
void * y_create (y_Runtime *rt, const void * class_type, y_Error ** error) { y_Object * obj = NULL; apr_pool_t * pool = NULL; pool = y_Runtime_create_object_pool (rt, error); if ( error && *error ) goto cleanup; obj = apr_pcalloc (pool, ((y_ObjectClass *)class_type)->instance_size); obj->type = (void *)class_type; obj->protect = apr_pcalloc (pool, ((y_ObjectClass *)class_type)->protected_size); obj->protect->rt = rt; obj->protect->pool = pool; #if APR_HAS_THREADS if ( y_Runtime_is_threadsafe (rt) ) { if ( y_Error_throw_apr (rt, error, __FILE__, __LINE__, apr_thread_mutex_create (&(obj->protect->mutex), APR_THREAD_MUTEX_DEFAULT, pool)) ) goto cleanup; apr_pool_cleanup_register (pool, obj->protect->mutex, (apr_status_t (*)(void *))apr_thread_mutex_destroy, NULL); } #endif /* APR_HAS_THREADS */ obj->protect->refcount = 1; obj->protect->weak_ref = NULL; y_InitMethodList * init = ((y_ObjectClass *)class_type)->init; if ( init ) { int i; for ( i = 0; i < init->size; i++ ) { struct y_InitMethod method = init->methods[i]; if ( y_bless (obj, method.type ) ) { method.exec (obj, error); if ( error && *error ) { goto cleanup; } } } } obj->type = (void *)class_type; apr_pool_cleanup_register (pool, obj, y_cleanup_of_last_resort, NULL); return obj; /* Failure: just delete underlying pool and return NULL */ cleanup: if ( pool ) y_Runtime_free_object_pool (obj->protect->rt, obj->protect->pool); return NULL; }
mpf_buffer_t* mpf_buffer_create(apr_pool_t *pool) { mpf_buffer_t *buffer = apr_palloc(pool,sizeof(mpf_buffer_t)); buffer->pool = pool; buffer->cur_chunk = NULL; buffer->remaining_chunk_size = 0; APR_RING_INIT(&buffer->head, mpf_chunk_t, link); apr_thread_mutex_create(&buffer->guard,APR_THREAD_MUTEX_UNNESTED,pool); return buffer; }
int slayer_server_log_open(slayer_server_log_manager_t **_manager,const char *filename, int nentries, apr_pool_t *mpool) { apr_status_t status; apr_pool_t *logpool; apr_pool_create(&logpool,mpool); slayer_server_log_manager_t *manager = *_manager = apr_pcalloc(logpool,sizeof(slayer_server_log_manager_t)); manager->mpool = logpool; //only create if there is a non-null filename passed in if (filename) { status = apr_thread_mutex_create(&manager->file_mutex,APR_THREAD_MUTEX_DEFAULT,manager->mpool); status = apr_file_open(&manager->fhandle,filename,APR_CREATE | APR_WRITE | APR_APPEND | APR_BUFFERED,APR_OS_DEFAULT,manager->mpool); } status = apr_thread_mutex_create(&manager->list_mutex,APR_THREAD_MUTEX_DEFAULT,manager->mpool); manager->nentries = nentries; manager->entries = apr_pcalloc(manager->mpool,sizeof(query_entry_t)*nentries); return status; }
void view_init() { apr_pool_create(&mp_view_, NULL); gid_nid_ht_ht_ = apr_hash_make(mp_view_); nid_gid_ht_ht_ = apr_hash_make(mp_view_); arr_nodes_ = apr_array_make(mp_view_, 10, sizeof(nodeid_t)); ht_view_ = apr_hash_make(mp_view_); apr_thread_mutex_create(&mx_view_, APR_THREAD_MUTEX_UNNESTED, mp_view_); mpr_hash_create(&ht_node_info_); }
static void thread_init(CuTest *tc) { apr_status_t rv; rv = apr_thread_once_init(&control, p); CuAssertIntEquals(tc, APR_SUCCESS, rv); rv = apr_thread_mutex_create(&thread_lock, APR_THREAD_MUTEX_DEFAULT, p); CuAssertIntEquals(tc, APR_SUCCESS, rv); }
void accp_info_create(accp_info_t **a, instid_t iid) { *a = (accp_info_t *)malloc(sizeof(accp_info_t)); accp_info_t *ainfo = *a; ainfo->iid = iid; ainfo->bid_max = 0; apr_pool_create(&ainfo->mp, NULL); ainfo->arr_prop = apr_array_make(ainfo->mp, 0, sizeof(proposal_t *)); apr_hash_set(ht_accp_info_, &ainfo->iid, sizeof(instid_t), ainfo); apr_thread_mutex_create(&ainfo->mx, APR_THREAD_MUTEX_UNNESTED, ainfo->mp); }
/* Create the audio queue. */ int audio_queue_create(audio_queue_t **audio_queue, const char *name) { int status = 0; audio_queue_t *laudio_queue = NULL; char *lname = ""; apr_pool_t *pool; if (audio_queue == NULL) return -1; else *audio_queue = NULL; if ((pool = apt_pool_create()) == NULL) return -1; if ((name == NULL) || (strlen(name) == 0)) lname = ""; else lname = apr_pstrdup(pool, name); if (lname == NULL) lname = ""; if ((laudio_queue = (audio_queue_t *)apr_palloc(pool, sizeof(audio_queue_t))) == NULL) { ast_log(LOG_ERROR, "(%s) Unable to create audio queue\n", lname); return -1; } else { laudio_queue->buffer = NULL; laudio_queue->cond = NULL; laudio_queue->mutex = NULL; laudio_queue->name = lname; laudio_queue->pool = pool; laudio_queue->read_bytes = 0; laudio_queue->waiting = 0; laudio_queue->write_bytes = 0; if (audio_buffer_create(&laudio_queue->buffer, AUDIO_QUEUE_SIZE) != 0) { ast_log(LOG_ERROR, "(%s) Unable to create audio queue buffer\n", laudio_queue->name); status = -1; } else if (apr_thread_mutex_create(&laudio_queue->mutex, APR_THREAD_MUTEX_UNNESTED, pool) != APR_SUCCESS) { ast_log(LOG_ERROR, "(%s) Unable to create audio queue mutex\n", laudio_queue->name); status = -1; } else if (apr_thread_cond_create(&laudio_queue->cond, pool) != APR_SUCCESS) { ast_log(LOG_ERROR, "(%s) Unable to create audio queue condition variable\n", laudio_queue->name); status = -1; } else { *audio_queue = laudio_queue; ast_log(LOG_DEBUG, "(%s) Audio queue created\n", laudio_queue->name); } } if (status != 0) audio_queue_destroy(laudio_queue); return status; }
void gop_dummy_init() { //** Make the variables assert_result(apr_pool_create(&gd_pool, NULL), APR_SUCCESS); assert_result(apr_thread_mutex_create(&gd_lock, APR_THREAD_MUTEX_DEFAULT, gd_pool), APR_SUCCESS); assert_result(apr_thread_cond_create(&gd_cond, gd_pool), APR_SUCCESS); gd_stack = new_stack(); //** and launch the thread thread_create_assert(&gd_thread, NULL, gd_thread_func, NULL, gd_pool); }
static void mod_mapcache_child_init(apr_pool_t *pool, server_rec *s) { int threaded; pchild = pool; #ifdef APR_HAS_THREADS ap_mpm_query(AP_MPMQ_IS_THREADED,&threaded); if(threaded) { apr_thread_mutex_create(&thread_mutex,APR_THREAD_MUTEX_DEFAULT,pool); } #endif }
/** * Configuration and start-up */ static int mem_cache_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { /* Sanity check the cache configuration */ if (sconf->min_cache_object_size >= sconf->max_cache_object_size) { ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "MCacheMaxObjectSize must be greater than MCacheMinObjectSize"); return DONE; } if (sconf->max_cache_object_size >= sconf->max_cache_size) { ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "MCacheSize must be greater than MCacheMaxObjectSize"); return DONE; } if (sconf->max_streaming_buffer_size > sconf->max_cache_object_size) { /* Issue a notice only if something other than the default config * is being used */ if (sconf->max_streaming_buffer_size != DEFAULT_MAX_STREAMING_BUFFER_SIZE && sconf->max_cache_object_size != DEFAULT_MAX_CACHE_OBJECT_SIZE) { ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, "MCacheMaxStreamingBuffer must be less than or equal to MCacheMaxObjectSize. " "Resetting MCacheMaxStreamingBuffer to MCacheMaxObjectSize."); } sconf->max_streaming_buffer_size = sconf->max_cache_object_size; } if (sconf->max_streaming_buffer_size < sconf->min_cache_object_size) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "MCacheMaxStreamingBuffer must be greater than or equal to MCacheMinObjectSize. " "Resetting MCacheMaxStreamingBuffer to MCacheMinObjectSize."); sconf->max_streaming_buffer_size = sconf->min_cache_object_size; } ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm); if (threaded_mpm) { apr_thread_mutex_create(&sconf->lock, APR_THREAD_MUTEX_DEFAULT, p); } sconf->cache_cache = cache_init(sconf->max_object_cnt, sconf->max_cache_size, memcache_get_priority, sconf->cache_remove_algorithm, memcache_get_pos, memcache_set_pos, memcache_inc_frequency, memcache_cache_get_size, memcache_cache_get_key, memcache_cache_free); apr_pool_cleanup_register(p, sconf, cleanup_cache_mem, apr_pool_cleanup_null); if (sconf->cache_cache) return OK; return -1; }
static void sqlalias_register_hooks(apr_pool_t *p) { static const char * const aszSucc[] = { "mod_rewrite.c", NULL }; ap_hook_post_config(sqlalias_init_handler, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_translate_name(sqlalias_redir, NULL, aszSucc, APR_HOOK_FIRST); #ifdef SQLALIAS_USE_PCONNECT ap_hook_child_init(sqlalias_child_init, NULL, NULL, APR_HOOK_MIDDLE); apr_thread_mutex_create(&sqlalias_mutex, APR_THREAD_MUTEX_DEFAULT, p); #endif }
static CRYPTO_dynlock_value *ssl_dyn_create(const char* file, int line) { CRYPTO_dynlock_value *l; apr_status_t rv; l = apr_palloc(ssl_pool, sizeof(CRYPTO_dynlock_value)); rv = apr_thread_mutex_create(&l->lock, APR_THREAD_MUTEX_DEFAULT, ssl_pool); if (rv != APR_SUCCESS) { /* FIXME: return error here */ } return l; }
static cache * cacheCreate (int maxsize, int timeout, unsigned long hash, request_data *rd) /*{{{ */ { // create pool for cache to live in apr_status_t s; apr_pool_t *p; s = apr_pool_create (&p, (apr_pool_t *) NULL); if (s != APR_SUCCESS) { ap_log_error(APLOG_MARK,LOG_WARNING,0,rd->server,"cacheCreate: could not create memory pool"); raise_exn ((int) &exn_OVERFLOW); } cache *c = (cache *) apr_palloc (p, sizeof (cache)); if (c == NULL) { ap_log_error(APLOG_MARK,LOG_WARNING,0,rd->server,"cacheCreate: could not allocate memory from pool"); raise_exn ((int) &exn_OVERFLOW); } ap_log_error(APLOG_MARK,LOG_DEBUG,0,rd->server,"cacheCreate: 0x%x", (unsigned int) c); c->pool = p; c->hashofname = hash; apr_proc_mutex_lock(rd->ctx->cachelock.plock); unsigned long cachehash = hash % rd->ctx->cachelock.shmsize; c->version = rd->ctx->cachelock.version[cachehash]; apr_proc_mutex_unlock(rd->ctx->cachelock.plock); // setup locks apr_thread_rwlock_create (&(c->rwlock), c->pool); apr_thread_mutex_create (&(c->mutex), APR_THREAD_MUTEX_DEFAULT, c->pool); // setup linked list c->sentinel = (entry *) apr_palloc (c->pool, sizeof (entry)); c->sentinel->up = c->sentinel; c->sentinel->down = c->sentinel; c->sentinel->key = NULL; // c->sentinel->key.hash = 0; c->sentinel->data = NULL; c->sentinel->size = 0; // setup hashtable & binary heap c->htable = (entrytable_hashtable_t *) apr_palloc (c->pool, sizeof (entrytable_hashtable_t) + sizeof(cacheheap_binaryheap_t)); c->heap = (cacheheap_binaryheap_t *) (c->htable + 1); entrytable_init (c->htable); cacheheap_heapinit(c->heap); // calculate size c->size = c->htable->hashTableSize * sizeof (entrytable_hashelement_t); c->maxsize = maxsize; // set timeout scheme c->timeout = timeout; return c; } /*}}} */
void ll_init_apr() { if (!gAPRPoolp) { // Initialize APR and create the global pool apr_initialize(); apr_pool_create(&gAPRPoolp, NULL); // Initialize the logging mutex apr_thread_mutex_create(&gLogMutexp, APR_THREAD_MUTEX_UNNESTED, gAPRPoolp); } }
static apr_status_t impl_pollset_create(apr_pollset_t *pollset, apr_uint32_t size, apr_pool_t *p, apr_uint32_t flags) { apr_status_t rv = APR_SUCCESS; pollset->p = apr_palloc(p, sizeof(apr_pollset_private_t)); #if APR_HAS_THREADS if (flags & APR_POLLSET_THREADSAFE && ((rv = apr_thread_mutex_create(&pollset->p->ring_lock, APR_THREAD_MUTEX_DEFAULT, p)) != APR_SUCCESS)) { pollset->p = NULL; return rv; } #else if (flags & APR_POLLSET_THREADSAFE) { pollset->p = NULL; return APR_ENOTIMPL; } #endif pollset->p->waiting = 0; pollset->p->port_set = apr_palloc(p, size * sizeof(port_event_t)); pollset->p->port_fd = port_create(); if (pollset->p->port_fd < 0) { pollset->p = NULL; return apr_get_netos_error(); } { int flags; if ((flags = fcntl(pollset->p->port_fd, F_GETFD)) == -1) return errno; flags |= FD_CLOEXEC; if (fcntl(pollset->p->port_fd, F_SETFD, flags) == -1) return errno; } pollset->p->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); APR_RING_INIT(&pollset->p->query_ring, pfd_elem_t, link); APR_RING_INIT(&pollset->p->add_ring, pfd_elem_t, link); APR_RING_INIT(&pollset->p->free_ring, pfd_elem_t, link); APR_RING_INIT(&pollset->p->dead_ring, pfd_elem_t, link); return rv; }
gop_thread_pool_context_t *gop_tp_context_create(char *tp_name, int min_threads, int max_threads, int max_recursion_depth) { // char buffer[1024]; gop_thread_pool_context_t *tpc; apr_interval_time_t dt; int i; log_printf(15, "count=%d\n", _tp_context_count); tbx_type_malloc_clear(tpc, gop_thread_pool_context_t, 1); if (tbx_atomic_inc(_tp_context_count) == 0) { apr_pool_create(&_tp_pool, NULL); apr_thread_mutex_create(&_tp_lock, APR_THREAD_MUTEX_DEFAULT, _tp_pool); thread_pool_stats_init(); } if (thread_local_depth_key == NULL) apr_threadkey_private_create(&thread_local_depth_key,_thread_pool_destructor, _tp_pool); tpc->pc = gop_hp_context_create(&_tp_base_portal); //** Really just used for the submit default_thread_pool_config(tpc); if (min_threads > 0) tpc->min_threads = min_threads; if (max_threads > 0) tpc->max_threads = max_threads + 1; //** Add one for the recursion depth starting offset being 1 tpc->recursion_depth = max_recursion_depth + 1; //** The min recusion normally starts at 1 so just slap an extra level and we don't care about 0|1 starting location tpc->max_concurrency = tpc->max_threads - tpc->recursion_depth; if (tpc->max_concurrency <= 0) { tpc->max_threads += 5 - tpc->max_concurrency; //** MAke sure we have at least 5 threads for work tpc->max_concurrency = tpc->max_threads - tpc->recursion_depth; log_printf(0, "Specified max threads and recursion depth don't work. Adjusting max_threads=%d\n", tpc->max_threads); } dt = tpc->min_idle * 1000000; assert_result(apr_thread_pool_create(&(tpc->tp), tpc->min_threads, tpc->max_threads, _tp_pool), APR_SUCCESS); apr_thread_pool_idle_wait_set(tpc->tp, dt); apr_thread_pool_threshold_set(tpc->tp, 0); tpc->name = (tp_name == NULL) ? NULL : strdup(tp_name); tbx_atomic_set(tpc->n_ops, 0); tbx_atomic_set(tpc->n_completed, 0); tbx_atomic_set(tpc->n_started, 0); tbx_atomic_set(tpc->n_submitted, 0); tbx_atomic_set(tpc->n_running, 0); tbx_type_malloc(tpc->overflow_running_depth, int, tpc->recursion_depth); tbx_type_malloc(tpc->reserve_stack, tbx_stack_t *, tpc->recursion_depth); for (i=0; i<tpc->recursion_depth; i++) { tpc->overflow_running_depth[i] = -1; tpc->reserve_stack[i] = tbx_stack_new(); } return(tpc); }
APU_DECLARE(apr_status_t) apr_reslist_create(apr_reslist_t **reslist, int min, int smax, int hmax, apr_interval_time_t ttl, apr_reslist_constructor con, apr_reslist_destructor de, void *params, apr_pool_t *pool) { apr_status_t rv; apr_reslist_t *rl; /* Do some sanity checks so we don't thrash around in the * maintenance routine later. */ if (min > smax || min > hmax || smax > hmax || ttl < 0) { return APR_EINVAL; } rl = apr_pcalloc(pool, sizeof(*rl)); rl->pool = pool; rl->min = min; rl->smax = smax; rl->hmax = hmax; rl->ttl = ttl; rl->constructor = con; rl->destructor = de; rl->params = params; APR_RING_INIT(&rl->avail_list, apr_res_t, link); APR_RING_INIT(&rl->free_list, apr_res_t, link); rv = apr_thread_mutex_create(&rl->listlock, APR_THREAD_MUTEX_DEFAULT, pool); if (rv != APR_SUCCESS) { return rv; } rv = apr_thread_cond_create(&rl->avail, pool); if (rv != APR_SUCCESS) { return rv; } rv = reslist_maint(rl); if (rv != APR_SUCCESS) { return rv; } apr_pool_cleanup_register(rl->pool, rl, reslist_cleanup, apr_pool_cleanup_null); *reslist = rl; return APR_SUCCESS; }