Esempio n. 1
0
File: core.c Progetto: k0a1a/pom-ng
int core_set_state(enum core_state state) {

	int res = POM_OK;

	pom_mutex_lock(&core_state_lock);

	if (core_cur_state == state) {
		pomlog(POMLOG_DEBUG "Core state unchanged : %u", state);
		pom_mutex_unlock(&core_state_lock);
		return POM_OK;
	}

	core_cur_state = state;
	pomlog(POMLOG_DEBUG "Core state changed to %u", state);
	if (pthread_cond_broadcast(&core_state_cond)) {
		pomlog(POMLOG_ERR "Unable to signal core state condition : %s", pom_strerror(errno));
		pom_mutex_unlock(&core_state_lock);
		return POM_ERR;
	}
	pom_mutex_unlock(&core_state_lock);

	if (state == core_state_idle) {

		res = core_processing_stop();

		ptime now = pom_gettimeofday();

		int i;
		for (i = 0; i < CORE_PROCESS_THREAD_MAX; i++)
			core_clock[i] = 0;

		ptime runtime = now - core_start_time;

		pomlog(POMLOG_INFO "Core was running for %u.%06u secs", pom_ptime_sec(runtime), pom_ptime_usec(runtime));

	} else if (state == core_state_running) {
		core_start_time = pom_gettimeofday();
		res = core_processing_start();
	} else if (state == core_state_finishing) {
		// Signal all the threads
		unsigned int i;
		for (i = 0; i < core_num_threads; i++) {
			struct core_processing_thread *t = core_processing_threads[i];

			pom_mutex_lock(&t->pkt_queue_lock);
			int res = pthread_cond_broadcast(&t->pkt_queue_cond);
			pom_mutex_unlock(&t->pkt_queue_lock);
			if (res) {
				pomlog(POMLOG_ERR "Error while broadcasting restart condition after set state");
				abort();
			}
		}
	}
	return res;
}
Esempio n. 2
0
int core_set_state(enum core_state state) {

	int res = POM_OK;

	pom_mutex_lock(&core_state_lock);
	core_cur_state = state;
	pomlog(POMLOG_DEBUG "Core state changed to %u", state);
	if (pthread_cond_broadcast(&core_state_cond)) {
		pomlog(POMLOG_ERR "Unable to signal core state condition : %s", pom_strerror(errno));
		pom_mutex_unlock(&core_state_lock);
		return POM_ERR;
	}

	if (state == core_state_idle) {

		res = core_processing_stop();

		struct timeval now;
		gettimeofday(&now, NULL);
		if (now.tv_usec < core_start_time.tv_usec) {
			now.tv_sec--;
			now.tv_usec += 1000000;
		}
		pom_mutex_lock(&core_clock_lock);
		memset(&core_clock, 0, sizeof(struct timeval));
		pom_mutex_unlock(&core_clock_lock);


		now.tv_usec -= core_start_time.tv_usec;
		now.tv_sec -= core_start_time.tv_sec;
		pomlog(POMLOG_INFO "Core was running for %u.%06u secs", now.tv_sec, now.tv_usec);

	} else if (state == core_state_running) {
		gettimeofday(&core_start_time, NULL);
		res = core_processing_start();
	} else if (state == core_state_finishing) {
		//pom_mutex_lock(&core_pkt_queue_mutex);
		if (pthread_cond_broadcast(&core_pkt_queue_restart_cond)) {
			pom_mutex_unlock(&core_pkt_queue_mutex);
			pom_mutex_unlock(&core_state_lock);
			pomlog(POMLOG_ERR "Error while broadcasting restart condition after set state");
			return POM_ERR;
		}
		//pom_mutex_unlock(&core_pkt_queue_mutex);
	}
	pom_mutex_unlock(&core_state_lock);
	return res;
}