Helixis 1.0
Task Programming API
Functions | Variables
sources/sched.c File Reference
#include "hlx/core.h"
#include "helixis_internal.h"

Go to the source code of this file.

Functions

void hlx_scheduler_construct (void)
void hlx_scheduler_destruct (void)
hlx_group_id hlx_core_create_group (void)
hlx_grouphlx_sheduler_find_lighter_group (void)
void hlx_core_add_task_in_group (hlx_task_func task_func, void *data, hlx_group_id group_id)
void hlx_core_add_task (hlx_task_func task_func, void *data)
hlx_taskhlx_scheduler_init_task (hlx_task_func task_func, void *data, hlx_group *group, hlx_task_callback callback)
int hlx_scheduler_schedule_group (hlx_group *group)

Variables

hlx_api gl_api
hlx_scheduler gl_scheduler

Function Documentation

void hlx_core_add_task ( hlx_task_func  task,
void *  data 
)

Add a task in the lighter group

Parameters:
taskThe task to push.
dataUser argument (optionnal).
See also:
hlx_core_add_task_in_group()

Definition at line 134 of file sched.c.

References hlx_core_add_task_in_group_callback(), and hlx_sheduler_find_lighter_group().

void hlx_core_add_task_in_group ( hlx_task_func  task,
void *  data,
hlx_group_id  group_id 
)

Add a task in a group

Parameters:
taskThe task to push.
dataUser argument (optionnal).
group_idGroup id where the task will be pushed.
See also:
hlx_core_create_group()
hlx_core_add_task()

Definition at line 129 of file sched.c.

References hlx_core_add_task_in_group_callback().

{
        hlx_core_add_task_in_group_callback(task_func, data, group_id, 0, 0);
}
hlx_group_id hlx_core_create_group ( void  )

Create a new group of tasks in the scheduler

See also:
hlx_core_add_task_in_group()
Returns:
The new group ID.

Definition at line 93 of file sched.c.

References hlx_scheduler::groups, hlx_group_construct(), hlx_list_push_back(), hlx_group::id, and hlx_api::malloc_entry.

{
        hlx_group* g;

        if ((g = gl_api.malloc_entry(sizeof(*g))) == 0)
           return ((hlx_group_id)-1);
    hlx_group_construct(g);
        hlx_list_push_back(&gl_scheduler.groups, g);
        return (g->id);
}
void hlx_scheduler_construct ( void  )
void hlx_scheduler_destruct ( void  )
hlx_task* hlx_scheduler_init_task ( hlx_task_func  task_func,
void *  data,
hlx_group group,
hlx_task_callback  callback 
)

Definition at line 139 of file sched.c.

References hlx_task::callback, hlx_task::ctx, hlx_task::data, hlx_task::group_id, HLX_TASK_STATUS_RUN, hlx_group::id, hlx_api::malloc_entry, hlx_task::stack, hlx_task::status, and hlx_task::task_func.

Referenced by hlx_core_add_task_in_group_callback(), and hlx_core_add_task_in_group_callback2().

{
        hlx_task* task;

        task = gl_api.malloc_entry(sizeof (*task));
        if (!task)
                return (0);
        task->status = HLX_TASK_STATUS_RUN;
        task->task_func = task_func;
        task->data = data;
        task->stack = 0;
        task->group_id = group->id;
        task->callback = callback;
        task->ctx = 0;
        return (task);
}
int hlx_scheduler_schedule_group ( hlx_group group)

Definition at line 156 of file sched.c.

References hlx_task::callback, hlx_task::ctx, hlx_task::data, _hlx_list_node::data, hlx_list::first, hlx_api::free_entry, hlx_task::group_id, HLX_ENDED, HLX_EXITED, hlx_list_erase(), HLX_MEMORY_EXHAUSTED, HLX_TASK_STATUS_RUN, _hlx_list_node::next, hlx_task::stack, hlx_task::status, hlx_task::task_func, and hlx_group::tasks.

{
        hlx_list_node* it;
        hlx_list_node* tmp;
        hlx_task* task;
        int loop;
        int ret;

        loop = 0;
        it = group->tasks.first;
        while (it)
        {
                task = it->data;
                if (task->status != HLX_TASK_STATUS_RUN)
                {
                        it = it->next;
                        continue;
                }
                if (!task->task_func)
                        ret = HLX_EXITED;
                else
                        ret = task->task_func(&(task->ctx), task->group_id, &(task->stack), task->data);
                if (ret == HLX_ENDED || ret == HLX_EXITED || ret == HLX_MEMORY_EXHAUSTED)
                {
                        if (task->callback != 0)
                                task->callback(task->data, task->group_id, ret);
                        if (task->stack != 0)
                                gl_api.free_entry(task->stack);
                        gl_api.free_entry(task);
                        tmp = it->next;
                        hlx_list_erase(&group->tasks, it);
                        it = tmp;
                }
                else
                {
                        loop = 1;
                        it = it->next;
                }
        }
        return (loop);
}
hlx_group* hlx_sheduler_find_lighter_group ( void  )

Definition at line 104 of file sched.c.

References hlx_scheduler::cpu_count, hlx_scheduler::default_groups_id, and hlx_group_get_size().

Referenced by hlx_core_add_task(), and hlx_core_add_task_callback().

{
        unsigned int i;
        unsigned int best_size;
        unsigned int group_size;
        hlx_group* best;
        hlx_group* group;

    best_size = 0;
    group_size = 0;
    best = 0;
    group = 0;
    for (i = 0; i < gl_scheduler.cpu_count; ++i)
    {
        group = (hlx_group*)(gl_scheduler.default_groups_id[i]);
        group_size = hlx_group_get_size(group);
        if (best == 0 || best_size > group_size)
        {
                best = group;
                best_size = group_size;
        }
    }
    return (group);
}

Variable Documentation

Definition at line 42 of file api.c.

Definition at line 50 of file parallel_sched.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines