void *
rtcp_new_object (rtcp_memory_t *memory, 
                 rtcp_mem_obj_t type)
{
    void *ptr = NULL;

    if (!memory) {
        return (NULL);
    }
    if (!(type >= RTCP_MIN_OBJ && type <= RTCP_MAX_OBJ)) {
        return (NULL);
    }

    ptr = zone_acquire(memory->pool[type].zone);
    if (ptr) {
        memory->pool[type].pool_stats.allocations++;
        if (memory->pool[type].pool_stats.allocations > 
            memory->pool[type].pool_stats.allocations_hw) {
            memory->pool[type].pool_stats.allocations_hw = 
                memory->pool[type].pool_stats.allocations;
        }

        memory->allocated += zm_elem_size(memory->pool[type].zone);
    } else {
        memory->pool[type].pool_stats.allocations_failed++;
    }

    return (ptr);
}
Example #2
0
void
database_service_zone_unload(zone_desc_s *zone_desc, zdb_zone *zone)
{
    log_debug("database_service_zone_unload(%{dnsname}@%p=%i,%{dnsname})",
            zone_desc->origin, zone_desc, zone_desc->rc,
            (zone != NULL)?zone->origin:(const u8*)"\004NULL");

    zdb_zone *work_zone = NULL;

    if(zone != NULL)
    {
        work_zone = zone; // zone will be released by the thread
        zone_lock(zone_desc, ZONE_LOCK_UNLOAD);
        if(zone == zone_desc->loaded_zone) // UNLOAD
        {
            log_warn("database_service_zone_unload: forced unload of %p = loaded_zone", zone);
            
            log_debug7("database_service_zone_unload: %{dnsname}@%p: loaded_zone@%p (was %p)",
                    zone_desc->origin,
                    zone_desc,
                    NULL,
                    zone_desc->loaded_zone); // UNLOAD
            zdb_zone_release(zone_desc->loaded_zone);
            zone_desc->loaded_zone = NULL; // UNLOAD
        }
        // else the zone in the descriptor has changed : don't touch it
        zone_unlock(zone_desc, ZONE_LOCK_UNLOAD);
    }
    else
    {
        zone_lock(zone_desc, ZONE_LOCK_UNLOAD);
        work_zone = zone_desc->loaded_zone; // UNLOAD
        
        log_debug7("database_service_zone_unload: %{dnsname}@%p: loaded_zone@%p (was %p)",
                zone_desc->origin,
                zone_desc,
                NULL,
                zone_desc->loaded_zone); // UNLOAD
        
        if(zone_desc->loaded_zone != NULL)
        {
            // the zone we are about to unload will be released by the thread
            //zdb_zone_release(zone_desc->loaded_zone);
            zone_desc->loaded_zone = NULL; // UNLOAD
        }
        zone_unlock(zone_desc, ZONE_LOCK_UNLOAD);
    }
    
    if(work_zone != NULL)
    {
        database_service_zone_unload_parms_s *parm;
        MALLOC_OR_DIE(database_service_zone_unload_parms_s*, parm, sizeof(database_service_zone_unload_parms_s), DSZZUPRM_TAG);
        parm->zone_desc = zone_desc;
        parm->zone = work_zone;
    
        zone_acquire(zone_desc);
        database_service_zone_unload_queue_thread(database_service_zone_unload_thread, parm, NULL, "database_service_zone_unload_thread");
    }
/**
 * vqec_pak_hdr_alloc()
 *
 * Allocates a packet header for insertion of a packet onto a list.
 *
 * @param[id]  id                ID of hdr pool from which the packet hdr
 *                                should be allocated.
 * @param[out] vqec_pak_hdr_t *  Pointer of allocated hdr,
 *                                or NULL if unsuccessful.
 */
vqec_pak_hdr_t *
vqec_pak_hdr_alloc (vqec_pak_hdr_poolid_t id)
{
    vqec_pak_hdr_t *hdr = NULL;

    if ((id != VQEC_PAK_HDR_POOLID) || (!s_pak_hdr_pool)) {
        goto done;
    }
    
    hdr = zone_acquire(s_pak_hdr_pool);
    if (!hdr) {
        goto done;
    }

    /* Clear the pak header and store the pool from which it came */
    memset(hdr, 0, sizeof(*hdr));
    hdr->pool = VQEC_PAK_HDR_POOLID;
done:
    return (hdr);
}
/**
   Create sink object.
   @return pointer of sink allocated.
 */
vqec_sink_t * vqec_sink_create (uint32_t max_q_depth, uint32_t max_paksize) 
{

    vqec_sink_t * sink;
    
    sink = (vqec_sink_t *) zone_acquire(s_vqec_sink_pool);
    
    if (!sink) {
        return (NULL);
    }

    memset(sink, 0, sizeof(vqec_sink_t));
    sink->__func_table = &vqec_sink_fcn_table;

#ifdef HAVE_SCHED_JITTER_HISTOGRAM
    sink->reader_jitter_hist =
        zone_acquire(s_reader_hist_pool);
    if (!sink->reader_jitter_hist) {
        zone_release(s_vqec_sink_pool, sink);
        return (NULL);
    }

    if (vam_hist_create_ranges(sink->reader_jitter_hist,
                               s_reader_jitter_ranges,
                               s_reader_jitter_num_ranges,
                               "Reader exit-to-enter jitter")) {
        zone_release(s_reader_hist_pool,
                     sink->reader_jitter_hist);
        zone_release(s_vqec_sink_pool, sink);
        return (NULL);
    }

    sink->inp_delay_hist =
        zone_acquire(s_inp_delay_hist_pool);
    if (!sink->inp_delay_hist) {
        zone_release(s_reader_hist_pool,
                     sink->reader_jitter_hist);
        zone_release(s_vqec_sink_pool, sink);
        return (NULL);
    }

    if (vam_hist_create_ranges(sink->inp_delay_hist,
                               s_inp_delay_ranges,
                               s_inp_delay_num_ranges,
                               "Input jitter")) {
        zone_release(s_inp_delay_hist_pool,
                     sink->inp_delay_hist);
        zone_release(s_reader_hist_pool,
                     sink->reader_jitter_hist);
        zone_release(s_vqec_sink_pool, sink);
        return (NULL);
    }
#endif  /* HAVE_SCHED_JITTER_HISTOGRAM */

    VQE_TAILQ_INIT(&sink->pak_queue);
    sink->hdr_pool = s_pak_hdr_poolid;
    sink->queue_size = max_q_depth;
    sink->max_paksize = max_paksize;

    return sink;
}
/**
 * Build the flowgraph for the given channel descriptor. A new
 * graph may be built, or an existing flowgraph may be used. A new
 * graph is built per channel unless SSRC multiplexing is in use. 
 * The flow of data through the graph is started, once the graph
 * has been built within the context of this call. The identifier of
 * the flowgraph which contains the channel is returned in *id.
 */
vqec_dp_error_t
vqec_dp_graph_create (vqec_dp_chan_desc_t *chan,
                      vqec_dp_tunerid_t tid, 
                      vqec_dp_encap_type_t tuner_encap, 
                      vqec_dp_graphinfo_t *graphinfo)
{
    vqec_dp_graph_t *graph;
    vqec_dp_graphid_t id;
    vqec_dp_error_t ret = VQEC_DP_ERR_OK;

    if (!chan) {
        return VQEC_DP_ERR_INVALIDARGS;
    }

    /* if the graph doesn't already exist, create a new one */
    graph = (vqec_dp_graph_t *) zone_acquire(s_vqec_graph_pool);
    if (!graph || (graph_index == s_graphs_max)) {
        id = VQEC_DP_GRAPHID_INVALID;
        ret = VQEC_DP_ERR_NOMEM;
        goto bail;
    }
    s_graph_cache[graph_index] = graph;
    graph_index++;
    memset(graph, 0, sizeof(vqec_dp_graph_t));

    /* 
     * Register graph in id_mgr - must have a channel id at time of
     * channel init.
     */ 
    id = id_get(graph, vqec_dp_graph_id_table_key);
    if (id == VQEC_DP_GRAPHID_INVALID) {
        ret = VQEC_DP_ERR_NOMEM;
        goto bail;
    }
    graph->id = id;

    /* initialize graph and build all components */
    if (vqec_dp_graph_init(graph, chan, graphinfo) != VQEC_DP_ERR_OK) {
        VQEC_DP_SYSLOG_PRINT(ERROR, "graph initialization failed");
        ret = VQEC_DP_ERR_NOMEM;
        goto bail;
    }

    /* add_tuner() to the graph */
    if (vqec_dp_graph_add_tuner(graph->id, tid) != VQEC_DP_ERR_OK) {
        VQEC_DP_SYSLOG_PRINT(ERROR, "graph add_tuner failed");
        ret = VQEC_DP_ERR_NOMEM;
        goto bail;
    }

    /* cache channel info inside the tuner */
    vqec_dp_output_shim_tuner_cache_channel(tid, chan);

    /* make IS-OS connections */
    if (vqec_dp_graph_connect(graph, chan->fallback) != VQEC_DP_ERR_OK) {
        VQEC_DP_SYSLOG_PRINT(ERROR, "graph connection failed");
        ret = VQEC_DP_ERR_NOMEM;
        goto bail;
    }

    return VQEC_DP_ERR_OK;

bail:
    if (id != VQEC_DP_GRAPHID_INVALID) {
        vqec_dp_graph_destroy(id);
        id = VQEC_DP_GRAPHID_INVALID;
    } else if (graph) {
        zone_release(s_vqec_graph_pool, graph);
        s_graph_cache[graph_index] = NULL;
        graph_index--;
    }

    return ret;
}
/*
 * Initialize the graph module.
 */
vqec_dp_error_t
vqec_dp_graph_init_module (vqec_dp_module_init_params_t *params)
{
    vqec_dp_error_t err = VQEC_DP_ERR_OK;

    if (!params) {
        err = VQEC_DP_ERR_INVALIDARGS;
        goto done;
    }

    /* allocate resource zone */
    if (s_vqec_graph_pool) {
        err = VQEC_DP_ERR_ALREADY_INITIALIZED;
        goto done;
    }
    s_vqec_graph_pool = zone_instance_get_loc(
                            "dp_graph_pool",
                            O_CREAT,
                            sizeof(vqec_dp_graph_t),
                            params->max_channels,
                            NULL, NULL);
    if (!s_vqec_graph_pool) {
        VQEC_DP_SYSLOG_PRINT(ERROR, "failed to allocate graph pool");
        err = VQEC_DP_ERR_NOMEM;
        goto done;
    }

    /* allocate and acquire zone for graph pointer cache */
    s_graph_cache_pool = zone_instance_get_loc(
        "graph_ptr_pool",
        O_CREAT,
        sizeof(vqec_dp_graph_t *) * params->max_channels,
        1,
        NULL, NULL);
    if (!s_graph_cache_pool) {
        VQEC_DP_SYSLOG_PRINT(ERROR, "failed to allocate graph ptr cache pool");
        err = VQEC_DP_ERR_NOMEM;
        goto done;
    }
    s_graph_cache = zone_acquire(s_graph_cache_pool);
    if (!s_graph_cache) {
        VQEC_DP_SYSLOG_PRINT(ERROR, "failed to acquire graph ptr cache pool");
        err = VQEC_DP_ERR_NOMEM;
        goto done;
    }

    /* initialize id_mgr table */
    if (VQEC_DP_ERR_OK != vqec_dp_graph_init_id_table(params->max_channels)) {
        VQEC_DP_SYSLOG_PRINT(ERROR, "failed to init graph id table");
        err = VQEC_DP_ERR_INTERNAL;
        goto done;
    }

    /* set max number of graphs */
    s_graphs_max = params->max_channels;

  done:
    if (err != VQEC_DP_ERR_OK &&
        err != VQEC_DP_ERR_ALREADY_INITIALIZED) {
        if (s_vqec_graph_pool) {
            (void) zone_instance_put(s_vqec_graph_pool);
            s_vqec_graph_pool = NULL;
        }
        if (s_graph_cache_pool) {
            (void)zone_instance_put(s_graph_cache_pool);
            s_graph_cache_pool = NULL;
        }
            
    }
    return err;
}