Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7179e30e authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar
Browse files

locking,arch,cris: Fold atomic_ops



Many of the atomic op implementations are the same except for one
instruction; fold the lot into a few CPP macros and reduce LoC.

This also prepares for easy addition of new ops.

Signed-off-by: default avatarPeter Zijlstra <peterz@infradead.org>
Acked-by: default avatarJesper Nilsson <jesper.nilsson@axis.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mikael Starvik <starvik@axis.com>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: linux-cris-kernel@axis.com
Link: http://lkml.kernel.org/r/20140508135852.104572724@infradead.org


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent d325209b
Loading
Loading
Loading
Loading
+25 −32
Original line number Diff line number Diff line
@@ -22,43 +22,36 @@

/* These should be written in asm but we do it in C for now. */

static inline void atomic_add(int i, volatile atomic_t *v)
{
	unsigned long flags;
	cris_atomic_save(v, flags);
	v->counter += i;
	cris_atomic_restore(v, flags);
#define ATOMIC_OP(op, c_op)						\
static inline void atomic_##op(int i, volatile atomic_t *v)		\
{									\
	unsigned long flags;						\
	cris_atomic_save(v, flags);					\
	v->counter c_op i;						\
	cris_atomic_restore(v, flags);					\
}									\

#define ATOMIC_OP_RETURN(op, c_op)					\
static inline int atomic_##op##_return(int i, volatile atomic_t *v)	\
{									\
	unsigned long flags;						\
	int retval;							\
	cris_atomic_save(v, flags);					\
	retval = (v->counter c_op i);					\
	cris_atomic_restore(v, flags);					\
	return retval;							\
}

static inline void atomic_sub(int i, volatile atomic_t *v)
{
	unsigned long flags;
	cris_atomic_save(v, flags);
	v->counter -= i;
	cris_atomic_restore(v, flags);
}
#define ATOMIC_OPS(op, c_op) ATOMIC_OP(op, c_op) ATOMIC_OP_RETURN(op, c_op)

static inline int atomic_add_return(int i, volatile atomic_t *v)
{
	unsigned long flags;
	int retval;
	cris_atomic_save(v, flags);
	retval = (v->counter += i);
	cris_atomic_restore(v, flags);
	return retval;
}
ATOMIC_OPS(add, +=)
ATOMIC_OPS(sub, -=)

#define atomic_add_negative(a, v)	(atomic_add_return((a), (v)) < 0)
#undef ATOMIC_OPS
#undef ATOMIC_OP_RETURN
#undef ATOMIC_OP

static inline int atomic_sub_return(int i, volatile atomic_t *v)
{
	unsigned long flags;
	int retval;
	cris_atomic_save(v, flags);
	retval = (v->counter -= i);
	cris_atomic_restore(v, flags);
	return retval;
}
#define atomic_add_negative(a, v)	(atomic_add_return((a), (v)) < 0)

static inline int atomic_sub_and_test(int i, volatile atomic_t *v)
{