Skip to content

Commit e1ab7f3

Browse files
fbqmpe
authored andcommitted
atomics: Allow architectures to define their own __atomic_op_* helpers
Some architectures may have their special barriers for acquire, release and fence semantics, so that general memory barriers(smp_mb__*_atomic()) in the default __atomic_op_*() may be too strong, so allow architectures to define their own helpers which can overwrite the default helpers. Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 78c1cff commit e1ab7f3

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎include/linux/atomic.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,29 @@
3434
* The idea here is to build acquire/release variants by adding explicit
3535
* barriers on top of the relaxed variant. In the case where the relaxed
3636
* variant is already fully ordered, no additional barriers are needed.
37+
*
38+
* Besides, if an arch has a special barrier for acquire/release, it could
39+
* implement its own __atomic_op_* and use the same framework for building
40+
* variants
3741
*/
42+
#ifndef __atomic_op_acquire
3843
#define __atomic_op_acquire(op, args...) \
3944
({ \
4045
typeof(op##_relaxed(args)) __ret = op##_relaxed(args); \
4146
smp_mb__after_atomic(); \
4247
__ret; \
4348
})
49+
#endif
4450

51+
#ifndef __atomic_op_release
4552
#define __atomic_op_release(op, args...) \
4653
({ \
4754
smp_mb__before_atomic(); \
4855
op##_relaxed(args); \
4956
})
57+
#endif
5058

59+
#ifndef __atomic_op_fence
5160
#define __atomic_op_fence(op, args...) \
5261
({ \
5362
typeof(op##_relaxed(args)) __ret; \
@@ -56,6 +65,7 @@
5665
smp_mb__after_atomic(); \
5766
__ret; \
5867
})
68+
#endif
5969

6070
/* atomic_add_return_relaxed */
6171
#ifndef atomic_add_return_relaxed

0 commit comments

Comments
 (0)