juce_setThreadPriority code question


#1

Jules,

The following code appears in the Linux version of juce_setThreadPriority:

        int pri = ((maxp - minp) / 2) * (priority - 1) / 9;

        if (param.sched_priority >= (minp + (maxp - minp) / 2))
            param.sched_priority = minp + ((maxp - minp) / 2) + pri;  // (realtime)
        else
            param.sched_priority = minp + pri;  // (high)

        param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);

The last assignment to ‘param.sched_priority’ nullifies the assigment done in the previous if statement. I’m not sure what your intention was, but I thought I would point it out to you… :slight_smile:

-cpr


#2

Thanks for spotting that, it really is garbage! No idea what I was thinking when I wrote that - it’s very old code!

I think the first section of code might just be something that I meant to delete, and it should just read:

if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0 && policy != SCHED_OTHER) { param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11); return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0; }

…so in fact it would have worked fine, but was doing some unnecessary stuff.