lkml.org 
[lkml]   [2022]   [Feb]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] atomic: Put the fetching of the old value into the loop when doing atomic CAS
Date
Put the acquisition of the expected value inside the loop to prevent an infinite loop when it does not match.

Signed-off-by: Junru Shen <hhusjrsjr@gmail.com>
---
arch/x86/include/asm/atomic64_64.h | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
index 7886d0578..3df04c44c 100644
--- a/arch/x86/include/asm/atomic64_64.h
+++ b/arch/x86/include/asm/atomic64_64.h
@@ -207,9 +207,10 @@ static inline void arch_atomic64_and(s64 i, atomic64_t *v)

static inline s64 arch_atomic64_fetch_and(s64 i, atomic64_t *v)
{
- s64 val = arch_atomic64_read(v);
+ s64 val;

do {
+ val = arch_atomic64_read(v);
} while (!arch_atomic64_try_cmpxchg(v, &val, val & i));
return val;
}
@@ -225,9 +226,10 @@ static inline void arch_atomic64_or(s64 i, atomic64_t *v)

static inline s64 arch_atomic64_fetch_or(s64 i, atomic64_t *v)
{
- s64 val = arch_atomic64_read(v);
+ s64 val;

do {
+ val = arch_atomic64_read(v);
} while (!arch_atomic64_try_cmpxchg(v, &val, val | i));
return val;
}
@@ -243,9 +245,10 @@ static inline void arch_atomic64_xor(s64 i, atomic64_t *v)

static inline s64 arch_atomic64_fetch_xor(s64 i, atomic64_t *v)
{
- s64 val = arch_atomic64_read(v);
+ s64 val;

do {
+ val = arch_atomic64_read(v);
} while (!arch_atomic64_try_cmpxchg(v, &val, val ^ i));
return val;
}
--
2.30.2
\
 
 \ /
  Last update: 2022-02-24 09:25    [W:0.034 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site