Skip to content

Commit 5acba71

Browse files
fweisbecingomolnar
authored andcommitted
locking/atomic: Introduce atomic_fetch_or()
This is deemed to replace the type generic fetch_or() which brings a lot of issues such as macro induced block variable aliasing and sloppy types. Not to mention fetch_or() doesn't refer to any namespace, adding even more confusion. So lets provide an atomic_t version. Current and next users of fetch_or() are thus encouraged to use atomic_t. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/1458830281-4255-2-git-send-email-fweisbec@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 1993b17 commit 5acba71

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎include/linux/atomic.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,27 @@ static inline int atomic_dec_if_positive(atomic_t *v)
558558
}
559559
#endif
560560

561+
/**
562+
* atomic_fetch_or - perform *p |= mask and return old value of *p
563+
* @p: pointer to atomic_t
564+
* @mask: mask to OR on the atomic_t
565+
*/
566+
#ifndef atomic_fetch_or
567+
static inline int atomic_fetch_or(atomic_t *p, int mask)
568+
{
569+
int old, val = atomic_read(p);
570+
571+
for (;;) {
572+
old = atomic_cmpxchg(p, val, val | mask);
573+
if (old == val)
574+
break;
575+
val = old;
576+
}
577+
578+
return old;
579+
}
580+
#endif
581+
561582
/**
562583
* fetch_or - perform *ptr |= mask and return old value of *ptr
563584
* @ptr: pointer to value

0 commit comments

Comments
 (0)