public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* test_and_set_bit implementation
@ 2006-12-12 15:01 Zoltan Menyhart
  2006-12-12 15:47 ` Matthew Wilcox
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Zoltan Menyhart @ 2006-12-12 15:01 UTC (permalink / raw)
  To: linux-ia64

We have got a test_and_set_bit implementation as follows:

static __inline__ int
test_and_set_bit (int nr, volatile void *addr)
{
        __u32 bit, old, new;
        volatile __u32 *m;

        m = (volatile __u32 *) addr + (nr >> 5);
        bit = 1 << (nr & 31);
        do {
                old = *m;
                new = old | bit;
        } while (cmpxchg_acq(m, old, new) != old);
        return (old & bit) != 0;
}

Let's assume the bit test & set is already set, why is then the
cmpxchg_acq() executed? Cannot we just return, e.g. like this?

        do {
                old = *m;
		if (old & bit)
			return 1;
                new = old | bit;
        } while (cmpxchg_acq(m, old, new) != old);

Thanks,

Zoltán Menyhárt

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-12-14  9:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-12 15:01 test_and_set_bit implementation Zoltan Menyhart
2006-12-12 15:47 ` Matthew Wilcox
2006-12-12 17:20 ` Christoph Lameter
2006-12-12 17:22 ` Christoph Lameter
2006-12-12 18:07 ` Matthew Wilcox
2006-12-13 10:02 ` Zoltan Menyhart
2006-12-13 10:20 ` Zoltan Menyhart
2006-12-13 12:29 ` Matthew Wilcox
2006-12-13 18:28 ` Christoph Lameter
2006-12-14  9:24 ` Zoltan Menyhart
2006-12-14  9:37 ` Zoltan Menyhart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox