Whamcloud - gitweb
rhel4 2.6.9-67 kernel has (nonfunctional)
[fs/lustre-release.git] / libcfs / include / libcfs / linux / linux-lock.h
index 0ada733..474132b 100644 (file)
@@ -50,6 +50,7 @@
 #endif
 
 #include <linux/smp_lock.h>
+#include <linux/mutex.h>
 
 /*
  * IMPORTANT !!!!!!!!
  * - spin_unlock_irqrestore(x, f)
  */
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
-static inline void spin_lock_nested(spinlock_t *lock, unsigned subclass)
-{
-        spin_lock(lock);
-}
-#endif
-
 /*
  * rw_semaphore (use Linux kernel's primitives)
  *
@@ -121,21 +115,7 @@ static inline void spin_lock_nested(spinlock_t *lock, unsigned subclass)
  * - wait_for_completion(c)
  */
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
-
-/**************************************************************************
- *
- * Lockdep "implementation". Also see liblustre.h
- *
- **************************************************************************/
-
-struct lock_class_key {
-        ;
-};
-
-static inline void lockdep_set_class(void *lock, struct lock_class_key *key)
-{
-}
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
 
 /**************************************************************************
  *
@@ -145,14 +125,7 @@ static inline void lockdep_set_class(void *lock, struct lock_class_key *key)
  *
  **************************************************************************/
 
-#ifndef mutex
-# define mutex semaphore
-#endif
-
-static inline void mutex_lock_nested(struct mutex *mutex, unsigned int subclass)
-{
-        return down(mutex);
-}
+struct mutex;
 
 static inline void mutex_destroy(struct mutex *lock)
 {
@@ -168,8 +141,44 @@ static inline void mutex_destroy(struct mutex *lock)
  */
 static inline int mutex_is_locked(struct mutex *lock)
 {
-        return !!down_trylock(lock);
+        return 1;
 }
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16) */
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
+
+/**************************************************************************
+ *
+ * Lockdep "implementation". Also see liblustre.h
+ *
+ **************************************************************************/
+
+struct lock_class_key {
+        ;
+};
+
+#ifndef lockdep_set_class
+# define lockdep_set_class(lock, key) do {;} while (0)
 #endif
 
+/* This has to be a macro, so that `subclass' can be undefined in kernels that
+ * do not support lockdep. */
+#ifndef mutex_lock_nested
+# define mutex_lock_nested(mutex, subclass) mutex_lock(mutex)
 #endif
+
+#ifndef spin_lock_nested
+# define spin_lock_nested(lock, subclass) spin_lock(lock)
+#endif
+
+#ifndef down_read_nested
+# define down_read_nested(lock, subclass) down_read(lock)
+#endif
+
+#ifndef down_write_nested
+# define down_write_nested(lock, subclass) down_write(lock)
+#endif
+
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) */
+
+#endif /* __LIBCFS_LINUX_CFS_LOCK_H__ */