Index: trunk/kernel/kern/alarm.c
===================================================================
--- trunk/kernel/kern/alarm.c	(revision 669)
+++ trunk/kernel/kern/alarm.c	(revision 683)
@@ -31,62 +31,59 @@
 
 ////////////////////////////////////////////////////////////////////////////////////////////
-// This static function registers the alarm identified ny the <new_alarm> argument 
+// This static function registers the alarm identified by the <alarm> & <cxy> arguments 
 // in the list of alarms rooted in the core identified by the <core> argument.
 // When the existing list of alarms is not empty, it scan the list to insert the new
 // alarm in the right place to respect the absolute dates ordering. 
 ////////////////////////////////////////////////////////////////////////////////////////////
-// @ new_alarm  : local pointer on the new alarm.
-// @ core       : local pointer on the target core.
+// @ cxy    : cluster containing both the new alarm and the core.
+// @ alarm  : local pointer on the alarm.
+// @ core   : local pointer on the core.
 ////////////////////////////////////////////////////////////////////////////////////////////
-static void alarm_register( alarm_t * new_alarm,
+static void alarm_register( cxy_t     cxy,
+                            alarm_t * alarm,
                             core_t  * core )
 {
-    list_entry_t * current;          // pointer on current list_entry in existing list
-    list_entry_t * previous;         // pointer on previous list_entry in existing list
-    alarm_t      * current_alarm;    // pointer on current alarm in existing list
-    cycle_t        current_date;     // date of current alarm in existing list
-
-    bool_t         done = false;
-
-    // get pointers on root of alarms and lock
+    // get alarm date
+    cycle_t new_date = hal_remote_l64( XPTR( cxy , &alarm->date ) );
+
+    // build local pointer on root of alarms list 
     list_entry_t * root = &core->alarms_root;
-    busylock_t   * lock = &core->alarms_lock;
-
-    // get pointer on new_alarm list_entry 
-    list_entry_t * new_entry = &new_alarm->list;
-
-    // get new_alarm date
-    cycle_t        new_date = new_alarm->date;
-
-    // take the lock
-    busylock_acquire( lock );
+
+    // build local pointer on new alarm list_entry
+    list_entry_t * new  = &alarm->list;
 
     // insert new alarm to respect dates order
-    if( list_is_empty( root ) )                     // list empty
+    if( list_remote_is_empty( cxy , &core->alarms_root ) )  // list empty
     {
-        list_add_first( root , new_entry ); 
+        list_remote_add_first( cxy , root , new ); 
     }
-    else                                            // list non empty
+    else                                                   // list non empty
     {
-        for( current = root->next ;
-             (current != root) && (done == false) ;
-             current = current->next )
+        list_entry_t * iter;        // local pointer on current list_entry in existing list
+        alarm_t      * iter_alarm;  // local pointer on current alarm in existing list
+        cycle_t        iter_date;   // date of current alarm in existing list
+        bool_t         done = false;
+
+        for( iter = hal_remote_lpt( XPTR( cxy , &root->next ) ) ;
+             (iter != root) && (done == false) ;
+             iter = hal_remote_lpt( XPTR( cxy , &iter->next ) ) )
         {
-            // get pointer on previous entry in existing list
-            previous = current->pred;
-
-            // get pointer on current alarm 
-            current_alarm = LIST_ELEMENT( current , alarm_t , list );
+            // get local pointer on pred and next for iter
+            list_entry_t * prev = hal_remote_lpt( XPTR( cxy , &iter->pred ) );
+
+            // get local pointer on current alarm 
+            iter_alarm = LIST_ELEMENT( iter , alarm_t , list );
 
             // get date for current alarm 
-            current_date  = current_alarm->date;
-
-            if( current_date > new_date )  // insert new alarm just before current
+            iter_date = hal_remote_l64( XPTR( cxy , &iter_alarm->date ) );
+
+            // insert new alarm just before current when required
+            if( iter_date > new_date )  
             {
-                new_entry->next = current;
-                new_entry->pred = previous;
-
-                current->pred  = new_entry;
-                previous->next = new_entry;
+                hal_remote_spt( XPTR( cxy , &new->next ) , iter );
+                hal_remote_spt( XPTR( cxy , &new->pred ) , prev );
+
+                hal_remote_spt( XPTR( cxy , &iter->pred ) , new );
+                hal_remote_spt( XPTR( cxy , &prev->next ) , new );
                 
                 done = true;
@@ -96,75 +93,114 @@
         if( done == false ) // new_date is larger than all registered dates
         {
-            list_add_last( root , new_entry );
+            list_remote_add_last( cxy, root , new );
         }
     }
-
+}  // end alarm_register()
+            
+
+///////////////////////////////////
+void alarm_init( alarm_t *  alarm )
+{
+    alarm->linked   = false;
+    list_entry_init( &alarm->list );
+}
+
+///////////////////////////////////////
+void alarm_start( xptr_t     thread_xp,
+                  cycle_t    date,
+                  void     * func_ptr,
+                  xptr_t     args_xp )
+{
+    // get cluster and local pointer on target thread
+    thread_t * tgt_ptr = GET_PTR( thread_xp );
+    cxy_t      tgt_cxy = GET_CXY( thread_xp );
+
+// check alarm state
+assert( __FUNCTION__ , (hal_remote_l32( XPTR(tgt_cxy,&tgt_ptr->alarm.linked)) == false ),
+"alarm already started");
+
+    // get local pointer on core running target thread
+    core_t * core = hal_remote_lpt( XPTR( tgt_cxy , &tgt_ptr->core ) );
+
+    // build extended pointer on lock protecting alarms list
+    xptr_t lock_xp = XPTR( tgt_cxy , &core->alarms_lock );
+  
+    // initialize alarm descriptor
+    hal_remote_s64( XPTR( tgt_cxy , &tgt_ptr->alarm.date     ) , date );
+    hal_remote_spt( XPTR( tgt_cxy , &tgt_ptr->alarm.func_ptr ) , func_ptr );
+    hal_remote_s64( XPTR( tgt_cxy , &tgt_ptr->alarm.args_xp  ) , args_xp );
+    hal_remote_s32( XPTR( tgt_cxy , &tgt_ptr->alarm.linked   ) , true );
+
+    // take the lock
+    remote_busylock_acquire( lock_xp );
+
+    // register alarm in core list
+    alarm_register( tgt_cxy , &tgt_ptr->alarm , core );
+
+    //release the lock
+    remote_busylock_release( lock_xp );
+
+}  // end alarm_start()
+
+
+/////////////////////////////////////
+void alarm_stop( xptr_t   thread_xp )
+{
+    // get cluster and local pointer on target thread
+    thread_t * tgt_ptr = GET_PTR( thread_xp );
+    cxy_t      tgt_cxy = GET_CXY( thread_xp );
+
+    // get local pointer on core running target thread
+    core_t * core = hal_remote_lpt( XPTR( tgt_cxy , &tgt_ptr->core ) );
+
+    // build extended pointer on lock protecting alarms list
+    xptr_t lock_xp = XPTR( tgt_cxy , &core->alarms_lock );
+  
+    // take the lock
+    remote_busylock_acquire( lock_xp );
+
+    // unlink the alarm from the list rooted in core
+    list_remote_unlink( tgt_cxy , &tgt_ptr->alarm.list );
+
+    // update alarm state
+    hal_remote_s32( XPTR( tgt_cxy , &tgt_ptr->alarm.linked ) , false );
+
+    //release the lock
+    remote_busylock_release( lock_xp );
+
+}  // end alarm_stop()
+
+
+//////////////////////////////////////
+void alarm_update( xptr_t   thread_xp,
+                   cycle_t  new_date )
+{
+    // get cluster and local pointer on target thread
+    thread_t * tgt_ptr = GET_PTR( thread_xp );
+    cxy_t      tgt_cxy = GET_CXY( thread_xp );
+
+    // get local pointer on core running target thread
+    core_t * core = hal_remote_lpt( XPTR( tgt_cxy , &tgt_ptr->core ) );
+
+    // build extended pointer on lock protecting alarms list
+    xptr_t lock_xp = XPTR( tgt_cxy , &core->alarms_lock );
+  
+    // take the lock
+    remote_busylock_acquire( lock_xp );
+
+    // unlink the alarm from the core list
+    list_remote_unlink( tgt_cxy , &tgt_ptr->alarm.list );
+
+    // update the alarm date and state
+    hal_remote_s64( XPTR( tgt_cxy , &tgt_ptr->alarm.date   ) , new_date );
+    hal_remote_s32( XPTR( tgt_cxy , &tgt_ptr->alarm.linked ) , true );
+
+    // register alarm in core list
+    alarm_register( tgt_cxy , &tgt_ptr->alarm , core );
+    
     // release the lock
-    busylock_release( lock );
-
-}  // end alarm_register()
-
-//////////////////////////////////////
-void alarm_start( cycle_t    date,
-                  void     * func_ptr,
-                  xptr_t     args_xp,
-                  thread_t * thread )
-{
-    // get pointer on alarm
-    alarm_t * alarm = &thread->alarm;
-
-    // initialize alarm descriptor
-    alarm->date     = date;
-    alarm->func_ptr = func_ptr;
-    alarm->args_xp = args_xp;
-    
-    // register alarm in core list
-    alarm_register( alarm , thread->core );
-
-}  // end alarm_start()
-
-/////////////////////////////////////
-void alarm_update( thread_t * thread,
-                   cycle_t    new_date )
-{
-    // get pointer on alarm
-    alarm_t * alarm = &thread->alarm;
-
-    // get pointer on core 
-    core_t   * core = thread->core;
-
-    // get pointer on lock protecting the alarms list
-    busylock_t   * lock = &core->alarms_lock;
-
-    // unlink the alarm from the core list
-    busylock_acquire( lock );
-    list_unlink( &alarm->list );
-    busylock_release( lock );
-
-    // update the alarm date
-    alarm->date = new_date;
-
-    // register alarm in core list
-    alarm_register( alarm , core );
-    
+    remote_busylock_release( lock_xp );
+
 }  // end alarm_update()
 
-////////////////////////////////////
-void alarm_stop( thread_t * thread )
-{
-    // get pointer on alarm
-    alarm_t * alarm = &thread->alarm;
-
-    // get pointer on core 
-    core_t * core = thread->core;
-
-    // get pointer on lock protecting the alarms list
-    busylock_t * lock = &core->alarms_lock;
-
-    // unlink the alarm from the list rooted in core
-    busylock_acquire( lock );
-    list_unlink( &alarm->list );
-    busylock_release( lock );
-
-}  // end alarm_stop()
-
+
