Index: trunk/kernel/libk/remote_rwlock.h
===================================================================
--- trunk/kernel/libk/remote_rwlock.h	(revision 690)
+++ trunk/kernel/libk/remote_rwlock.h	(revision 1)
@@ -1,6 +1,6 @@
 /*
- * remote_rwlock.h - kernel remote read/write lock definition.
+ * remote_rwlock.h - kernel remote_rwlock definition.
  *
- * Authors   Alain Greiner   (2016,2017,2018,2020)
+ * Authors   Alain Greiner   (2016)
  * 
  * Copyright (c) UPMC Sorbonne Universites
@@ -25,82 +25,72 @@
 #define _REMOTE_RWLOCK_H_
 
-#include <kernel_config.h>
-#include <hal_kernel_types.h>
-#include <remote_busylock.h>
+#include <almos_config.h>
+#include <hal_types.h>
 #include <xlist.h>
 
-/*******************************************************************************************
- * This structure defines a kernel, global, read/write lock, supporting several simultaneous
- * read accesses, but only one write access to a globally shared object, that can be
- * accessed by threads running in any cluster.
- * Both readers and writers take the associated busylock before accessing or updating
- * the rwlock state, and releases the busylock after rwlock state update.
- * - when a reader try to access the object, it increments the readers "count" when the 
- *   lock is not "taken" by a writer. It registers in the "rd_root" waiting queue, blocks,
- *   and deschedules when the lock is taken.
- * - when a writer try to take the rwlock, it check the "taken" field. If the lock is already
- *   taken, or if the number of readers is non zero, it registers in the "wr_root" waiting
- *   queue, blocks, and deschedules. It set "taken" otherwise.
- * - when a reader completes its access, it decrement the readers "count", unblock 
- *   the first waiting writer if there is no other readers, and unblock all waiting
- *   readers if there no write request.
- * - when a  writer completes its access, it reset the "taken" field, releases the first
- *   waiting writer if queue non empty, or releases all waiting readers if no writer.
- ******************************************************************************************/
-
-
-/*******************************************************************************************
- * This structure defines a remote rwlock.
- ******************************************************************************************/
+/***************************************************************************************
+ * This structure defines a remote rwdlock,that supports several simultaneous read 
+ * accesses, but only one write access. It implements a ticket based allocation policy.
+ * It can be used to synchronize threads running in different clusters, because
+ * all access functions use remote pointers.
+ * - A reader take the lock to atomically increments the registered readers count.
+ *   Then it release the lock and access the protected structure. It atomically 
+ *   decrements the readers count without taking the lock when access is completed.
+ * - A writer take the lock and keep it, but must wait completion of all current read 
+ *   accesses before starting its own access.
+ * When the lock is taken by another thread, the new-comers use a busy waiting policy.
+ *
+ * TODO This could be replaced by a descheduling policy and a threads waiting queue
+ * implemented in the lock itself: each thread releasing the lock (i.e. incrementing
+ * the current field) activates the first waiting thread... 
+ **************************************************************************************/
 
 typedef struct remote_rwlock_s
 {
-    remote_busylock_t   lock;        /*! busylock protecting the rwlock state             */
-	volatile uint32_t   taken;       /*! lock taken by an exclusive writer if non zero    */
-    volatile uint32_t   count;       /*! current number of simultaneous readers threads   */
-    xlist_entry_t       rd_xroot;    /*! root of list of waiting readers                  */
-    xlist_entry_t       wr_xroot;    /*! root of list of waiting writers                  */
-}
+    uint32_t     ticket;                /*! first free ticket index                   */
+    uint32_t     current;               /*! ticket index of current owner             */
+    uint32_t     count;                 /*! current number of reader threads          */
+    xptr_t       owner;                 /*! extended pointer on writer thread         */
+} 
 remote_rwlock_t;
-
 
 /***************************************************************************************
  * This function initializes a remote rwlock.
- * The <type> argument defines the lock usage and is only used for debug.
- * This type is actually stored in the associated busylock descriptor.
  ***************************************************************************************
  * @ lock_xp    : extended pointer on the remote rwlock
- * @ type       : lock usage for debug.
  **************************************************************************************/
-void remote_rwlock_init( xptr_t   lock_xp,
-                         uint32_t type );
+void remote_rwlock_init( xptr_t lock_xp );
 
 /***************************************************************************************
  * This blocking function get access to a remote rwlock for a reader.
+ * It increments the calling thread locks count when the lock has been taken.
  ***************************************************************************************
  * @ lock_xp    : extended pointer on the remote rwlock
  **************************************************************************************/
-void remote_rwlock_rd_acquire( xptr_t lock_xp );
+void remote_rwlock_rd_lock( xptr_t lock_xp );
 
 /***************************************************************************************
  * This function releases a remote rwlock for a reader.
+ * It decrements the calling thread locks count when the lock has been released.
  ***************************************************************************************
  * @ lock_xp    : extended pointer on the remote rwlock
  **************************************************************************************/
-void remote_rwlock_rd_release( xptr_t lock_xp );
+void remote_rwlock_rd_unlock( xptr_t lock_xp );
 
 /***************************************************************************************
  * This blocking function get access to a remote rwlock for a writer.
+ * It increments the calling thread locks count when the lock has been taken.
  ***************************************************************************************
  * @ lock_xp    : extended pointer on the remote rwlock
  **************************************************************************************/
-void remote_rwlock_wr_acquire( xptr_t lock_xp );
+void remote_rwlock_wr_lock( xptr_t lock_xp );
 
 /***************************************************************************************
  * This function releases a remote rwlock for a writer.
+ * It decrements the calling thread locks count when the lock has been released.
  ***************************************************************************************
  * @ lock_xp    : extended pointer on the remote rwlock
  **************************************************************************************/
-void remote_rwlock_wr_release( xptr_t lock_xp );
+void remote_rwlock_wr_unlock( xptr_t lock_xp );
 
 #endif
