Index: trunk/kernel/kern/cluster.c
===================================================================
--- trunk/kernel/kern/cluster.c	(revision 19)
+++ trunk/kernel/kern/cluster.c	(revision 23)
@@ -4,5 +4,5 @@
  * Author  Ghassan Almaless (2008,2009,2010,2011,2012)
  *         Mohamed Lamine Karaoui (2015)
- *         Alain Greiner (2016)
+ *         Alain Greiner (2016,2017)
  *
  * Copyright (c) UPMC Sorbonne Universites
@@ -49,5 +49,5 @@
 ///////////////////////////////////////////////////////////////////////////////////////////
 
-process_t process_zero;     // allocated in kernel_init.c file
+extern process_t process_zero;     // allocated in kernel_init.c file
 
 
@@ -121,6 +121,6 @@
 
     // initialise local_list in process manager
-	spinlock_init( &cluster->pmgr.local_lock );
-    list_root_init( &cluster->pmgr.local_root );
+	remote_spinlock_init( XPTR( local_cxy , &cluster->pmgr.local_lock ) );
+    xlist_root_init( XPTR( local_cxy , &cluster->pmgr.local_root ) );
     cluster->pmgr.local_nr = 0;
 
@@ -162,5 +162,5 @@
 {
     cluster_t * cluster = LOCAL_CLUSTER;
-	hal_atomic_inc( &cluster->cores_in_kernel );
+	hal_atomic_add( &cluster->cores_in_kernel , 1 );
 }
 
@@ -169,5 +169,5 @@
 {
     cluster_t * cluster = LOCAL_CLUSTER;
-	hal_atomic_dec( &cluster->cores_in_kernel );
+	hal_atomic_add( &cluster->cores_in_kernel , -1 );
 }
 
@@ -199,5 +199,5 @@
 xptr_t cluster_get_reference_process_from_pid( pid_t pid )
 {
-    xptr_t xp;   // extended pointer on process descriptor
+    xptr_t ref_xp;   // extended pointer on reference process descriptor
 
     cluster_t * cluster = LOCAL_CLUSTER;
@@ -208,20 +208,16 @@
 
     // Check valid PID
-    if( lpid >= CONFIG_MAX_PROCESS_PER_CLUSTER )
-    {
-        printk("\n[PANIC] in %s : illegal PID\n", __FUNCTION__ );
-        hal_core_sleep();
-    }
+    if( lpid >= CONFIG_MAX_PROCESS_PER_CLUSTER )  return XPTR_NULL;
 
     if( local_cxy == owner_cxy )   // local cluster is owner cluster
     {
-        xp = cluster->pmgr.pref_tbl[lpid];
+        ref_xp = cluster->pmgr.pref_tbl[lpid];
     }
     else                              // use a remote_lwd to access owner cluster
     {
-        xp = (xptr_t)hal_remote_lwd( XPTR( owner_cxy , &cluster->pmgr.pref_tbl[lpid] ) );
-    }
-
-    return xp;
+        ref_xp = (xptr_t)hal_remote_lwd( XPTR( owner_cxy , &cluster->pmgr.pref_tbl[lpid] ) );
+    }
+
+    return ref_xp;
 }
 
@@ -303,19 +299,26 @@
 process_t * cluster_get_local_process_from_pid( pid_t pid )
 {
-    process_t    * ret     = NULL;
-    list_entry_t * root    = &LOCAL_CLUSTER->pmgr.local_root;
-    list_entry_t * iter;
-    process_t    * process;
-
-    LIST_FOREACH( root , iter )
-    {
-        process = LIST_ELEMENT( iter , process_t , local_list );
-        if( process->pid == pid )
+    xptr_t         process_xp;
+    process_t    * process_ptr;
+    xptr_t         root_xp;
+    xptr_t         iter_xp;
+    bool_t         found;
+
+    found   = false;
+    root_xp = XPTR( local_cxy , &LOCAL_CLUSTER->pmgr.local_root );
+
+    XLIST_FOREACH( root_xp , iter_xp )
+    {
+        process_xp  = XLIST_ELEMENT( iter_xp , process_t , local_list );
+        process_ptr = (process_t *)GET_PTR( process_xp );
+        if( process_ptr->pid == pid )
         {
-            ret = process;
+            found = true;
             break;
         }
     }
-    return ret;
+
+    if (found ) return process_ptr;
+    else        return NULL;
 
 }  // end cluster_get_local_process_from_pid()
@@ -327,11 +330,12 @@
 
     // get lock protecting the process manager local list
-    spinlock_lock( &pm->local_lock );
-
-    list_add_first( &pm->local_root , &process->local_list );
+    remote_spinlock_lock( XPTR( local_cxy , &pm->local_lock ) );
+
+    xlist_add_first( XPTR( local_cxy , &pm->local_root ),
+                     XPTR( local_cxy , &process->local_list ) );
     pm->local_nr++;
 
     // release lock protecting the process manager local list
-    spinlock_unlock( &pm->local_lock );
+    remote_spinlock_unlock( XPTR( local_cxy , &pm->local_lock ) );
 }
 
@@ -342,11 +346,11 @@
 
     // get lock protecting the process manager local list
-    spinlock_lock( &pm->local_lock );
-
-    list_unlink( &process->local_list );
+    remote_spinlock_lock( XPTR( local_cxy , &pm->local_lock ) );
+
+    xlist_unlink( XPTR( local_cxy , &process->local_list ) );
     pm->local_nr--;
 
     // release lock protecting the process manager local list
-    spinlock_unlock( &pm->local_lock );
+    remote_spinlock_unlock( XPTR( local_cxy , &pm->local_lock ) );
 }
 
