Esempio n. 1
0
//============================================================================
//		NThreadPool::SchedulePriority : Priority scheduler.
//----------------------------------------------------------------------------
void NThreadPool::SchedulePriority(NThreadTaskList &theTasks)
{


	// Sort the list
	std::sort(theTasks.begin(), theTasks.end(), ComparePriority());
}
Esempio n. 2
0
MasterSchedulerBackend::Comparison MasterSchedulerBackend::GetBestTaskToRun(const openpal::MonotonicTimestamp& now,
                                                                            const Record& left,
                                                                            const Record& right)
{
    const auto BEST_ENABLED_STATUS = CompareEnabledStatus(left, right);

    if (BEST_ENABLED_STATUS != Comparison::SAME)
    {
        // if one task is disabled, return the other task
        return BEST_ENABLED_STATUS;
    }

    const auto BEST_BLOCKED_STATUS = CompareBlockedStatus(left, right);

    if (BEST_BLOCKED_STATUS != Comparison::SAME)
    {
        // if one task is blocked and the other isn't, return the unblocked task
        return BEST_BLOCKED_STATUS;
    }

    const auto EARLIEST_EXPIRATION = CompareTime(now, left, right);
    const auto BEST_PRIORITY = ComparePriority(left, right);

    // if the expiration times are the same, break based on priority, otherwise go with the expiration time
    return (EARLIEST_EXPIRATION == Comparison::SAME) ? BEST_PRIORITY : EARLIEST_EXPIRATION;
}