Re: Thread flags modified without set_thread_flag() (non atomically)
From: Kyle Moffett
Date: Mon Mar 05 2007 - 11:32:01 EST
On Mar 01, 2007, at 17:41:38, Andrew Morton wrote:
Well, it's unusual for code to want to test multiple bitflags in
the same operation. Perhaps thread_info.flags is unusual in that
regard.
But one can still do
if (foo->flags & (1<<bar)|(1<<zot))
Which can get to be a pain if it happens in a lot of places. But
if it only happens in a few places, this seems a reasonable price
to pay, given the safety gains.
Plus I'm _forever_ having to go into the header file to remember
whether REQ_RW is the bitmask or the bit offset.
Hey Andrew, I think you just fell victim to an order-of-operations
bug; '&' has a higher priority than '|' does, so:
if ( (foo->flags & (1<<bar)) | (1<<zot))
Or:
if ( dynamic_value | always_true_constant )
And as such this if statement is always true. You'd need an extra
pair of parentheses to make it correct.
Cheers,
Kyle Moffett
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/