* - 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)
*
typedef struct spin_lock spinlock_t;
#define DEFINE_SPINLOCK(lock) spinlock_t lock = { }
-#define LASSERT_SPIN_LOCKED(lock) do { (void)sizeof(lock); } while (0)
-#define LINVRNT_SPIN_LOCKED(lock) do { (void)sizeof(lock); } while (0)
-#define LASSERT_SEM_LOCKED(sem) do { (void)sizeof(sem); } while (0)
-#define LASSERT_MUTEX_LOCKED(x) do { (void)sizeof(x); } while (0)
+#define __SPIN_LOCK_UNLOCKED(x) ((spinlock_t) {})
void spin_lock_init(spinlock_t *lock);
void spin_lock(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
*
struct completion {
unsigned int done;
- cfs_waitq_t wait;
+ wait_queue_head_t wait;
};
#endif /* HAVE_LIBPTHREAD */
void down_read(struct rw_semaphore *s);
int down_read_trylock(struct rw_semaphore *s);
void down_write(struct rw_semaphore *s);
+void downgrade_write(struct rw_semaphore *s);
int down_write_trylock(struct rw_semaphore *s);
void up_read(struct rw_semaphore *s);
void up_write(struct rw_semaphore *s);
/*
* 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