Esempio n. 1
0
void scheduler_delete(struct scheduler *sched) {
    if (!sched) {
        return;
    }

    // shut everyone down
    pthread_mutex_lock(&sched->run_state.lock);
    sched->run_state.state = SCHED_SHUTDOWN;
    pthread_cond_broadcast(&sched->run_state.running);
    pthread_mutex_unlock(&sched->run_state.lock);

    worker_t *worker = NULL;
    for (int i = 1; i < sched->n_workers; ++i) {
        worker = scheduler_get_worker(sched, i);
        _join(worker);
    }
    log_sched("joined worker threads.\n");
    // unbind this thread's worker
    self = NULL;

    system_barrier_destroy(&sched->barrier);

    if (sched->workers) {
        for (int i = 0, e = sched->n_workers; i < e; ++i) {
            worker_t *worker = scheduler_get_worker(sched, i);
            worker_fini(worker);
        }
        free(sched->workers);
    }

    free(sched);
}
Esempio n. 2
0
File: edp.c Progetto: konghan/edp.io
int edp_init(int thread_num){
    int	    ret = -1;

    ret = logger_init();
    if(ret != 0){
	return ret;
    }

    // FIXME:pre-alloc memory for your application
    ret = mcache_init(NULL, 0);
    if(ret != 0){
	log_warn("mcache init fail:%d\n", ret);
	goto exit_mcache;
    }

    ret = hset_init();
    if(ret != 0){
	log_warn("hset init fail:%d\n", ret);
	goto exit_hset;
    }

    ret = worker_init(thread_num);
    if(ret != 0){
	log_warn("init worker fail:%d\n", ret);
	goto exit_worker;
    }

    ret = emit_init();
    if(ret != 0){
	log_warn("init emitter fail:%d\n", ret);
	goto exit_emit;
    }

    ret = edpnet_init();
    if(ret != 0){
	log_warn("init edpnet fail:%d\n", ret);
	goto exit_net;
    }

    log_info("edp have been initialized!\n");

    return 0;

exit_net:
    emit_fini();

exit_emit:
    worker_fini();

exit_worker:
    hset_fini();

exit_hset:
    mcache_fini();

exit_mcache:
    logger_fini();

    return ret;
}
Esempio n. 3
0
File: edp.c Progetto: konghan/edp.io
int edp_fini(){

    edpnet_fini();

    emit_fini();

    worker_fini();

    hset_fini();

    mcache_fini();

    logger_fini();

    return 0;
}