Whamcloud - gitweb
split osc_cl.c into osc_object.c osc_lock.c osc_io.c osc_page.c osc_dev.c
[fs/lustre-release.git] / libcfs / include / libcfs / user-lock.h
index 6f4e145..2561381 100644 (file)
@@ -146,7 +146,8 @@ struct completion {
         unsigned int done;
         cfs_waitq_t wait;
 };
-
+typedef int (cfs_wait_handler) (int timeout);
+void set_completion_wait_handler(cfs_wait_handler *handler);
 void init_completion(struct completion *c);
 void complete(struct completion *c);
 void wait_for_completion(struct completion *c);
@@ -279,6 +280,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 +300,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)