Whamcloud - gitweb
LU-4856 misc: Reduce exposure to overflow on page counters.
[fs/lustre-release.git] / libcfs / include / libcfs / user-lock.h
index d0ff4ff..16d7917 100644 (file)
@@ -78,7 +78,7 @@
  * - spin_lock_bh(x)
  * - spin_unlock_bh(x)
  *
- * - spin_is_locked(x)
+ * - assert_spin_locked(x)
  * - spin_lock_irqsave(x, f)
  * - spin_unlock_irqrestore(x, f)
  *
@@ -99,10 +99,11 @@ void spin_lock_bh_init(spinlock_t *lock);
 void spin_lock_bh(spinlock_t *lock);
 void spin_unlock_bh(spinlock_t *lock);
 
-static inline int spin_is_locked(spinlock_t *l) { return 1; }
 static inline void spin_lock_irqsave(spinlock_t *l, unsigned long f) {}
 static inline void spin_unlock_irqrestore(spinlock_t *l, unsigned long f) {}
 
+#define assert_spin_locked(lock)       do { (void)(lock); } while (0)
+
 /*
  * Semaphore
  *
@@ -273,6 +274,28 @@ typedef struct { volatile int counter; } atomic_t;
 #define atomic_cmpxchg(v, ov, nv) \
        ((v)->counter == ov ? ((v)->counter = nv, ov) : (v)->counter)
 
+typedef struct { volatile long counter; } atomic_long_t;
+
+#define ATOMIC_LONG_INIT(i) { (i) }
+
+#define atomic_long_read(a) ((a)->counter)
+#define atomic_long_set(a, b) do {(a)->counter = b; } while (0)
+#define atomic_long_dec_and_test(a) ((--((a)->counter)) == 0)
+#define atomic_long_dec_and_lock(a, b) ((--((a)->counter)) == 0)
+#define atomic_long_inc(a)  (((a)->counter)++)
+#define atomic_long_dec(a)  do { (a)->counter--; } while (0)
+#define atomic_long_add(b, a)  do {(a)->counter += b; } while (0)
+#define atomic_long_add_return(n, a) ((a)->counter += n)
+#define atomic_long_inc_return(a) atomic_long_add_return(1, a)
+#define atomic_long_sub(b, a)  do {(a)->counter -= b; } while (0)
+#define atomic_long_sub_return(n, a) ((a)->counter -= n)
+#define atomic_long_dec_return(a)  atomic_long_sub_return(1, a)
+#define atomic_long_add_unless(v, a, u) \
+       ((v)->counter != u ? (v)->counter += a : 0)
+#define atomic_long_inc_not_zero(v) atomic_long_add_unless((v), 1, 0)
+#define atomic_long_cmpxchg(v, ov, nv) \
+       ((v)->counter == ov ? ((v)->counter = nv, ov) : (v)->counter)
+
 #ifdef HAVE_LIBPTHREAD
 #include <pthread.h>