Beispiel #1
0
/**
 * Callback routine that is called to destroy this
 * etch_apr_queue_t when its pool is destroyed.
 */
static apr_status_t etch_apr_queue_destroy(void *data) 
{
    etch_apr_queue_t *queue = data;

    apr_thread_cond_destroy(queue->not_empty);
    apr_thread_cond_destroy(queue->not_full);
    apr_thread_mutex_destroy(queue->one_big_mutex);

    return APR_SUCCESS;
}
Beispiel #2
0
/**
 * Callback routine that is called to destroy this
 * apr_queue_t when its pool is destroyed.
 */
static apr_status_t queue_destroy(void *data) 
{
    apr_queue_t *queue = data;

    /* Ignore errors here, we can't do anything about them anyway. */

    apr_thread_cond_destroy(queue->not_empty);
    apr_thread_cond_destroy(queue->not_full);
    apr_thread_mutex_destroy(queue->one_big_mutex);

    return APR_SUCCESS;
}
Beispiel #3
0
/** Shutdown message processing loop */
MRCP_DECLARE(apt_bool_t) mrcp_client_shutdown(mrcp_client_t *client)
{
	apt_task_t *task;
	if(!client || !client->task) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Invalid Client");
		return FALSE;
	}
	task = apt_consumer_task_base_get(client->task);
	if(apt_task_terminate(task,TRUE) == FALSE) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Shutdown Client Task");
		return FALSE;
	}
	client->session_table = NULL;

	if(client->sync_start_object) {
		apr_thread_cond_destroy(client->sync_start_object);
		client->sync_start_object = NULL;
	}
	if(client->sync_start_mutex) {
		apr_thread_mutex_destroy(client->sync_start_mutex);
		client->sync_start_mutex = NULL;
	}

	return TRUE;
}
/** Destroy ASR session */
static apt_bool_t asr_session_destroy_ex(asr_session_t *asr_session, apt_bool_t terminate)
{
	if(terminate == TRUE) {
		apr_thread_mutex_lock(asr_session->mutex);
		if(mrcp_application_session_terminate(asr_session->mrcp_session) == TRUE) {
			apr_thread_cond_wait(asr_session->wait_object,asr_session->mutex);
			/* the response must be checked to be the valid one */
		}
		apr_thread_mutex_unlock(asr_session->mutex);
	}

	if(asr_session->audio_in) {
		fclose(asr_session->audio_in);
		asr_session->audio_in = NULL;
	}

	if(asr_session->mutex) {
		apr_thread_mutex_destroy(asr_session->mutex);
		asr_session->mutex = NULL;
	}
	if(asr_session->wait_object) {
		apr_thread_cond_destroy(asr_session->wait_object);
		asr_session->wait_object = NULL;
	}
	if(asr_session->media_buffer) {
		mpf_frame_buffer_destroy(asr_session->media_buffer);
		asr_session->media_buffer = NULL;
	}
	
	return mrcp_application_session_destroy(asr_session->mrcp_session);
}
Beispiel #5
0
static void broadcast_threads(abts_case *tc, void *data)
{
    toolbox_t box;
    unsigned int i;
    apr_status_t rv;
    apr_uint32_t count = 0;
    apr_thread_cond_t *cond = NULL;
    apr_thread_mutex_t *mutex = NULL;
    apr_thread_t *thread[NTHREADS];

    rv = apr_thread_cond_create(&cond, p);
    ABTS_SUCCESS(rv);
    ABTS_PTR_NOTNULL(tc, cond);

    rv = apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_DEFAULT, p);
    ABTS_SUCCESS(rv);
    ABTS_PTR_NOTNULL(tc, mutex);

    rv = apr_thread_mutex_lock(mutex);
    ABTS_SUCCESS(rv);

    box.tc = tc;
    box.data = &count;
    box.mutex = mutex;
    box.cond = cond;
    box.func = lock_and_wait;

    for (i = 0; i < NTHREADS; i++) {
        rv = apr_thread_create(&thread[i], NULL, thread_routine, &box, p);
        ABTS_SUCCESS(rv);
    }

    do {
        rv = apr_thread_mutex_unlock(mutex);
        ABTS_SUCCESS(rv);
        apr_sleep(100000);
        rv = apr_thread_mutex_lock(mutex);
        ABTS_SUCCESS(rv);
    } while (apr_atomic_read32(&count) != NTHREADS);

    rv = apr_thread_cond_broadcast(cond);
    ABTS_SUCCESS(rv);

    rv = apr_thread_mutex_unlock(mutex);
    ABTS_SUCCESS(rv);

    for (i = 0; i < NTHREADS; i++) {
        apr_status_t retval;
        rv = apr_thread_join(&retval, thread[i]);
        ABTS_SUCCESS(rv);
    }

    ABTS_INT_EQUAL(tc, 0, count);

    rv = apr_thread_cond_destroy(cond);
    ABTS_SUCCESS(rv);

    rv = apr_thread_mutex_destroy(mutex);
    ABTS_SUCCESS(rv);
}
Beispiel #6
0
static void dynamic_binding(abts_case *tc, void *data)
{
    unsigned int i;
    apr_status_t rv;
    toolbox_t box[NTHREADS];
    apr_thread_t *thread[NTHREADS];
    apr_thread_mutex_t *mutex[NTHREADS];
    apr_thread_cond_t *cond = NULL;

    rv = apr_thread_cond_create(&cond, p);
    ABTS_SUCCESS(rv);
    ABTS_PTR_NOTNULL(tc, cond);

    for (i = 0; i < NTHREADS; i++) {
        rv = apr_thread_mutex_create(&mutex[i], APR_THREAD_MUTEX_DEFAULT, p);
        ABTS_SUCCESS(rv);

        rv = apr_thread_mutex_lock(mutex[i]);
        ABTS_SUCCESS(rv);

        box[i].tc = tc;
        box[i].cond = cond;
        box[i].mutex = mutex[i];
        box[i].func = lock_and_signal;

        rv = apr_thread_create(&thread[i], NULL, thread_routine, &box[i], p);
        ABTS_SUCCESS(rv);
    }

    /*
     * The dynamic binding should be preserved because we use only one waiter
     */

    for (i = 0; i < NTHREADS; i++) {
        rv = apr_thread_cond_wait(cond, mutex[i]);
        ABTS_SUCCESS(rv);
    }

    for (i = 0; i < NTHREADS; i++) {
        rv = apr_thread_cond_timedwait(cond, mutex[i], 10000);
        ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));

        rv = apr_thread_mutex_unlock(mutex[i]);
        ABTS_SUCCESS(rv);
    }

    for (i = 0; i < NTHREADS; i++) {
        apr_status_t retval;
        rv = apr_thread_join(&retval, thread[i]);
        ABTS_SUCCESS(rv);
    }

    rv = apr_thread_cond_destroy(cond);
    ABTS_SUCCESS(rv);

    for (i = 0; i < NTHREADS; i++) {
        rv = apr_thread_mutex_destroy(mutex[i]);
        ABTS_SUCCESS(rv);
    }
}
Beispiel #7
0
void rs_simple_destroy(resource_service_fn_t *rs)
{
    rs_simple_priv_t *rss = (rs_simple_priv_t *)rs->priv;
    apr_status_t value;

    log_printf(15, "rs_simple_destroy: sl=%p\n", rss->rid_table);
    tbx_log_flush();

    //** Notify the depot check thread
    apr_thread_mutex_lock(rss->lock);
    rss->shutdown = 1;
    apr_thread_cond_broadcast(rss->cond);
    apr_thread_mutex_unlock(rss->lock);

    //** Wait for it to shutdown
    apr_thread_join(&value, rss->check_thread);

    //** Now we can free up all the space
    apr_thread_mutex_destroy(rss->lock);
    apr_thread_cond_destroy(rss->cond);
    apr_pool_destroy(rss->mpool);  //** This also frees the hash tables

    if (rss->rid_table != NULL) tbx_list_destroy(rss->rid_table);

    free(rss->random_array);
    free(rss->fname);
    free(rss);
    free(rs);
}
Beispiel #8
0
static apr_status_t reslist_cleanup(void *data_)
{
    apr_status_t rv;
    apr_reslist_t *rl = data_;
    apr_res_t *res;

    apr_thread_mutex_lock(rl->listlock);

    while (rl->nidle > 0) {
        res = pop_resource(rl);
        rl->ntotal--;
        rv = destroy_resource(rl, res);
        if (rv != APR_SUCCESS) {
            return rv;
        }
        free_container(rl, res);
    }

    assert(rl->nidle == 0);
    assert(rl->ntotal == 0);

    apr_thread_mutex_destroy(rl->listlock);
    apr_thread_cond_destroy(rl->avail);

    return APR_SUCCESS;
}
Beispiel #9
0
void h2_session_destroy(h2_session *session)
{
    AP_DEBUG_ASSERT(session);
    if (session->mplx) {
        h2_mplx_release_and_join(session->mplx, session->iowait);
        session->mplx = NULL;
    }
    if (session->streams) {
        if (h2_stream_set_size(session->streams)) {
            ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, session->c,
                          "h2_session(%ld): destroy, %d streams open",
                          session->id, (int)h2_stream_set_size(session->streams));
        }
        h2_stream_set_destroy(session->streams);
        session->streams = NULL;
    }
    if (session->ngh2) {
        nghttp2_session_del(session->ngh2);
        session->ngh2 = NULL;
    }
    h2_conn_io_destroy(&session->io);
    
    if (session->iowait) {
        apr_thread_cond_destroy(session->iowait);
        session->iowait = NULL;
    }
    
    if (session->pool) {
        apr_pool_destroy(session->pool);
    }
}
Beispiel #10
0
void close_server_port(tbx_ns_monitor_t *nm)
{
    apr_status_t dummy;

    //** Trigger a port shutdown
    apr_thread_mutex_lock(nm->lock);
    nm->shutdown_request = 1;
    log_printf(15, "close_server_port: port=%d Before cond_signal\n", nm->port);
    tbx_log_flush();
    apr_thread_cond_signal(nm->cond);
    log_printf(15, "close_server_port: port=%d After cond_signal\n", nm->port);
    tbx_log_flush();
    apr_thread_mutex_unlock(nm->lock);

    log_printf(15, "close_server_port: port=%d After unlock\n", nm->port);
    tbx_log_flush();

    //** Wait until the thread closes
    apr_thread_join(&dummy, nm->thread);

    log_printf(15, "close_server_port: port=%d After join\n", nm->port);
    tbx_log_flush();

    //** Free the actual struct
    free(nm->address);
    apr_thread_mutex_destroy(nm->lock);
    apr_thread_cond_destroy(nm->cond);

    apr_pool_destroy(nm->mpool);

    nm->port = -1;
}
Beispiel #11
0
void network_destroy(tbx_network_t *net)
{
    network_close(net);

    //** Free the main net variables
    apr_thread_mutex_destroy(net->ns_lock);
    apr_thread_cond_destroy(net->cond);
    apr_pool_destroy(net->mpool);

    free(net);
}
Beispiel #12
0
static apr_status_t queue_info_cleanup(void *data_)
{
    fd_queue_info_t *qi = data_;
    int i;
    apr_thread_cond_destroy(qi->wait_for_idler);
    apr_thread_mutex_destroy(qi->idlers_mutex);
    for (i = 0; i < qi->num_recycled; i++) {
        apr_pool_destroy(qi->recycled_pools[i]);
    }
    return APR_SUCCESS;
}
static void test_cond(abts_case *tc, void *data)
{
    apr_thread_t *p1, *p2, *p3, *p4, *c1;
    apr_status_t s0, s1, s2, s3, s4;
    int count1, count2, count3, count4;
    int sum;
    
    APR_ASSERT_SUCCESS(tc, "create put mutex",
                       apr_thread_mutex_create(&put.mutex, 
                                               APR_THREAD_MUTEX_DEFAULT, p));
    ABTS_PTR_NOTNULL(tc, put.mutex);

    APR_ASSERT_SUCCESS(tc, "create nready mutex",
                       apr_thread_mutex_create(&nready.mutex, 
                                               APR_THREAD_MUTEX_DEFAULT, p));
    ABTS_PTR_NOTNULL(tc, nready.mutex);

    APR_ASSERT_SUCCESS(tc, "create condvar",
                       apr_thread_cond_create(&nready.cond, p));
    ABTS_PTR_NOTNULL(tc, nready.cond);

    count1 = count2 = count3 = count4 = 0;
    put.nput = put.nval = 0;
    nready.nready = 0;
    i = 0;
    x = 0;

    s0 = apr_thread_create(&p1, NULL, thread_cond_producer, &count1, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, s0);
    s1 = apr_thread_create(&p2, NULL, thread_cond_producer, &count2, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, s1);
    s2 = apr_thread_create(&p3, NULL, thread_cond_producer, &count3, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, s2);
    s3 = apr_thread_create(&p4, NULL, thread_cond_producer, &count4, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, s3);
    s4 = apr_thread_create(&c1, NULL, thread_cond_consumer, NULL, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, s4);

    apr_thread_join(&s0, p1);
    apr_thread_join(&s1, p2);
    apr_thread_join(&s2, p3);
    apr_thread_join(&s3, p4);
    apr_thread_join(&s4, c1);

    APR_ASSERT_SUCCESS(tc, "destroy condvar", 
                       apr_thread_cond_destroy(nready.cond));

    sum = count1 + count2 + count3 + count4;
    /*
    printf("count1 = %d count2 = %d count3 = %d count4 = %d\n",
            count1, count2, count3, count4);
    */
    ABTS_INT_EQUAL(tc, MAX_COUNTER, sum);
}
Beispiel #14
0
/**
 * Callback routine that is called to destroy this
 * fd_queue_t when its pool is destroyed.
 */
static apr_status_t ap_queue_destroy(void *data)
{
    fd_queue_t *queue = data;

    /* Ignore errors here, we can't do anything about them anyway.
     * XXX: We should at least try to signal an error here, it is
     * indicative of a programmer error. -aaron */
    apr_thread_cond_destroy(queue->not_empty);
    apr_thread_mutex_destroy(queue->one_big_mutex);

    return APR_SUCCESS;
}
static apr_status_t thread_pool_cleanup(void *me)
{
    apr_thread_pool_t *_myself = me;

    _myself->terminated = 1;
    apr_thread_pool_idle_max_set(_myself, 0);
    while (_myself->thd_cnt) {
        apr_sleep(20 * 1000);   /* spin lock with 20 ms */
    }
    apr_thread_mutex_destroy(_myself->lock);
    apr_thread_cond_destroy(_myself->cond);
    return APR_SUCCESS;
}
Beispiel #16
0
void gop_control_free(void *arg, int size, void *data)
{
    gop_control_t *shelf = (gop_control_t *)data;
    int i;

    for (i=0; i<size; i++) {
        apr_thread_mutex_destroy(shelf[i].lock);
        apr_thread_cond_destroy(shelf[i].cond);
    }

    free(shelf);
    return;
}
Beispiel #17
0
void mq_stream_read_destroy(mq_stream_t *mqs)
{

    log_printf(1, "START msid=%d\n", mqs->msid);

    if (mqs->mpool == NULL) {  //** Nothing to do
        pack_destroy(mqs->pack);
        if (mqs->stream_id != NULL) free(mqs->stream_id);
        free(mqs);
        return;
    }

    //** Change the flag which signals we don't want anything else
    apr_thread_mutex_lock(mqs->lock);
    mqs->want_more = MQS_ABORT;

    //** Consume all the current data and request the pending
    while ((mqs->gop_processed != NULL) || (mqs->gop_waiting != NULL)) {
        log_printf(1, "Clearing pending processed=%d waiting=%p msid=%d\n", mqs->gop_processed, mqs->gop_waiting, mqs->msid);
        if (mqs->gop_processed != NULL) log_printf(1, "processed gid=%d\n", gop_id(mqs->gop_processed));
        if (mqs->gop_waiting != NULL) log_printf(1, "waiting gid=%d\n", gop_id(mqs->gop_waiting));
        mqs->want_more = MQS_ABORT;
        apr_thread_mutex_unlock(mqs->lock);
        mq_stream_read_wait(mqs);
        apr_thread_mutex_lock(mqs->lock);
    }

    if (log_level() >= 15) {
        char *rhost = mq_address_to_string(mqs->remote_host);
        log_printf(15, "remote_host as string = %s\n", rhost);
        if (rhost) free(rhost);
    }
    if (mqs->remote_host != NULL) mq_ongoing_host_dec(mqs->ongoing, mqs->remote_host, mqs->host_id, mqs->hid_len);

    apr_thread_mutex_unlock(mqs->lock);

    log_printf(2, "msid=%d transfer_packets=%d\n", mqs->msid, mqs->transfer_packets);

    //** Clean up
    if (mqs->stream_id != NULL) free(mqs->stream_id);
    pack_destroy(mqs->pack);
    apr_thread_mutex_destroy(mqs->lock);
    apr_thread_cond_destroy(mqs->cond);
    apr_pool_destroy(mqs->mpool);
    if (mqs->remote_host != NULL) mq_msg_destroy(mqs->remote_host);
    free(mqs);

    return;
}
Beispiel #18
0
static void lost_signal(abts_case *tc, void *data)
{
    apr_status_t rv;
    apr_thread_cond_t *cond = NULL;
    apr_thread_mutex_t *mutex = NULL;

    rv = apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_DEFAULT, p);
    ABTS_SUCCESS(rv);
    ABTS_PTR_NOTNULL(tc, mutex);

    rv = apr_thread_cond_create(&cond, p);
    ABTS_SUCCESS(rv);
    ABTS_PTR_NOTNULL(tc, cond);

    rv = apr_thread_cond_signal(cond);
    ABTS_SUCCESS(rv);

    rv = apr_thread_mutex_lock(mutex);
    ABTS_SUCCESS(rv);

    rv = apr_thread_cond_timedwait(cond, mutex, 10000);
    ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));

    rv = apr_thread_mutex_unlock(mutex);
    ABTS_SUCCESS(rv);

    rv = apr_thread_cond_broadcast(cond);
    ABTS_SUCCESS(rv);

    rv = apr_thread_mutex_lock(mutex);
    ABTS_SUCCESS(rv);

    rv = apr_thread_cond_timedwait(cond, mutex, 10000);
    ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));

    rv = apr_thread_mutex_unlock(mutex);
    ABTS_SUCCESS(rv);

    rv = apr_thread_cond_destroy(cond);
    ABTS_SUCCESS(rv);

    rv = apr_thread_mutex_destroy(mutex);
    ABTS_SUCCESS(rv);
}
Beispiel #19
0
void gop_dummy_destroy()
{
    apr_status_t tstat;

//** Signal a shutdown
    apr_thread_mutex_lock(gd_lock);
    gd_shutdown = 1;
    apr_thread_cond_broadcast(gd_cond);
    apr_thread_mutex_unlock(gd_lock);

//** Wait for the thread to complete
    apr_thread_join(&tstat, gd_thread);

    //** Clean up;
    free_stack(gd_stack, 0);
    apr_thread_mutex_destroy(gd_lock);
    apr_thread_cond_destroy(gd_cond);
    apr_pool_destroy(gd_pool);
}
Beispiel #20
0
static apr_status_t queue_info_cleanup(void *data_)
{
    fd_queue_info_t *qi = data_;
    apr_thread_cond_destroy(qi->wait_for_idler);
    apr_thread_mutex_destroy(qi->idlers_mutex);

    /* Clean up any pools in the recycled list */
    for (;;) {
        struct recycled_pool *first_pool = qi->recycled_pools;
        if (first_pool == NULL) {
            break;
        }
        if (apr_atomic_casptr((void*)&(qi->recycled_pools), first_pool->next,
                              first_pool) == first_pool) {
            apr_pool_destroy(first_pool->pool);
        }
    }

    return APR_SUCCESS;
}
/*! \brief Cleanup already allocated data */
static void uni_recog_cleanup(uni_speech_t *uni_speech)
{
	if(uni_speech->speech_base) {
		uni_speech->speech_base->data = NULL;
	}
	if(uni_speech->mutex) {
		apr_thread_mutex_destroy(uni_speech->mutex);
		uni_speech->mutex = NULL;
	}
	if(uni_speech->wait_object) {
		apr_thread_cond_destroy(uni_speech->wait_object);
		uni_speech->wait_object = NULL;
	}
	if(uni_speech->media_buffer) {
		mpf_frame_buffer_destroy(uni_speech->media_buffer);
		uni_speech->media_buffer = NULL;
	}

	mrcp_application_session_destroy(uni_speech->session);
}
Beispiel #22
0
/* Destroy the audio queue. */
int audio_queue_destroy(audio_queue_t *queue)
{
	if (queue != NULL) {
		char *name = queue->name;
		if ((name == NULL) || (strlen(name) == 0))
			name = "";

		if (queue->buffer != NULL) {
			audio_buffer_zero(queue->buffer);
			audio_buffer_destroy(queue->buffer);
			queue->buffer = NULL;
		}

		if (queue->cond != NULL) {
			if (apr_thread_cond_destroy(queue->cond) != APR_SUCCESS)
				ast_log(LOG_WARNING, "(%s) Unable to destroy audio queue condition variable\n", name);

			queue->cond = NULL;
		}

		if (queue->mutex != NULL) {
			if (apr_thread_mutex_destroy(queue->mutex) != APR_SUCCESS)
				ast_log(LOG_WARNING, "(%s) Unable to destroy audio queue mutex\n", name);

			queue->mutex = NULL;
		}

		queue->name = NULL;
		queue->read_bytes = 0;
		queue->waiting = 0;
		queue->write_bytes = 0;

		ast_log(LOG_DEBUG, "(%s) Audio queue destroyed\n", name);
		if (queue->pool != NULL) {
			apr_pool_destroy(queue->pool);
		}
	}

	return 0;
}
Beispiel #23
0
void ds_ibp_destroy(data_service_fn_t *dsf)
{
    ds_ibp_priv_t *ds = (ds_ibp_priv_t *)dsf->priv;
    apr_status_t value;

    //** Wait for the warmer thread to complete
    apr_thread_mutex_lock(ds->lock);
    ds->warm_stop = 1;
    apr_thread_cond_signal(ds->cond);
    apr_thread_mutex_unlock(ds->lock);
    apr_thread_join(&value, ds->thread);  //** Wait for it to complete

    //** Now we can clean up
    apr_thread_mutex_destroy(ds->lock);
    apr_thread_cond_destroy(ds->cond);
    apr_pool_destroy(ds->pool);

    ibp_destroy_context(ds->ic);

    free(ds);
    free(dsf);
}
/*! \brief Cleanup already allocated data */
static void uni_recog_cleanup(uni_speech_t *uni_speech)
{
	if(uni_speech->speech_base) {
		uni_speech->speech_base->data = NULL;
	}
	if(uni_speech->mutex) {
		apr_thread_mutex_destroy(uni_speech->mutex);
		uni_speech->mutex = NULL;
	}
	if(uni_speech->wait_object) {
		apr_thread_cond_destroy(uni_speech->wait_object);
		uni_speech->wait_object = NULL;
	}
	if(uni_speech->media_buffer) {
		mpf_frame_buffer_destroy(uni_speech->media_buffer);
		uni_speech->media_buffer = NULL;
	}

	if(mrcp_application_session_destroy(uni_speech->session) != TRUE) {
		ast_log(LOG_WARNING, "(%s) Failed to destroy application session\n",uni_speech->name);
	}
}
Beispiel #25
0
void destroy_hportal(host_portal_t *hp)
{
    log_printf(5, "host=%s conn_list=%d closed=%d\n", hp->host, tbx_stack_count(hp->conn_list),tbx_stack_count(hp->closed_que));
    hportal_lock(hp);
    _reap_hportal(hp, 0);
    hportal_unlock(hp);

    tbx_stack_free(hp->conn_list, 1);
    tbx_stack_free(hp->que, 1);
    tbx_stack_free(hp->closed_que, 1);
    tbx_stack_free(hp->direct_list, 1);

    hp->context->fn->destroy_connect_context(hp->connect_context);

    apr_thread_mutex_destroy(hp->lock);
    apr_thread_cond_destroy(hp->cond);

    apr_pool_destroy(hp->mpool);
    log_printf(5, "destroy_hportal: Total commands processed: " I64T " (host:%s:%d)\n", hp->cmds_processed,
               hp->host, hp->port);
    free(hp);
}
static void test_timeoutcond(abts_case *tc, void *data)
{
    apr_status_t s;
    apr_interval_time_t timeout;
    apr_time_t begin, end;
    int i;

    s = apr_thread_mutex_create(&timeout_mutex, APR_THREAD_MUTEX_DEFAULT, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, s);
    ABTS_PTR_NOTNULL(tc, timeout_mutex);

    s = apr_thread_cond_create(&timeout_cond, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, s);
    ABTS_PTR_NOTNULL(tc, timeout_cond);

    timeout = apr_time_from_sec(5);

    for (i = 0; i < MAX_RETRY; i++) {
        apr_thread_mutex_lock(timeout_mutex);

        begin = apr_time_now();
        s = apr_thread_cond_timedwait(timeout_cond, timeout_mutex, timeout);
        end = apr_time_now();
        apr_thread_mutex_unlock(timeout_mutex);
        
        if (s != APR_SUCCESS && !APR_STATUS_IS_TIMEUP(s)) {
            continue;
        }
        ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(s));
        ABTS_ASSERT(tc, "Timer returned too late", end - begin - timeout < 500000);
        break;
    }
    ABTS_ASSERT(tc, "Too many retries", i < MAX_RETRY);
    APR_ASSERT_SUCCESS(tc, "Unable to destroy the conditional",
                       apr_thread_cond_destroy(timeout_cond));
}
static apr_status_t thread_pool_construct(apr_thread_pool_t * me,
                                          apr_size_t init_threads,
                                          apr_size_t max_threads)
{
    apr_status_t rv;
    int i;

    me->thd_max = max_threads;
    me->idle_max = init_threads;
    me->threshold = init_threads / 2;
    rv = apr_thread_mutex_create(&me->lock, APR_THREAD_MUTEX_NESTED,
                                 me->pool);
    if (APR_SUCCESS != rv) {
        return rv;
    }
    rv = apr_thread_cond_create(&me->cond, me->pool);
    if (APR_SUCCESS != rv) {
        apr_thread_mutex_destroy(me->lock);
        return rv;
    }
    me->tasks = apr_palloc(me->pool, sizeof(*me->tasks));
    if (!me->tasks) {
        goto CATCH_ENOMEM;
    }
    APR_RING_INIT(me->tasks, apr_thread_pool_task, link);
    me->scheduled_tasks = apr_palloc(me->pool, sizeof(*me->scheduled_tasks));
    if (!me->scheduled_tasks) {
        goto CATCH_ENOMEM;
    }
    APR_RING_INIT(me->scheduled_tasks, apr_thread_pool_task, link);
    me->recycled_tasks = apr_palloc(me->pool, sizeof(*me->recycled_tasks));
    if (!me->recycled_tasks) {
        goto CATCH_ENOMEM;
    }
    APR_RING_INIT(me->recycled_tasks, apr_thread_pool_task, link);
    me->busy_thds = apr_palloc(me->pool, sizeof(*me->busy_thds));
    if (!me->busy_thds) {
        goto CATCH_ENOMEM;
    }
    APR_RING_INIT(me->busy_thds, apr_thread_list_elt, link);
    me->idle_thds = apr_palloc(me->pool, sizeof(*me->idle_thds));
    if (!me->idle_thds) {
        goto CATCH_ENOMEM;
    }
    APR_RING_INIT(me->idle_thds, apr_thread_list_elt, link);
    me->recycled_thds = apr_palloc(me->pool, sizeof(*me->recycled_thds));
    if (!me->recycled_thds) {
        goto CATCH_ENOMEM;
    }
    APR_RING_INIT(me->recycled_thds, apr_thread_list_elt, link);
    me->thd_cnt = me->idle_cnt = me->task_cnt = me->scheduled_task_cnt = 0;
    me->tasks_run = me->tasks_high = me->thd_high = me->thd_timed_out = 0;
    me->spawning_cnt = 0;
    me->idle_wait = 0;
    me->terminated = 0;
    for (i = 0; i < TASK_PRIORITY_SEGS; i++) {
        me->task_idx[i] = NULL;
    }
    goto FINAL_EXIT;
  CATCH_ENOMEM:
    rv = APR_ENOMEM;
    apr_thread_mutex_destroy(me->lock);
    apr_thread_cond_destroy(me->cond);
  FINAL_EXIT:
    return rv;
}
/*
 * Program entry point.
 */
int
main(int argc, char** argv)
{
        /*
         * Standard command-line parsing.
         */
        const HASH_T *options = parse_cmdline(argc, argv, arg_opts);
        if(options == NULL || hash_get(options, "help") != NULL) {
                show_usage(argc, argv, arg_opts);
                return EXIT_FAILURE;
        }

        const char *url = hash_get(options, "url");
        const char *principal = hash_get(options, "principal");
        CREDENTIALS_T *credentials = NULL;
        const char *password = hash_get(options, "credentials");
        if(password != NULL) {
                credentials = credentials_create_password(password);
        }
        const char *topic_name = hash_get(options, "topic");
        const long seconds = atol(hash_get(options, "seconds"));

        /*
         * Setup for condition variable.
         */
        apr_initialize();
        apr_pool_create(&pool, NULL);
        apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_UNNESTED, pool);
        apr_thread_cond_create(&cond, pool);

        /*
         * Create a session with the Diffusion server.
         */
        SESSION_T *session;
        DIFFUSION_ERROR_T error = { 0 };
        session = session_create(url, principal, credentials, NULL, NULL, &error);
        if(session == NULL) {
                fprintf(stderr, "TEST: Failed to create session\n");
                fprintf(stderr, "ERR : %s\n", error.message);
                return EXIT_FAILURE;
        }

        /*
         * Create a topic holding simple string content.
         */
        TOPIC_DETAILS_T *string_topic_details = create_topic_details_single_value(M_DATA_TYPE_STRING);
        const ADD_TOPIC_PARAMS_T add_topic_params = {
                .topic_path = topic_name,
                .details = string_topic_details,
                .on_topic_added = on_topic_added,
                .on_topic_add_failed = on_topic_add_failed,
                .on_discard = on_topic_add_discard,
        };

        apr_thread_mutex_lock(mutex);
        add_topic(session, add_topic_params);
        apr_thread_cond_wait(cond, mutex);
        apr_thread_mutex_unlock(mutex);

        topic_details_free(string_topic_details);

        /*
         * Define the handlers for add_update_source()
         */
        const UPDATE_SOURCE_REGISTRATION_PARAMS_T update_reg_params = {
                .topic_path = topic_name,
                .on_init = on_update_source_init,
                .on_registered = on_update_source_registered,
                .on_active = on_update_source_active,
                .on_standby = on_update_source_standby,
                .on_close = on_update_source_closed
        };

        /*
         * Register an updater.
         */
        apr_thread_mutex_lock(mutex);
        CONVERSATION_ID_T *updater_id = register_update_source(session, update_reg_params);
        apr_thread_cond_wait(cond, mutex);
        apr_thread_mutex_unlock(mutex);

        /*
         * Define default parameters for an update source.
         */
        UPDATE_SOURCE_PARAMS_T update_source_params_base = {
                .updater_id = updater_id,
                .topic_path = topic_name,
                .on_success = on_update_success,
                .on_failure = on_update_failure
        };

        time_t end_time = time(NULL) + seconds;

        while(time(NULL) < end_time) {

                if(active) {
                        /*
                         * Create an update structure containing the current time.
                         */
                        BUF_T *buf = buf_create();
                        const time_t time_now = time(NULL);
                        buf_write_string(buf, ctime(&time_now));

                        CONTENT_T *content = content_create(CONTENT_ENCODING_NONE, buf);

                        UPDATE_T *upd = update_create(UPDATE_ACTION_REFRESH,
                                                      UPDATE_TYPE_CONTENT,
                                                      content);

                        UPDATE_SOURCE_PARAMS_T update_source_params = update_source_params_base;
                        update_source_params.update = upd;

                        /*
                         * Update the topic.
                         */
                        update(session, update_source_params);

                        content_free(content);
                        update_free(upd);
                        buf_free(buf);
                }

                sleep(1);
        }

        if(active) {
                UPDATE_SOURCE_DEREGISTRATION_PARAMS_T update_dereg_params = {
                        .updater_id = updater_id,
                        .on_deregistered = on_update_source_deregistered
                };

                apr_thread_mutex_lock(mutex);
                deregister_update_source(session, update_dereg_params);
                apr_thread_cond_wait(cond, mutex);
                apr_thread_mutex_unlock(mutex);
        }

        /*
         * Close session and free resources.
         */
        session_close(session, NULL);
        session_free(session);

        conversation_id_free(updater_id);
        credentials_free(credentials);

        apr_thread_mutex_destroy(mutex);
        apr_thread_cond_destroy(cond);
        apr_pool_destroy(pool);
        apr_terminate();

        return EXIT_SUCCESS;

}
Beispiel #29
0
SWITCH_DECLARE(switch_status_t) switch_thread_cond_destroy(switch_thread_cond_t *cond)
{
	return apr_thread_cond_destroy(cond);
}
Beispiel #30
0
LLCondition::~LLCondition()
{
	apr_thread_cond_destroy(mAPRCondp);
	mAPRCondp = NULL;
}