Whamcloud - gitweb
LU-5577 libcfs: fix warnings in libcfs/curproc.h
[fs/lustre-release.git] / libcfs / include / libcfs / user-lock.h
index 0cac240..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
  *
@@ -251,26 +252,48 @@ static inline void read_unlock_irqrestore(rwlock_t *l, unsigned long f)
 /*
  * Atomic for single-threaded user-space
  */
-typedef struct { volatile int counter; } cfs_atomic_t;
-
-#define CFS_ATOMIC_INIT(i) { (i) }
-
-#define cfs_atomic_read(a) ((a)->counter)
-#define cfs_atomic_set(a,b) do {(a)->counter = b; } while (0)
-#define cfs_atomic_dec_and_test(a) ((--((a)->counter)) == 0)
-#define cfs_atomic_dec_and_lock(a,b) ((--((a)->counter)) == 0)
-#define cfs_atomic_inc(a)  (((a)->counter)++)
-#define cfs_atomic_dec(a)  do { (a)->counter--; } while (0)
-#define cfs_atomic_add(b,a)  do {(a)->counter += b;} while (0)
-#define cfs_atomic_add_return(n,a) ((a)->counter += n)
-#define cfs_atomic_inc_return(a) cfs_atomic_add_return(1,a)
-#define cfs_atomic_sub(b,a)  do {(a)->counter -= b;} while (0)
-#define cfs_atomic_sub_return(n,a) ((a)->counter -= n)
-#define cfs_atomic_dec_return(a)  cfs_atomic_sub_return(1,a)
-#define cfs_atomic_add_unless(v, a, u) \
+typedef struct { volatile int counter; } atomic_t;
+
+#define ATOMIC_INIT(i) { (i) }
+
+#define atomic_read(a) ((a)->counter)
+#define atomic_set(a,b) do {(a)->counter = b; } while (0)
+#define atomic_dec_and_test(a) ((--((a)->counter)) == 0)
+#define atomic_dec_and_lock(a,b) ((--((a)->counter)) == 0)
+#define atomic_inc(a)  (((a)->counter)++)
+#define atomic_dec(a)  do { (a)->counter--; } while (0)
+#define atomic_add(b,a)  do {(a)->counter += b;} while (0)
+#define atomic_add_return(n,a) ((a)->counter += n)
+#define atomic_inc_return(a) atomic_add_return(1,a)
+#define atomic_sub(b,a)  do {(a)->counter -= b;} while (0)
+#define atomic_sub_return(n,a) ((a)->counter -= n)
+#define atomic_dec_return(a)  atomic_sub_return(1,a)
+#define atomic_add_unless(v, a, u) \
         ((v)->counter != u ? (v)->counter += a : 0)
-#define cfs_atomic_inc_not_zero(v) cfs_atomic_add_unless((v), 1, 0)
-#define cfs_atomic_cmpxchg(v, ov, nv) \
+#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
+#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