From 29f7643a8934e811423b00e53cda4ef66c3c527e Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Tue, 2 Aug 2011 23:14:23 +0200 Subject: [PATCH] compat: add linux/atmoic.h This include is needed by some drivers. Signed-off-by: Hauke Mehrtens --- include/linux/atomic.h | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 include/linux/atomic.h diff --git a/include/linux/atomic.h b/include/linux/atomic.h new file mode 100644 index 000000000000..378b748fb207 --- /dev/null +++ b/include/linux/atomic.h @@ -0,0 +1,46 @@ +#ifndef _COMPAT_LINUX_ATOMIC_H +#define _COMPAT_LINUX_ATOMIC_H 1 + +#include + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,36)) +#include_next +#else + +#include + +/** + * atomic_inc_not_zero_hint - increment if not null + * @v: pointer of type atomic_t + * @hint: probable value of the atomic before the increment + * + * This version of atomic_inc_not_zero() gives a hint of probable + * value of the atomic. This helps processor to not read the memory + * before doing the atomic read/modify/write cycle, lowering + * number of bus transactions on some arches. + * + * Returns: 0 if increment was not done, 1 otherwise. + */ +#ifndef atomic_inc_not_zero_hint +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint) +{ + int val, c = hint; + + /* sanity test, should be removed by compiler if hint is a constant */ + if (!hint) + return atomic_inc_not_zero(v); + + do { + val = atomic_cmpxchg(v, c, c + 1); + if (val == c) + return 1; + c = val; + } while (c); + + return 0; +} +#endif + +#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,36)) */ + +#endif /* _COMPAT_LINUX_ATOMIC_H */ -- 2.30.2