TNLPriority TNLConvertGCDQOSToTNLPriority()

in Source/TNLPriority.m [114:160]


TNLPriority TNLConvertGCDQOSToTNLPriority(qos_class_t gcdQOS)
{
    if (gcdQOS == QOS_CLASS_DEFAULT) {
        return (QOS_CLASS_USER_INITIATED + QOS_CLASS_UTILITY) / 2;
    }

    // Below I will denote how much of the range of possibilities remain with comments
    // [] == bounded inclusive
    // () == bounded exclusive
    // Example:
    //    [Val1...Val2) == "from Val1 inclusive to Val2 exclusive"


    // [INF...INF]

    if (gcdQOS > QOS_CLASS_USER_INITIATED) {
        return TNLPriorityVeryHigh + 1;
    }

    // [INF...UserInitiated]

    if (gcdQOS < QOS_CLASS_BACKGROUND) {
        return TNLPriorityVeryLow - 1;
    }

    // [Background...UserInitiated]

    if (gcdQOS < QOS_CLASS_UTILITY) {
        return TNLPriorityVeryLow;
    }

    // [Utility...UserInitiated]

    if (gcdQOS == QOS_CLASS_UTILITY) {
        return TNLPriorityLow;
    }

    // (Utility...UserInitiated]

    if (gcdQOS <= ((QOS_CLASS_USER_INITIATED + QOS_CLASS_UTILITY) / 2)) {
        return TNLPriorityNormal;
    }

    // (Default...UserInitiated]

    return TNLPriorityHigh;
}