Beispiel #1
0
static void * APR_THREAD_FUNC resource_consuming_thread(apr_thread_t *thd,
                                                        void *data)
{
    apr_status_t rv;
    my_thread_info_t *thread_info = data;
    apr_reslist_t *rl = thread_info->reslist;
    int i;

    for (i = 0; i < CONSUMER_ITERATIONS; i++) {
        my_resource_t *res;
        rv = apr_reslist_acquire(rl, (void**)&res);
        if (rv != APR_SUCCESS) {
            fprintf(stderr, "Failed to retrieve resource from reslist\n");
            apr_thread_exit(thd, rv);
            return NULL;
        }
        printf("  [tid:%d,iter:%d] using resource id:%d\n", thread_info->tid,
               i, res->id);
        apr_sleep(thread_info->work_delay_sleep);
        rv = apr_reslist_release(rl, res);
        if (rv != APR_SUCCESS) {
            fprintf(stderr, "Failed to return resource to reslist\n");
            apr_thread_exit(thd, rv);
            return NULL;
        }
    }

    return APR_SUCCESS;
}
Beispiel #2
0
/* Functions we export for modules to use:
	- open acquires a connection from the pool (opens one if necessary)
	- close releases it back in to the pool
*/
PGconn* pgasp_pool_open(server_rec* s) {
  PGconn* ret = NULL ;
  pgasp_config* pgasp = (pgasp_config*)
	ap_get_module_config(s->module_config, &pgasp_module) ;
  apr_uint32_t acquired_cnt ;

  if (pgasp->dbpool == NULL) {
    pgasp = apr_hash_get(pgasp_pool_config, pgasp->key, APR_HASH_KEY_STRING);
  }
  if ( apr_reslist_acquire(pgasp->dbpool, (void**)&ret) != APR_SUCCESS ) {
    ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "mod_pgasp: Failed to acquire PgSQL connection from pool!") ;
    return NULL ;
  }
  if (PQstatus(ret) != CONNECTION_OK) {
    PQreset(ret);
    if (PQstatus(ret) != CONNECTION_OK) {
      ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
	"PgSQL Error: %s", PQerrorMessage(ret) ) ;
      apr_reslist_release(pgasp->dbpool, ret) ;
      return NULL ;
    }
  }
  if (pgasp->nkeep < (acquired_cnt = apr_reslist_acquired_count	( pgasp->dbpool	))) {
    ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "mod_pgasp: %d connections in the %s pool acquired (%d,%d,%d)",
		 acquired_cnt, pgasp->key, pgasp->nmin, pgasp->nkeep, pgasp->nmax
		 ) ;
  }
  return ret ;
}
Beispiel #3
0
static void test_timeout(abts_case *tc, apr_reslist_t *rl)
{
    apr_status_t rv;
    my_resource_t *resources[RESLIST_HMAX];
    my_resource_t *res;
    void *vp;
    int i;

    apr_reslist_timeout_set(rl, 1000);

    /* deplete all possible resources from the resource list
     * so that the next call will block until timeout is reached
     * (since there are no other threads to make a resource
     * available)
     */

    for (i = 0; i < RESLIST_HMAX; i++) {
        rv = apr_reslist_acquire(rl, (void**)&resources[i]);
        ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    }

    /* next call will block until timeout is reached */
    rv = apr_reslist_acquire(rl, &vp);
    ABTS_TRUE(tc, APR_STATUS_IS_TIMEUP(rv));

    res = vp;

    /* release the resources; otherwise the destroy operation
     * will blow
     */
    for (i = 0; i < RESLIST_HMAX; i++) {
        rv = apr_reslist_release(rl, resources[i]);
        ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    }
}
Beispiel #4
0
void pgasp_pool_close(server_rec* s, PGconn* sql) {
  pgasp_config* pgasp = (pgasp_config*)
	ap_get_module_config(s->module_config, &pgasp_module) ;
  if (pgasp->dbpool == NULL) {
    pgasp = apr_hash_get(pgasp_pool_config, pgasp->key, APR_HASH_KEY_STRING);
  }
  apr_reslist_release(pgasp->dbpool, sql) ;
}
Beispiel #5
0
static apr_status_t safe_dbi_rel_server(apr_reslist_t * ftpd_dbi_pool,
                                        ftpd_dbi_rest * server,
                                        const request_rec * r)
{
    apr_status_t rv;
    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                  "[mod_ftpd_dbi.c] Returning Server Connection to DBI Pool");
    rv = apr_reslist_release(ftpd_dbi_pool, (void **) server);
    return rv;
}
Beispiel #6
0
static void _release_mapboj(mapcache_context *ctx, mapcache_map *map, struct mc_mapobj *mcmap) {
   mapcache_source_mapserver *src = (mapcache_source_mapserver*) map->tileset->source;
   msFreeLabelCache(&mcmap->map->labelcache);
   apr_reslist_t *mapobjs = apr_hash_get(mapobj_container,src->source.name, APR_HASH_KEY_STRING);
   assert(mapobjs);
   if (GC_HAS_ERROR(ctx)) {
      apr_reslist_invalidate(mapobjs, (void*) mcmap);
   } else {
      apr_reslist_release(mapobjs, (void*) mcmap);
   }
}
Beispiel #7
0
static void test_shrinking(abts_case *tc, apr_reslist_t *rl)
{
    apr_status_t rv;
    my_resource_t *resources[RESLIST_HMAX];
    my_resource_t *res;
    void *vp;
    int i;
    int sleep_time = RESLIST_TTL / RESLIST_HMAX;

    /* deplete all possible resources from the resource list */
    for (i = 0; i < RESLIST_HMAX; i++) {
        rv = apr_reslist_acquire(rl, (void**)&resources[i]);
        ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    }

    /* Free all resources above RESLIST_SMAX - 1 */
    for (i = RESLIST_SMAX - 1; i < RESLIST_HMAX; i++) {
        rv = apr_reslist_release(rl, resources[i]);
        ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    }

    for (i = 0; i < RESLIST_HMAX; i++) {
        rv = apr_reslist_acquire(rl, &vp);
        ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
        res = vp;
        apr_sleep(sleep_time);
        rv = apr_reslist_release(rl, res);
        ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    }
    apr_sleep(sleep_time);

    /*
     * Now free the remaining elements. This should trigger the shrinking of
     * the list
     */
    for (i = 0; i < RESLIST_SMAX - 1; i++) {
        rv = apr_reslist_release(rl, resources[i]);
        ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    }
}
Beispiel #8
0
static void _bdb_release_conn(mapcache_context *ctx, mapcache_tile *tile, struct bdb_env *benv) {
   mapcache_cache_bdb* cache = (mapcache_cache_bdb*)tile->tileset->cache;
   apr_reslist_t *pool;
   if(benv->readonly) 
      pool = cache->ro_connection_pool;
   else
      pool = cache->rw_connection_pool;
   if(GC_HAS_ERROR(ctx)) {
      apr_reslist_invalidate(pool,(void*)benv);  
   } else {
      apr_reslist_release(pool, (void*)benv);
   }
}
Beispiel #9
0
int ml_reslist_release(lua_State*L)
{
  request_rec* r = CHECK_REQUEST_OBJECT(1);
  size_t l;
  const char* o = luaL_checklstring(L, 2, &l);
  void* resource = *(void**)lua_touserdata(L, 3);

  struct dir_config *d = ap_get_module_config(r->per_dir_config, &luaex_module);
  apr_reslist_t *reslist = apr_hash_get(d->resource, o, l);

  apr_status_t status = apr_reslist_release(reslist, resource);
  lua_pushboolean(L, status == APR_SUCCESS);
  return 1;
}
Beispiel #10
0
static void _sqlite_release_conn(mapcache_context *ctx, mapcache_tile *tile, struct sqlite_conn *conn)
{
  apr_reslist_t *pool;
  apr_hash_t *pool_container;
  if(conn->readonly) {
    pool_container = ro_connection_pools;
  } else {
    pool_container = rw_connection_pools;
  }
  pool = apr_hash_get(pool_container,tile->tileset->cache->name, APR_HASH_KEY_STRING);

  if (GC_HAS_ERROR(ctx)) {
    apr_reslist_invalidate(pool, (void*) conn);
  } else {
    apr_reslist_release(pool, (void*) conn);
  }
}
Beispiel #11
0
static apr_status_t proc_close_socket(jaxer_connection * ac)
{
	apr_status_t rv = APR_SUCCESS;

	if (ac->has_error)
	{
		compat_log_rerror(APLOG_MARK, APLOG_DEBUG, 0,ac->request, "mod_jaxer: invalidating connection (%d) due to error", ac->sock);

		apr_reslist_invalidate(ac->worker->ac_cache, ac);
		
	} else 
	{
		compat_log_rerror(APLOG_MARK, APLOG_DEBUG, 0,ac->request, "mod_jaxer: releasing connection (%d) back to pool", ac->sock);

		ac->has_error = 0;
		ac->request = 0;
		apr_reslist_release(ac->worker->ac_cache, ac);
	}

	return rv;
}
Beispiel #12
0
static void * APR_THREAD_FUNC resource_consuming_thread(apr_thread_t *thd,
                                                        void *data)
{
    int i;
    apr_uint32_t chance;
    void *vp;
    apr_status_t rv;
    my_resource_t *res;
    my_thread_info_t *thread_info = data;
    apr_reslist_t *rl = thread_info->reslist;

#if APR_HAS_RANDOM
    apr_generate_random_bytes((void*)&chance, sizeof(chance));
#else
    chance = (apr_uint32_t)(apr_time_now() % APR_TIME_C(4294967291));
#endif

    for (i = 0; i < CONSUMER_ITERATIONS; i++) {
        rv = apr_reslist_acquire(rl, &vp);
        ABTS_INT_EQUAL(thread_info->tc, APR_SUCCESS, rv);
        res = vp;
        apr_sleep(thread_info->work_delay_sleep);

        /* simulate a 5% chance of the resource being bad */
        chance = lgc(chance);
        if ( chance < PERCENT95th ) {
            rv = apr_reslist_release(rl, res);
            ABTS_INT_EQUAL(thread_info->tc, APR_SUCCESS, rv);
        } else {
            rv = apr_reslist_invalidate(rl, res);
            ABTS_INT_EQUAL(thread_info->tc, APR_SUCCESS, rv);
        }
    }

    return APR_SUCCESS;
}
Beispiel #13
0
void jxr_conn_release(jaxer_worker* aw, jaxer_connection* ac)
{
	apr_reslist_release(aw->ac_cache, ac);
}
Beispiel #14
0
/**
 * Relase redis context on redis pool
 */
static void pool_close(server_rec *s, redisContext* ctx) {
	redis_cfg *config = (redis_cfg*) ap_get_module_config(s->module_config, &apachelog_module);
	apr_reslist_release(config->redis_pool, ctx);
}
Beispiel #15
0
static void _couchbase_release_connection(mapcache_tile *tile, libcouchbase_t* instance)
{
   mapcache_cache_couchbase* cache = (mapcache_cache_couchbase*)tile->tileset->cache;
   apr_reslist_release(cache->connection_pool, (void*)instance);
}