lkml.org 
[lkml]   [2019]   [Jan]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 3/3] bitops.h: set_mask_bits() to return old value
On Thu, Jan 10, 2019 at 04:26:27PM -0800, Vineet Gupta wrote:

> @@ -246,7 +246,7 @@ static __always_inline void __assign_bit(long nr, volatile unsigned long *addr,
> new__ = (old__ & ~mask__) | bits__; \
> } while (cmpxchg(ptr, old__, new__) != old__); \

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 705f7c442691..2060d26a35f5 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -241,10 +241,10 @@ static __always_inline void __assign_bit(long nr, volatile unsigned long *addr,
const typeof(*(ptr)) mask__ = (mask), bits__ = (bits); \
typeof(*(ptr)) old__, new__; \
\
+ old__ = READ_ONCE(*(ptr)); \
do { \
- old__ = READ_ONCE(*(ptr)); \
new__ = (old__ & ~mask__) | bits__; \
- } while (cmpxchg(ptr, old__, new__) != old__); \
+ } while (!try_cmpxchg(ptr, &old__, new__)); \
\
new__; \
})

While there you probably want something like the above... although,
looking at it now, we seem to have 'forgotten' to add try_cmpxchg to the
generic code :/

\
 
 \ /
  Last update: 2019-01-11 10:24    [W:0.080 / U:2.844 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site