cvs commit: src/sys/kern sched_ule.c
Jeff Roberson
jroberson at chesapeake.net
Sat Mar 17 20:16:54 UTC 2007
On Sat, 17 Mar 2007, Max Laier wrote:
> On Saturday 17 March 2007 20:09, Jeff Roberson wrote:
>> Any language lawyers care to comment on this?
>
> I find this strange. According to the spec "(Decrementing is equivalent
> to subtracting 1.)", but "pri = --pri % RQ_NQS;" will behave like you
> expect, while "pri = (pri - 1) % RQ_NQS;" clearly didn't.
I noticed this as well.
When you do --pri, pri is promoted to int for the math and then demoted
back to char wich truncates the value. Subsequently this value is used
in the % operation, which gives the expected results.
When you do pri - 1 the intermediate result is promoted to a signed int
which doesn't yield the result you'd like when you mod with 64.
Jeff
>
>> On Sat, 17 Mar 2007, Jeff Roberson wrote:
>>> jeff 2007-03-17 18:13:33 UTC
>>>
>>> FreeBSD src repository
>>>
>>> Modified files:
>>> sys/kern sched_ule.c
>>> Log:
>>> - Cast the intermediate value in priority computtion back down to
>>> unsigned char. Weirdly, casting the 1 constant to u_char still
>>> produces a signed integer result that is then used in the %
>>> computation. This avoids that mess all together and causes a 0 pri
>>> to turn into 255 % 64 as we expect.
>>>
>>> Reported by: kkenn (about 4 times, thanks)
>>>
>>> Revision Changes Path
>>> 1.190 +1 -1 src/sys/kern/sched_ule.c
>
> --
> /"\ Best regards, | mlaier at freebsd.org
> \ / Max Laier | ICQ #67774661
> X http://pf4freebsd.love2party.net/ | mlaier at EFnet
> / \ ASCII Ribbon Campaign | Against HTML Mail and News
>
More information about the cvs-src
mailing list