Re: surpring results of test_and_set_bit() andtest_and_clear_bit() functions in Linux-2.6.25 kernel at x86_64 architecture

From: Petr Tesarik
Date: Mon Jun 29 2009 - 09:28:09 EST


qingbo yuan pÃÅe v St 17. 06. 2009 v 18:42 +0800:
> hi,all
> I recently encountered a strange phenomenon about test_and_set_bit()
> and test_and_clear_bit().
> [...]
> So, if the old bit is '0', these functions return 0;
> if the old bit is '1', these functions return -1;
> Both of these functions were right if the comments modified as
> "test_and_set_bit - Set a bit and return its opposite old value".
>
> Can anybody point out what problems exist in my analysis?

None. Just, the intended return type of those functions is actually
bool, I think, so it doesn't matter if they return 1 or -1. Any non-zero
value will do.

OTOH choosing the word "opposite" is probably unfortunate, because most
people would have difficulties understanding what the function really
returns.

And while we're at nitpicking, what makes you think that a single bit
integer must be an unsigned int? If I look at one bit as a signed int,
then it can hold the values 0 and -1. The test_and_*_bit() merely
sign-extend the bit...

Petr Tesarik

--
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/