Beispiel #1
0
int session_mgr_start(session_mgr_t *mgr)
{
	if (mgr == NULL) {
		LOG_ERROR("Invalid session mgr");
		return ZISS_ERROR;
	}

	int is_ok = ZISS_ERROR;
	do {
		if (thread_new(&mgr->thread) == ZISS_ERROR) {
			LOG_ERROR("Fail to new thread");
			break;
		}

		if (cond_new(&mgr->exit_cond) == ZISS_ERROR) {
			LOG_ERROR("Fail to new cond");
			break;
		}

		if (thread_start(mgr->thread, _session_mgr_thread, mgr) == ZISS_ERROR) {
			cond_delete(mgr->exit_cond);
			LOG_ERROR("Fail to start thread");
			break;
		}

		is_ok = ZISS_OK;
	} while (0);

	if (is_ok == ZISS_ERROR) {
		session_mgr_stop(mgr);
	}

	return is_ok;
}
Beispiel #2
0
COND * cond_create() {
    COND * c = (COND*) malloc(sizeof (COND));
    memset(c, 0, sizeof (COND));
    c->lock = mutex_create(1);
    c->wait_sem = mutex_create(MAX_SEMAPHORE);
    c->wait_done = mutex_create(MAX_SEMAPHORE);
    c->waiting = c->signals = 0;
    if (!c->lock || !c->wait_sem || !c->wait_done) {
        cond_delete(c);
        c = NULL;
    }
    return c;
};
Beispiel #3
0
int session_mgr_stop(session_mgr_t *mgr)
{
	if (mgr == NULL) {
		LOG_ERROR("Invalid session mgr");
		return ZISS_ERROR;
	}

	if (mgr->thread != NULL) {
		cond_signal(mgr->exit_cond);
		thread_stop(mgr->thread);
		thread_delete(mgr->thread);
		cond_delete(mgr->exit_cond);
		mgr->thread = NULL;
		mgr->exit_cond = NULL;
	}
	session_mgr_clear(mgr);

	return ZISS_OK;
}