@@ -170,6 +170,11 @@ static inline int atomic_add_negative(int i, atomic_t *v)
return atomic_add_return(i, v) < 0;
}
+static inline int atomic_add_unless(atomic_t *v, int a, int u)
+{
+ return __atomic_add_unless(v, a, u);
+}
+
#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
#endif /* __ARCH_ARM_ATOMIC__ */
@@ -126,6 +126,11 @@ static inline void atomic_sub(int i, atomic_t *v)
: "ir" (i), "m" (*(volatile int *)&v->counter) );
}
+static inline int atomic_sub_return(int i, atomic_t *v)
+{
+ return arch_fetch_and_add(&v->counter, -i) - i;
+}
+
static inline int atomic_sub_and_test(int i, atomic_t *v)
{
unsigned char c;
@@ -145,6 +150,11 @@ static inline void atomic_inc(atomic_t *v)
: "m" (*(volatile int *)&v->counter) );
}
+static inline int atomic_inc_return(atomic_t *v)
+{
+ return atomic_add_return(1, v);
+}
+
static inline int atomic_inc_and_test(atomic_t *v)
{
unsigned char c;
@@ -164,6 +174,11 @@ static inline void atomic_dec(atomic_t *v)
: "m" (*(volatile int *)&v->counter) );
}
+static inline int atomic_dec_return(atomic_t *v)
+{
+ return atomic_sub_return(1, v);
+}
+
static inline int atomic_dec_and_test(atomic_t *v)
{
unsigned char c;
@@ -186,4 +201,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
return c;
}
+static inline int atomic_add_unless(atomic_t *v, int a, int u)
+{
+ int c, old;
+
+ c = atomic_read(v);
+ while (c != u && (old = atomic_cmpxchg(v, c, c + a)) != c)
+ c = old;
+ return c;
+}
+
+#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
+
#endif /* __ARCH_X86_ATOMIC__ */
@@ -111,6 +111,15 @@ static inline int atomic_add_return(int i, atomic_t *v);
static inline void atomic_sub(int i, atomic_t *v);
/**
+ * atomic_sub_return - sub integer and return
+ * @i: integer value to sub
+ * @v: pointer of type atomic_t
+ *
+ * Atomically subtracts @i from @v and returns @v - @i.
+ */
+static inline int atomic_sub_return(int i, atomic_t *v);
+
+/**
* atomic_sub_and_test - subtract value from variable and test result
* @i: integer value to subtract
* @v: pointer of type atomic_t
@@ -130,6 +139,14 @@ static inline int atomic_sub_and_test(int i, atomic_t *v);
static inline void atomic_inc(atomic_t *v);
/**
+ * atomic_inc_return - increment atomic variable and return
+ * @v: pointer of type atomic_t
+ *
+ * Atomically increments @v by 1 and returns @v + 1.
+ */
+static inline int atomic_inc_return(atomic_t *v);
+
+/**
* atomic_inc_and_test - increment and test
* @v: pointer of type atomic_t
*
@@ -148,6 +165,14 @@ static inline int atomic_inc_and_test(atomic_t *v);
static inline void atomic_dec(atomic_t *v);
/**
+ * atomic_dec_return - decrement atomic variable and return
+ * @v: pointer of type atomic_t
+ *
+ * Atomically decrements @v by 1 and returns @v - 1.
+ */
+static inline int atomic_dec_return(atomic_t *v);
+
+/**
* atomic_dec_and_test - decrement and test
* @v: pointer of type atomic_t
*
@@ -168,4 +193,15 @@ static inline int atomic_dec_and_test(atomic_t *v);
*/
static inline int atomic_add_negative(int i, atomic_t *v);
+/**
+ * atomic_add_unless - add to atomic variable unless it has a specified value
+ * @v: pointer of type atomic_t
+ * @a: integer value to add
+ * @u: integer value @v must -not- be for the add to be performed
+ *
+ * If @v != @u, adds @a to @v and returns @v + @a.
+ * Otherwise returns @u (== @v).
+ */
+static inline int atomic_add_unless(atomic_t *v, int a, int u);
+
#endif /* __XEN_ATOMIC_H__ */