From: Petr Tesarik <ptesarik@suse.cz>
To: qingbo yuan <yuanbor.maillist@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: surpring results of test_and_set_bit() and test_and_clear_bit() functions in Linux-2.6.25 kernel at x86_64 architecture
Date: Mon, 29 Jun 2009 15:27:56 +0200 [thread overview]
Message-ID: <1246282076.7698.10.camel@nathan.suse.cz> (raw)
In-Reply-To: <2ab84cd80906170342ta334955yc69a2648fa979979@mail.gmail.com>
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
prev parent reply other threads:[~2009-06-29 13:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <2ab84cd80906170340w3ad8b938t64b6d0926b18daa4@mail.gmail.com>
2009-06-17 10:42 ` qingbo yuan
2009-06-29 13:27 ` Petr Tesarik [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1246282076.7698.10.camel@nathan.suse.cz \
--to=ptesarik@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=yuanbor.maillist@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®