Esempio n. 1
0
int timer_cleanup(struct timer *t) {

	if (t->queue)
		timer_dequeue(t);

	free(t);
	
	return POM_OK;
}
Esempio n. 2
0
int timer_cleanup(struct timer *t) {

	if (t->queue)
		timer_dequeue(t);

	free(t);
	
	registry_perf_dec(perf_timer_allocated, 1);

	return POM_OK;
}
Esempio n. 3
0
void timer_execute()
{
	void (*hdl) (void *);
	void *hdl_arg = NULL;
	int ret = 0;

	if (timerq.first != NULL) {
		hdl = timerq.first->handler;
		hdl_arg = timerq.first->handler_arg;
		pthread_mutex_lock(&timerq.mutex);
		timer_dequeue(timerq.first);
		pthread_mutex_unlock(&timerq.mutex);
		
		if (hdl) {
			ret = add_timeout_list(hdl, hdl_arg);
			if (ret != 0) {
				fprintf(std_err, "add_timeout_list() failed, err: %d,[%s]", errno, strerror(errno));
				return;
			}

			pthread_mutex_lock(&timeout_mutex);
			if (timeout_thread_is_on == 0) {
				timeout_thread_is_on = 1;
				pthread_mutex_unlock(&timeout_mutex);
				
				pthread_t thread_id;
				pthread_attr_t attr;
				pthread_attr_init(&attr);
				
				pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
				
				ret = pthread_create(&thread_id, &attr, time_out_task, NULL);
				if (ret != 0) {
					fprintf(std_err, "pthread_create() failed, err: %d,[%s]", errno, strerror(errno));
					pthread_mutex_lock(&timeout_mutex);
					timeout_thread_is_on = 0;
					pthread_mutex_unlock(&timeout_mutex);
					return;
				}
			}else {
				pthread_cond_signal(&timeout_cond);
				pthread_mutex_unlock(&timeout_mutex);
			}
		}
	} else {
		fprintf(std_err, "timerq.first is null.\n");
	}

	return ;
}
Esempio n. 4
0
int conntrack_delayed_cleanup(struct conntrack_entry *ce, unsigned int delay, ptime now) {

	if (!delay) {
		if (ce->cleanup_timer && ce->cleanup_timer != (void*)-1) {
			timer_dequeue(ce->cleanup_timer->timer);
			timer_cleanup(ce->cleanup_timer->timer);
			free(ce->cleanup_timer);
			ce->cleanup_timer = NULL;
		}
		return POM_OK;
	}

	if (ce->cleanup_timer == (void *) -1) {
		debug_conntrack("Not queuing timer for conntrack %p as it is currently being cleaned up", ce);
		return POM_OK;
	}

	if (!ce->cleanup_timer) {
		ce->cleanup_timer = malloc(sizeof(struct conntrack_timer));
		if (!ce->cleanup_timer) {
			pom_oom(sizeof(struct conntrack_timer));
			return POM_ERR;
		}
		ce->cleanup_timer->timer = timer_alloc(ce->cleanup_timer, conntrack_timed_cleanup);
		if (!ce->cleanup_timer->timer) {
			free(ce->cleanup_timer);
			ce->cleanup_timer = NULL;
			return POM_ERR;
		}

		ce->cleanup_timer->ce = ce;
		ce->cleanup_timer->proto = ce->proto;
		ce->cleanup_timer->hash = ce->hash;
		

	}

	timer_queue_now(ce->cleanup_timer->timer, delay, now);

	return POM_OK;
}
Esempio n. 5
0
int del_all_timer(int need_destrory)
{
	tl_timer_t *t;

	pthread_mutex_lock(&timerq.mutex);
	t = timerq.last;
	while (t != NULL) {
		timer_dequeue(t);
		t = timerq.last;
	}
	pthread_mutex_unlock(&timerq.mutex);
	
	if (need_destrory) {
		pthread_mutex_destroy(&timerq.mutex);
		pthread_mutex_destroy(&timeout_mutex);
		pthread_cond_destroy(&timeout_cond);
		fclose(std_err);
		pthread_exit(NULL);
	}
	return 0;
}
Esempio n. 6
0
int del_timernode_from_list(tl_timer_t *msg)
{
	tl_timer_t *t;

	if (msg->id == -1) {
		return -1;
	}

	pthread_mutex_lock(&timerq.mutex);
	t = timerq.first;

	/* look for timer id */
	while (t != NULL) {

		if (t->id == msg->id)
			break;
		t = t->next;
	}

	if (t == NULL) {
		/* timer id is not in queue (maybe empty) */
		pthread_mutex_unlock(&timerq.mutex);
		return -1;
	}

	/* timer id is in the queue */
	if (msg->handler) {
		msg->handler(t->handler_arg);
		t->handler_arg = NULL;
	}
	
	timer_dequeue(t);

	pthread_mutex_unlock(&timerq.mutex);

	return 0;
}
Esempio n. 7
0
int conntrack_timer_dequeue(struct conntrack_timer *t) {
	return timer_dequeue(t->timer);
}