Skip to content

Commit

Permalink
atomic: atomic_sub uses atomic_add
Browse files Browse the repository at this point in the history
* `atomic_sub` uses `atomic_add` with a negative number
* `atomic_dec` takes an implicit `1` parameter

Signed-off-by: Daniele Ahmed <ahmeddan amazon c;0m >
  • Loading branch information
82marbag authored and wipawel committed Feb 14, 2021
1 parent 7d57dde commit 8660925
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions include/arch/x86/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,28 +151,16 @@ static inline void atomic64_dec(atomic64_t *v) {
}

static inline int32_t atomic_sub_return(atomic_t *v, int32_t n) {
int32_t val = n;
asm volatile("lock xsubl %[n], %[addr];"
: [ n ] "+r"(val), [ addr ] "+m"(v->counter)
:
: "memory");
return val;
return atomic_add_return(v, -n);
}

static inline int64_t atomic64_sub_return(atomic64_t *v, int64_t n) {
int64_t val = n;
asm volatile("lock xsubq %[n], %[addr];"
: [ n ] "+r"(val), [ addr ] "+m"(v->counter)
:
: "memory");
return val;
return atomic64_add_return(v, -n);
}

static inline int32_t atomic_dec_return(atomic_t *v, int32_t n) {
return atomic_sub_return(v, 1);
}
static inline int32_t atomic_dec_return(atomic_t *v) { return atomic_sub_return(v, 1); }

static inline int64_t atomic64_dec_return(atomic64_t *v, int64_t n) {
static inline int64_t atomic64_dec_return(atomic64_t *v) {
return atomic64_sub_return(v, 1);
}

Expand Down

0 comments on commit 8660925

Please sign in to comment.