Whamcloud - gitweb
lockdep: add lockdep_{on,off}() functions.
[fs/lustre-release.git] / libcfs / include / libcfs / user-lock.h
index b134096..c81c208 100644 (file)
@@ -146,8 +146,10 @@ 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);
 void init_completion(struct completion *c);
+void init_completion_module(cfs_wait_handler_t handler);
 void complete(struct completion *c);
 void wait_for_completion(struct completion *c);
 int wait_for_completion_interruptible(struct completion *c);
@@ -181,6 +183,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!!
@@ -279,6 +282,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,18 +302,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_trylock(struct mutex *mutex)
+static inline int mutex_down_trylock(struct mutex *mutex)
 {
-        return 1;
+        return 0;
 }
 
-static inline void mutex_lock_nested(struct mutex *mutex, unsigned int subclass)
+/**
+ * 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 mutex_lock(mutex);
+        return !mutex_down_trylock(mutex);
 }
 
 static inline void mutex_destroy(struct mutex *lock)
@@ -336,13 +350,29 @@ 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)
+#define spin_lock_nested(lock, subclass) spin_lock(lock)
+#define down_read_nested(lock, subclass) down_read(lock)
+#define down_write_nested(lock, subclass) down_write(lock)
+
+
 /* !__KERNEL__ */
 #endif