struct fast_task_info *free_queue_pop()
{
    struct fast_task_info *pTask;
	if ((pTask=task_queue_pop(&g_free_queue)) != NULL)
    {
        return pTask;
    }

    if (g_free_queue.alloc_connections >= g_free_queue.max_connections)
    {
        return NULL;
    }

	pthread_mutex_lock(&g_free_queue.lock);
    if (g_free_queue.alloc_connections >= g_free_queue.max_connections)
    {
        if (g_free_queue.head == NULL)
        {
            pthread_mutex_unlock(&g_free_queue.lock);
            return NULL;
        }
    }
    else
    {
        if (free_queue_realloc() != 0)
        {
            pthread_mutex_unlock(&g_free_queue.lock);
            return NULL;
        }
    }
	pthread_mutex_unlock(&g_free_queue.lock);

    return task_queue_pop(&g_free_queue);
}
static void
*task_consum(void *pl) {
    thread_pool_t p=NULL;
    task_t t=NULL;
    routine_t r=NULL;
    arg_t a=NULL;

    assert(pl!=NULL);
    p=*(thread_pool_t *) pl;
    assert(p!=NULL);
    assert(p->tasks!=NULL);
    _Y
    while(!p->pool_finish) {
        p->tasks=task_queue_pop(p->tasks,&t);
        _Y
        assert(t!=NULL);
        _Y
        /* take the routine and the argument and execute it */
        r=task_routine(t);
        _Y
        a=task_arg(t);
        _Y
        t=task_destroy(t);
        _Y
        t=NULL;
        assert(r!=NULL);
        r(a); /* execute the routine */
    }
    pthread_mutex_lock(&p->mutex);
    p->finalizados++;
    pthread_mutex_unlock(&p->mutex);

    pthread_exit(NULL);
}
Beispiel #3
0
/** 
* the callback function when the task queue got item
* @param   fd: the pipe which got a read event  
* @param   which: not use
* @param   arg: param send to the callback function
************************************************************/
static void server_taskitem_got(int fd, short which, void *arg) {

	task_thread_t *me = (task_thread_t*)arg;
	task_queue_item_t *item;
	char buf[1];
	message_t message;
	memset( &message, 0, sizeof(message_t) );

	message_t message_out;
	connection_t *connection;
	char *action;

	//LM_DBG("handle a new taskitem, [%d]\n", fd);

	if (read(fd, buf, 1) != 1) {}

	item = task_queue_pop(me->new_task_queue);
	message = item->task_data.msg;
	
	if (NULL != item) {
		memset(&message_out, 0, sizeof(message_t));
		message = item->task_data.msg;
		connection = message.connection;
		action = (char*)emp_get_header(&message, "Action");

		task_queue_item_free(&server_threads_manager,item);
		
		//LM_DBG( "ActionID is [%s], Event is [%s]\n", actionid, event);

		emp_server_message_handler_t *handles = NULL;
		
		handles = (emp_server_message_handler_t*)	server_find_handle(ACTION, action);
		if (handles){
			handles->handle_fun(connection, &message);	
			return;
		}
	}
	
}
Beispiel #4
0
struct fast_task_info *free_queue_pop()
{
	return task_queue_pop(&g_free_queue);;
}