aboutsummaryrefslogtreecommitdiff
path: root/linuxthreads/spinlock.h
diff options
context:
space:
mode:
Diffstat (limited to 'linuxthreads/spinlock.h')
-rw-r--r--linuxthreads/spinlock.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/linuxthreads/spinlock.h b/linuxthreads/spinlock.h
index 29f030406c..aae18a27b4 100644
--- a/linuxthreads/spinlock.h
+++ b/linuxthreads/spinlock.h
@@ -72,3 +72,31 @@ static inline int __pthread_trylock (struct _pthread_fastlock * lock)
}
#define LOCK_INITIALIZER {0, 0}
+
+/* Operations on pthread_atomic, which is defined in internals.h */
+
+static inline long atomic_increment(struct pthread_atomic *pa)
+{
+ long oldval;
+
+ do {
+ oldval = pa->p_count;
+ } while (!compare_and_swap(&pa->p_count, oldval, oldval + 1, &pa->p_spinlock));
+
+ return oldval;
+}
+
+
+static inline long atomic_decrement(struct pthread_atomic *pa)
+{
+ long oldval;
+
+ do {
+ oldval = pa->p_count;
+ } while (!compare_and_swap(&pa->p_count, oldval, oldval - 1, &pa->p_spinlock));
+
+ return oldval;
+}
+
+#define ATOMIC_INITIALIZER { 0, 0 }
+