From ebb3f4d480cf21f48581db63cc58dfcc78efa0a2 Mon Sep 17 00:00:00 2001
From: zam <zam>
Date: Tue, 9 Dec 2008 19:13:20 +0000
Subject: [PATCH] Branch HEAD b=17461 i=robert.read i=tappro

list_empty_careful() definition, missed in
a fix of ptlrpc_handle_rs locking.
---
 libcfs/include/libcfs/list.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/libcfs/include/libcfs/list.h b/libcfs/include/libcfs/list.h
index 548bdf5cd1..eaec15691f 100644
--- a/libcfs/include/libcfs/list.h
+++ b/libcfs/include/libcfs/list.h
@@ -156,6 +156,25 @@ static inline int list_empty(struct list_head *head)
 	return head->next == head;
 }
 
+/**
+ * list_empty_careful - tests whether a list is empty and not being modified
+ * @head: the list to test
+ *
+ * Description:
+ * tests whether a list is empty _and_ checks that no other CPU might be
+ * in the process of modifying either member (next or prev)
+ *
+ * NOTE: using list_empty_careful() without synchronization
+ * can only be safe if the only activity that can happen
+ * to the list entry is list_del_init(). Eg. it cannot be used
+ * if another CPU could re-list_add() it.
+ */
+static inline int list_empty_careful(const struct list_head *head)
+{
+        struct list_head *next = head->next;
+        return (next == head) && (next == head->prev);
+}
+
 static inline void __list_splice(struct list_head *list,
 				 struct list_head *head)
 {
-- 
GitLab