From 534b67238eebe59e9142c95a4b25e96154565854 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Thu, 11 Nov 2010 14:05:08 -0800 Subject: [PATCH] --- yaml --- r: 221714 b: refs/heads/master c: 3f9d35b9514da6757ca98831372518f9eeb71b33 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/include/linux/atomic.h | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 trunk/include/linux/atomic.h diff --git a/[refs] b/[refs] index 3db5c1bacc6e..d303ab2b0897 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 8705a1baf78287eceeb00bc29401d0ae6a03f213 +refs/heads/master: 3f9d35b9514da6757ca98831372518f9eeb71b33 diff --git a/trunk/include/linux/atomic.h b/trunk/include/linux/atomic.h new file mode 100644 index 000000000000..96c038e43d66 --- /dev/null +++ b/trunk/include/linux/atomic.h @@ -0,0 +1,37 @@ +#ifndef _LINUX_ATOMIC_H +#define _LINUX_ATOMIC_H +#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_ATOMIC_H */