Esempio n. 1
0
static apt_bool_t apt_poller_task_run(apt_task_t *base)
{
	apt_poller_task_t *task = apt_task_object_get(base);
	apt_bool_t running = TRUE;
	apr_status_t status;
	apr_int32_t num;
	const apr_pollfd_t *ret_pfd;
	apr_interval_time_t timeout;
	apr_uint32_t queue_timeout;
	apr_time_t time_now, time_last = 0;
	int i;
	const char *task_name;

	if(!task) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Start Poller Task");
		return FALSE;
	}
	task_name = apt_task_name_get(task->base),

	/* explicitly indicate task is ready to process messages */
	apt_task_ready(task->base);

	while(running) {
		if(apt_timer_queue_timeout_get(task->timer_queue,&queue_timeout) == TRUE) {
			timeout = queue_timeout * 1000;
			time_last = apr_time_now();
			apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Wait for Messages [%s] timeout [%lu]",
				task_name, queue_timeout);
		}
		else {
			timeout = -1;
			apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Wait for Messages [%s]",task_name);
		}
		status = apt_pollset_poll(task->pollset, timeout, &num, &ret_pfd);
		if(status != APR_SUCCESS && status != APR_TIMEUP) {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Poll status: %d",status);
			continue;
		}
		for(i = 0; i < num; i++) {
			if(apt_pollset_is_wakeup(task->pollset,&ret_pfd[i])) {
				apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process Poller Wakeup [%s]",task_name);
				if(apt_poller_task_wakeup_process(task) == FALSE) {
					running = FALSE;
					break;
				}
				continue;
			}

			apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process Signalled Descriptor [%s]",task_name);
			task->signal_handler(task->obj,&ret_pfd[i]);
		}

		if(timeout != -1) {
			time_now = apr_time_now();
			if(time_now > time_last) {
				apt_timer_queue_advance(task->timer_queue,(apr_uint32_t)((time_now - time_last)/1000));
			}
		}
	}

	return TRUE;
}
Esempio n. 2
0
static apt_bool_t apt_consumer_task_run(apt_task_t *task)
{
	apr_status_t rv;
	void *msg;
	apt_bool_t *running;
	apt_consumer_task_t *consumer_task;
#if APR_HAS_QUEUE_TIMEOUT
	apr_interval_time_t timeout;
	apr_uint32_t queue_timeout;
	apr_time_t time_now, time_last = 0;
#endif
	const char *task_name;

	consumer_task = apt_task_object_get(task);
	if(!consumer_task) {
		return FALSE;
	}
	task_name = apt_task_name_get(consumer_task->base),

	running = apt_task_running_flag_get(task);
	if(!running) {
		return FALSE;
	}

	while(*running) {
#if APR_HAS_QUEUE_TIMEOUT
		if(apt_timer_queue_timeout_get(consumer_task->timer_queue,&queue_timeout) == TRUE) {
			timeout = (apr_interval_time_t)queue_timeout * 1000;
			time_last = apr_time_now();
			apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Wait for Messages [%s] timeout [%u]",
				task_name, queue_timeout);
			rv = apr_queue_timedpop(consumer_task->msg_queue,timeout,&msg);
		}
		else
		{
			timeout = -1;
			apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Wait for Messages [%s]",task_name);
			rv = apr_queue_pop(consumer_task->msg_queue,&msg);
		}
#else
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Wait for Messages [%s]",task_name);
		rv = apr_queue_pop(consumer_task->msg_queue,&msg);
#endif
		if(rv == APR_SUCCESS) {
			if(msg) {
				apt_task_msg_t *task_msg = msg;
				apt_task_msg_process(consumer_task->base,task_msg);
			}
		}
		else if(rv != APR_TIMEUP) {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Pop Message [%s] status: %d",task_name,rv);
		}

#if APR_HAS_QUEUE_TIMEOUT
		if(timeout != -1) {
			time_now = apr_time_now();
			if(time_now > time_last) {
				apt_timer_queue_advance(consumer_task->timer_queue,(apr_uint32_t)((time_now - time_last)/1000));
			}
		}
#endif
	}
	return TRUE;
}