[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130314162413.GA21344@redhat.com>
Date: Thu, 14 Mar 2013 17:24:13 +0100
From: Oleg Nesterov <oleg@...hat.com>
To: Ming Lei <tom.leiming@...il.com>, Shaohua Li <shli@...nel.org>,
Al Viro <viro@...iv.linux.org.uk>,
Andrew Morton <akpm@...ux-foundation.org>
Cc: linux-kernel@...r.kernel.org
Subject: Re: +
atomic-improve-atomic_inc_unless_negative-atomic_dec_unless_positive
.patch added to -mm tree
> From: Ming Lei <tom.leiming@...il.com>
> Subject: atomic: improve atomic_inc_unless_negative/atomic_dec_unless_positive
>
> Generally, both atomic_inc_unless_negative() and
> atomic_dec_unless_positive() need at least two atomic_cmpxchg() to
> complete the atomic operation. In fact, the 1st atomic_cmpxchg() is just
> used to read current value of the atomic variable at most times.
Agreed, this looks ugly...
But can't we make a simpler patch and keep the code simple/readable ?
Oleg.
--- x/include/linux/atomic.h
+++ x/include/linux/atomic.h
@@ -64,7 +64,7 @@ static inline int atomic_inc_not_zero_hi
static inline int atomic_inc_unless_negative(atomic_t *p)
{
int v, v1;
- for (v = 0; v >= 0; v = v1) {
+ for (v = atomic_read(p); v >= 0; v = v1) {
v1 = atomic_cmpxchg(p, v, v + 1);
if (likely(v1 == v))
return 1;
@@ -77,7 +77,7 @@ static inline int atomic_inc_unless_nega
static inline int atomic_dec_unless_positive(atomic_t *p)
{
int v, v1;
- for (v = 0; v <= 0; v = v1) {
+ for (v = atomic_read(p); v <= 0; v = v1) {
v1 = atomic_cmpxchg(p, v, v - 1);
if (likely(v1 == v))
return 1;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists