Index: trunk/kernel/libk/list.h
===================================================================
--- trunk/kernel/libk/list.h	(revision 690)
+++ trunk/kernel/libk/list.h	(revision 1)
@@ -1,7 +1,7 @@
 /*
- * list.h - Local double circular linked list, using local pointers.
+ * list.h - Double circular chained lists, inspired from linux
  *
  * Authors Ghassan Almaless  (2008,2009,2010,2011,2012)
- *         Alain Greiner     (2016,2017,2018,2019,2020)
+ *         Alain Greiner     (2016)
  *
  * Copyright (c) UPMC Sorbonne Universites
@@ -23,11 +23,9 @@
  */
 
-#ifndef _LIST_H_
-#define _LIST_H_
-
-#include <kernel_config.h>
-#include <hal_kernel_types.h>
-#include <hal_remote.h>
-#include <printk.h>
+#ifndef _ALMOS_LIST_H_
+#define _ALMOS_LIST_H_
+
+#include <almos_config.h>
+#include <hal_types.h>
 
 #ifndef NULL
@@ -36,19 +34,25 @@
 
 
-////////////////////////////////////////////////////////////////////////////
-//          Double circular linked list functions & macros
-// 
-// It defines a generic local list, as all elements are in the same cluster.
-//
-// There is two sets of access functions, because these local lists can be
-// accessed by local threads, using local pointers, but they can also be 
-// accessed by remote threads running in any cluster, with specific access
-// functions using extended pointers.
+/***************************************************************************
+ * This macro return an uint32_t that is the offset (number of bytes)
+ * of a field in a structure.
+ * @ type   : structure type
+ * @ member : name of the field
+ **************************************************************************/
+
+#ifndef OFFSETOF
+#define OFFSETOF( type , member ) ((unsigned int) & ((type *)0)->member)
+#endif
+
+////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////
+//          Double circular linked list functions & macros 
+////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////
 
 /***************************************************************************
  * This structure defines a Double Circular Linked List entry.
- * Note : The list root is an extra list-entry_t, that is NOT part
- *            of the set of linked elements.
+ * Note : The list root is an extra list-entry_t, that is NOT part of the 
+ *        set of linked elements.
  **************************************************************************/
 
@@ -59,16 +63,4 @@
 }
 list_entry_t;
-
-/***************************************************************************
- * This macro return an intptr_t that is the offset (number of bytes)
- * of a field in a structure.
- ***************************************************************************
- * @ type   : structure type
- * @ member : name of the field
- **************************************************************************/
-
-#ifndef OFFSETOF
-#define OFFSETOF( type , member ) ((intptr_t) & ((type *)0)->member)
-#endif
 
 /***************************************************************************
@@ -84,14 +76,8 @@
 	(container_type *)( (char*)__member_ptr - OFFSETOF( container_type , member_name ));})
 
-
-////////////////////////////////////////////////////////////////////////////
-// These functions and macros mus be called by a thread running
-// in the local cluster to access the local list.
-////////////////////////////////////////////////////////////////////////////
-
-/***************************************************************************
- * This macro returns a pointer on the first element of a list. 
- ***************************************************************************
- * @ root     : pointer on the list root
+/***************************************************************************
+ * This macro returns the first element of a rooted double linked list. 
+ ***************************************************************************
+ * @ root_ptr : pointer on the list root
  * @ type     : type of the linked elements
  * @ member   : name of the list_entry_t field
@@ -102,7 +88,7 @@
 
 /***************************************************************************
- * This macro returns a pointer on the last element of a list. 
- ***************************************************************************
- * @ root     : pointer on the list root
+ * This macro returns the last element of a rooted double linked list. 
+ ***************************************************************************
+ * @ root_ptr : pointer on the list root
  * @ type     : type of the linked elements
  * @ member   : name of the list_entry_t field
@@ -113,7 +99,40 @@
 
 /***************************************************************************
+ * This function returns the pointer on the next list_entry_t.
+ ***************************************************************************
+ * @ root    : pointer on the list root.
+ * @ current : pointer on the current list_entry_t.
+ * @ returns pointer on next entry if success.
+ *   returns NULL if list empty or next is the root. 
+ **************************************************************************/
+static inline list_entry_t * list_next( list_entry_t * root,
+                                        list_entry_t * current )
+{
+	if((root == root->next) || (current->next == root)) return NULL;
+  
+	return current->next;
+}
+
+/***************************************************************************
+ * This function returns the pointer on the previous list_entry_t.
+ ***************************************************************************
+ * @ root    : pointer on the list root.
+ * @ current : pointer on the current list_entry.
+ * @ returns pointer on previous entry if success.
+ *   returns NULL if list empty or previous is the root. 
+ **************************************************************************/
+static inline list_entry_t * list_pred( list_entry_t * root,
+                                        list_entry_t * current )
+{
+	if((root == root->next) || (current->pred == root))
+		return NULL;
+  
+	return current->pred;
+}
+
+/***************************************************************************
  * This macro traverse a rooted double linked list in forward order.
- * WARNING : Don't use this macro when you want to remove one or several
- * item(s) from the traversed list.	
+ * WARNING : Don't use 2 LIST_FOREACH in the same function, because the	
+ * variable __ptr will be defined twice, wich result in a compilation error.
  ***************************************************************************
  * @ root      : pointer on the root list_entry
@@ -162,6 +181,5 @@
 
 /***************************************************************************
- * This function must be called by a thread running in local cluster.
- * It inserts a new entry in first place of a double linked list.
+ * This function inserts a new entry in first place of a double linked list.
  ***************************************************************************
  * @ root    : pointer on the list root
@@ -171,16 +189,19 @@
                                    list_entry_t * entry )
 {
-    list_entry_t * first = root->next;  
-
-	entry->next = first;
-	entry->pred = root;
-  
-	root->next  = entry;
-	first->pred = entry;
-}
-
-/***************************************************************************
- * This function must be called by a thread running in local cluster.
- * It inserts a new entry in last place of a double linked list.
+    list_entry_t * pred_entry;
+    list_entry_t * next_entry;
+  
+	pred_entry = root;
+	next_entry = root->next;
+	
+	entry->next = next_entry;
+	entry->pred = pred_entry;
+  
+	pred_entry->next = entry;
+	next_entry->pred = entry;
+}
+
+/***************************************************************************
+ * This function inserts a new entry in last place of a double linked list.
  ***************************************************************************
  * @ root    : pointer on the list root
@@ -190,16 +211,9 @@
                                   list_entry_t * entry )
 {
-    list_entry_t * last = root->pred;
-
-	entry->next = root;
-	entry->pred = last;
-  
-	root->pred = entry;
-	last->next = entry;
-}
-
-/***************************************************************************
- * This function must be called by a thread running in local cluster.
- * It returns true if the list is empty.
+    list_add_first( root->pred , entry );
+}
+
+/***************************************************************************
+ * This function returns true if the list is empty.
  ***************************************************************************
  * @ root    : pointer on the list root
@@ -210,8 +224,6 @@
 }
 
-
-/***************************************************************************
- * This function must be called by a thread running in local cluster.
- * It removes an entry from the list.
+/***************************************************************************
+ * This function remove an entry from a rooted double linked list.
  ***************************************************************************
  * @ entry : pointer on the entry to be removed.
@@ -219,12 +231,12 @@
 static inline void list_unlink( list_entry_t * entry )
 {
-	list_entry_t * pred = entry->pred;
-    list_entry_t * next = entry->next;
-
-	pred->next = next;
-	next->pred = pred;
-
-    entry->next = NULL;
-    entry->pred = NULL;
+	list_entry_t * pred_entry;
+    list_entry_t * next_entry;
+
+	pred_entry = entry->pred;
+	next_entry = entry->next;
+
+	pred_entry->next = entry->next;
+	next_entry->pred = entry->pred;
 }
 
@@ -251,169 +263,4 @@
 }
 
-/***************************************************************************
- * This debug function displays all entries of a list.
- * @ root    : local pointer on the root list_entry_t.
- * @ string  : list identifier displayed in header.
- * @ max     : max number of éléments to display.
- **************************************************************************/
-static inline void list_display( list_entry_t * root,
-                                 char         * string,
-                                 uint32_t       max )
-{
-    list_entry_t * iter;
-    list_entry_t * next;
-    list_entry_t * pred;
-    uint32_t       index;
-
-    next = root->next;
-    pred = root->pred;
-
-    printk("\n***** root (%x) / next (%x) / pred (%x) / %s *****\n",
-    root, next, pred, string );
-
-    if( list_is_empty( root ) == false )
-    {
-        for( iter = next , index = 0 ;
-             (iter != root) && (index < max) ;
-             iter = next , index++ )
-        {
-            next = iter->next;
-			pred = iter->pred;
-
-            printk(" - %d : iter (%x) / next (%x) / pred (%x)\n",
-            index, iter, next, pred );
-        }
-    }
-}  // end list_display()
-
-
-
-////////////////////////////////////////////////////////////////////////////
-// These functions and macros can be used by any thread running
-// in any cluster to access a remote local list.
-////////////////////////////////////////////////////////////////////////////
-
-/***************************************************************************
- * This macro can be used by a thread running in any cluster to access
- * a remote local list. It returns a local pointer on the first element
- * of the remote list in the remote cluster.
- ***************************************************************************
- * @ cxy     : remote list cluster identifier
- * @ root    : local pointer on the list root
- * @ type    : type of the linked element
- * @ member  : name of the list_entry_t field
- **************************************************************************/
-
-#define LIST_REMOTE_FIRST( cxy , root , type , member )		       \
-	LIST_ELEMENT( hal_remote_lpt( XPTR( (cxy) , &(root)->next ) ), \
-                  type , member )
-
-/***************************************************************************
- * This macro can be used by a thread running in any cluster to access
- * a remote local list. It traverse the list in forward order.
- * WARNING : Don't use this macro when you want to remove one or several
- * item(s) from the traversed list.	
- ***************************************************************************
- * @ cxy     : remote cluster identifier.
- * @ root    : pointer on the root list_entry.
- * @ iter    : pointer on the current list_entry.
- **************************************************************************/
-
-#define LIST_REMOTE_FOREACH( cxy , root , iter )                 \
-for( (iter) = hal_remote_lpt( XPTR( (cxy) , &(root)->next ) ) ;  \
-     (iter) != (root) ;				                             \
-     (iter) = hal_remote_lpt( XPTR( (cxy) , &(iter)->next ) ) ) 
-	
-/***************************************************************************
- * This macro can be used by a thread running in any cluster to access
- * a remote local list. It traverse the list in backward order.
- * WARNING : same as the forward traversal
- ***************************************************************************
- * @ cxy       : remote cluster identifier.
- * @ root      : pointer on the root list_entry.
- * @ iter      : pointer on the current list_entry.
- **************************************************************************/
-
-#define LIST_REMOTE_FOREACH_BACKWARD( cxy , root , iter )       \
-for( (iter) = hal_remote_lpt( XPTR( (cxy) , &(root)->pred ) ) ; \
-     (iter) != (root) ;                                         \
-     (iter) = hal_remote_lpt( XPTR( (cxy) , &(iter)->pred ) ) )
-
-/***************************************************************************
- * This function can be called by a thread running in any cluster to access
- * a remote local list. It returns true if the list is empty.
- ***************************************************************************
- * @ cxy     : remote list cluster identifier
- * @ root    : local pointer on the remote list root
- **************************************************************************/
-static inline bool_t list_remote_is_empty( cxy_t          cxy,
-                                           list_entry_t * root )
-{
-    list_entry_t * next = hal_remote_lpt( XPTR( cxy , &root->next ) );
-    return( root == next );
-}
-
-/***************************************************************************
- * This function can be called by a thread running in any cluster to access
- * a remote local list. It inserts a new entry in first place of the list.
- ***************************************************************************
- * @ cxy     : remote list cluster identifier
- * @ root    : local pointer on the remote list root
- * @ entry   : local pointer on the remote entry to be inserted
- **************************************************************************/
-static inline void list_remote_add_first( cxy_t          cxy,
-                                          list_entry_t * root, 
-                                          list_entry_t * entry )
-{
-    list_entry_t * first = hal_remote_lpt( XPTR( cxy , &root->next ) );
-	
-	hal_remote_spt( XPTR( cxy , &entry->next ) , first );
-	hal_remote_spt( XPTR( cxy , &entry->pred ) , root );
-  
-	hal_remote_spt( XPTR( cxy , &root->next )  , entry );
-	hal_remote_spt( XPTR( cxy , &first->pred ) , entry );
-}
-
-/***************************************************************************
- * This function can be called by a thread running in any cluster to access
- * a remote local list. It inserts a new entry in last place of the list.
- ***************************************************************************
- * @ cxy     : remote list cluster identifier
- * @ root    : local pointer on the remote list root
- * @ entry   : local pointer on the remote entry to be inserted
- **************************************************************************/
-static inline void list_remote_add_last( cxy_t          cxy,
-                                         list_entry_t * root, 
-                                         list_entry_t * entry )
-{
-    list_entry_t * last = hal_remote_lpt( XPTR( cxy , &root->pred ) );
-	
-	hal_remote_spt( XPTR( cxy , &entry->next ) , root );
-	hal_remote_spt( XPTR( cxy , &entry->pred ) , last );
-  
-	hal_remote_spt( XPTR( cxy , &root->pred ) , entry );
-	hal_remote_spt( XPTR( cxy , &last->next ) , entry );
-}
-
-/***************************************************************************
- * This function can be called by a thread running in any cluster to access
- * a remote local list. It removes an entry from the list.
- ***************************************************************************
- * @ cxy     : remote list cluster identifier
- * @ entry   : local pointer on the remote entry to be removed.
- **************************************************************************/
-static inline void list_remote_unlink( cxy_t          cxy,
-                                       list_entry_t * entry )
-{
-	list_entry_t * pred = hal_remote_lpt( XPTR( cxy , &entry->pred ) );
-    list_entry_t * next = hal_remote_lpt( XPTR( cxy , &entry->next ) );
-
-	hal_remote_spt( XPTR( cxy , &pred->next ) , next );
-	hal_remote_spt( XPTR( cxy , &next->pred ) , pred );
-
-	hal_remote_spt( XPTR( cxy , &entry->next ) , NULL );
-	hal_remote_spt( XPTR( cxy , &entry->pred ) , NULL );
-}
-
-
-#endif	/* _LIST_H_ */
+
+#endif	/* _ALMOS_LIST_H_ */
