Re: test_and_set_bit implementation

From: Zoltan Menyhart <>
Date: 2006-12-14 20:24:23
Matthew Wilcox wrote:
> On Wed, Dec 13, 2006 at 11:02:48AM +0100, Zoltan Menyhart wrote:
>>I like this code with the following slight modifications:
>>- let's keep "m" as pointer to volatile
> Why?  What benefit is there to doing an ld4.acq instead of a plain ld4?

It is not about the ld4.acq, but the volatile storage class (= don't
assume it wont be changed by someone else, do reload it each time).

Not using the volatile key word allows the compiler to optimize
out the actual load in loops like:

	while (test_and_set_bit(bitnum, addr))

>>- let's keep on using "__u32" types
> Why be so ugly?

- It has been like that for a while, I got used to it :-)
- grep-ing for "__u32" gives less false positives that grep-ing for "u32"
>>- return the old bit
> I don't understand what you mean here.

In your code:
    while (!(old & bit)) {
            return 1;
    return 0;

You return the inverse of the old bit, while the orig. code says:

" * test_and_set_bit - Set a bit and return its old value"


Zoltán Menyhárt

To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to
More majordomo info at
Received on Thu Dec 14 20:25:13 2006

This archive was generated by hypermail 2.1.8 : 2006-12-14 20:26:04 EST