Exemple #1
0
/// choose a task and assign it to cellet
void* ScheduleProcessor(void* unused) {
    while (true) {
        // pick a task from the framework pool
        TaskPtr task = ComponentsMgr::Instance()->GetPool()->GetTask();
        // has wait task then begin to assign the task
        if (task.get()) {
            // task asssign success change task state to started
            if (task->AssignTask())
                task->TaskAssigned();
            else
                ComponentsMgr::Instance()->GetPool()->AddTask(task);
        }
        usleep(1000*50);
    }
    return NULL;
}
void ThreadGroup::schedule(TaskPtr task)
{
    apex_assert_hard(!destroyed_);

    std::unique_lock<std::recursive_mutex> tasks_lock(tasks_mtx_);

    if (!tasks_.empty()) {
        //        for(const TaskPtr& t : tasks_) {
        for (auto it = tasks_.begin(); it != tasks_.end(); ++it) {
            const TaskPtr& t = *it;
            if (t.get() == task.get()) {
                return;
            }
        }
    }

    tasks_.insert(task);

    task->setScheduled(true);

    work_available_.notify_all();
}