Whamcloud - gitweb
Landing b_hd_newconfig on HEAD
[fs/lustre-release.git] / lnet / include / libcfs / user-lock.h
index e57200f..cea7a6d 100644 (file)
 
 /*
  * liblustre is single-threaded, so most "synchronization" APIs are trivial.
+ *
+ * XXX Liang: There are several branches share lnet with b_hd_newconfig,
+ * if we define lock APIs at here, there will be conflict with liblustre
+ * in other branches.
  */
 
 #ifndef __KERNEL__
+#include <stdio.h>
+#include <stdlib.h>
 
+#if 0
 /*
  * Optional debugging (magic stamping and checking ownership) can be added.
  */
  *
  * No-op implementation.
  */
-struct spin_lock {};
+struct spin_lock {int foo;};
 
 typedef struct spin_lock spinlock_t;
 
+#define SPIN_LOCK_UNLOCKED (spinlock_t) { }
+#define LASSERT_SPIN_LOCKED(lock) do {} while(0)
+
 void spin_lock_init(spinlock_t *lock);
 void spin_lock(spinlock_t *lock);
 void spin_unlock(spinlock_t *lock);
@@ -66,9 +76,10 @@ int spin_trylock(spinlock_t *lock);
 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;}
 
-#define spin_lock_irqsave(l, flags) ({ spin_lock(l); (void)flags; })
-#define spin_unlock_irqrestore(l, flags)  ({ spin_unlock(l); (void)flags; })
+static inline void spin_lock_irqsave(spinlock_t *l, unsigned long f){}
+static inline void spin_unlock_irqrestore(spinlock_t *l, unsigned long f){}
 
 /*
  * Semaphore
@@ -77,7 +88,9 @@ void spin_unlock_bh(spinlock_t *lock);
  * - __down(x)
  * - __up(x)
  */
-struct semaphore {};
+typedef struct semaphore {
+    int foo;
+} mutex_t;
 
 void sema_init(struct semaphore *s, int val);
 void __down(struct semaphore *s);
@@ -104,11 +117,13 @@ void __up(struct semaphore *s);
  * - complete(c)
  * - wait_for_completion(c)
  */
+#if 0
 struct completion {};
 
 void init_completion(struct completion *c);
 void complete(struct completion *c);
 void wait_for_completion(struct completion *c);
+#endif
 
 /*
  * rw_semaphore:
@@ -149,11 +164,32 @@ typedef struct rw_semaphore rwlock_t;
 #define write_lock(l)          down_write(l)
 #define write_unlock(l)                up_write(l)
 
-#define write_lock_irqsave(l, f)       write_lock(l)
-#define write_unlock_irqrestore(l, f)  write_unlock(l)
+static inline void
+write_lock_irqsave(rwlock_t *l, unsigned long f) { write_lock(l); }
+static inline void
+write_unlock_irqrestore(rwlock_t *l, unsigned long f) { write_unlock(l); }
 
-#define read_lock_irqsave(l, f)                read_lock(l)
-#define read_unlock_irqrestore(l, f)   read_unlock(l)
+static inline void 
+read_lock_irqsave(rwlock_t *l, unsigned long f) { read_lock(l); }
+static inline void
+read_unlock_irqrestore(rwlock_t *l, unsigned long f) { read_unlock(l); }
+
+/*
+ * Atomic for user-space
+ * Copied from liblustre
+ */
+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_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_sub(b,a)  do {(a)->counter -= b;} while (0)
+
+#endif
 
 /* !__KERNEL__ */
 #endif