Whamcloud - gitweb
b=20592
[fs/lustre-release.git] / libcfs / include / libcfs / user-lock.h
index 6f4e145..958519e 100644 (file)
@@ -85,8 +85,9 @@ 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)
-#define LASSERT_SEM_LOCKED(sem) do {} while(0)
+#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)
 
 void spin_lock_init(spinlock_t *lock);
 void spin_lock(spinlock_t *lock);
@@ -146,7 +147,9 @@ struct completion {
         unsigned int done;
         cfs_waitq_t wait;
 };
-
+typedef int (*cfs_wait_handler_t) (int timeout);
+void init_completion_module(cfs_wait_handler_t handler);
+int  call_wait_handler(int timeout);
 void init_completion(struct completion *c);
 void complete(struct completion *c);
 void wait_for_completion(struct completion *c);
@@ -181,6 +184,7 @@ void down_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);
+void fini_rwsem(struct rw_semaphore *s);
 
 /*
  * read-write lock : Need to be investigated more!!
@@ -233,6 +237,8 @@ typedef struct { volatile int counter; } atomic_t;
 #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 atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
 
 
 #ifdef HAVE_LIBPTHREAD
@@ -279,6 +285,8 @@ struct mutex {
         struct semaphore m_sem;
 };
 
+#define DEFINE_MUTEX(m) struct mutex m
+
 static inline void mutex_init(struct mutex *mutex)
 {
         init_mutex(&mutex->m_sem);
@@ -297,13 +305,27 @@ static inline void mutex_unlock(struct mutex *mutex)
 /**
  * Try-lock this mutex.
  *
- * \retval 1 try-lock succeeded.
  *
- * \retval 0 try-lock failed.
+ * \retval 0 try-lock succeeded (lock acquired).
+ * \retval errno indicates lock contention.
+ */
+static inline int mutex_down_trylock(struct mutex *mutex)
+{
+        return 0;
+}
+
+/**
+ * Try-lock this mutex.
+ *
+ * Note, return values are negation of what is expected from down_trylock() or
+ * pthread_mutex_trylock().
+ *
+ * \retval 1 try-lock succeeded (lock acquired).
+ * \retval 0 indicates lock contention.
  */
 static inline int mutex_trylock(struct mutex *mutex)
 {
-        return 1;
+        return !mutex_down_trylock(mutex);
 }
 
 static inline void mutex_destroy(struct mutex *lock)
@@ -331,13 +353,21 @@ static inline int mutex_is_locked(struct mutex *lock)
  **************************************************************************/
 
 struct lock_class_key {
-        ;
+        int foo;
 };
 
 static inline void lockdep_set_class(void *lock, struct lock_class_key *key)
 {
 }
 
+static inline void lockdep_off(void)
+{
+}
+
+static inline void lockdep_on(void)
+{
+}
+
 /* This has to be a macro, so that can be undefined in kernels that do not
  * support lockdep. */
 #define mutex_lock_nested(mutex, subclass) mutex_lock(mutex)
@@ -345,6 +375,7 @@ static inline void lockdep_set_class(void *lock, struct lock_class_key *key)
 #define down_read_nested(lock, subclass) down_read(lock)
 #define down_write_nested(lock, subclass) down_write(lock)
 
+
 /* !__KERNEL__ */
 #endif