Index: trunk/kernel/libk/remote_spinlock.c
===================================================================
--- trunk/kernel/libk/remote_spinlock.c	(revision 1)
+++ trunk/kernel/libk/remote_spinlock.c	(revision 11)
@@ -31,9 +31,9 @@
 #include <remote_spinlock.h>
 
-////////////////////////////////////////
-void remote_spinlock_init( xptr_t lock )
+///////////////////////////////////////////
+void remote_spinlock_init( xptr_t lock_xp )
 { 
-    remote_spinlock_t * ptr = (remote_spinlock_t *)GET_PTR( lock );
-    cxy_t               cxy = GET_CXY( lock );
+    remote_spinlock_t * ptr = (remote_spinlock_t *)GET_PTR( lock_xp );
+    cxy_t               cxy = GET_CXY( lock_xp );
 
     hal_remote_sw ( XPTR( cxy , &ptr->taken ) , 0 );
@@ -42,6 +42,6 @@
 }
 
-///////////////////////////////////////////////
-uint32_t remote_spinlock_trylock( xptr_t lock )
+/////////////////////////////////////////////////
+error_t remote_spinlock_trylock( xptr_t lock_xp )
 { 
 	uint32_t            mode;
@@ -49,6 +49,6 @@
 
     // get cluster and local pointer on remote_spinlock
-    remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock );
-    cxy_t               lock_cxy = GET_CXY( lock );
+    remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp );
+    cxy_t               lock_cxy = GET_CXY( lock_xp );
 
     // get cluster and local pointer on local thread
@@ -84,6 +84,7 @@
 }
 
-////////////////////////////////////////
-void remote_spinlock_lock( xptr_t lock )
+///////////////////////////////////////////////////
+void remote_spinlock_lock_busy( xptr_t     lock_xp,
+                                uint32_t * irq_state )
 {
     bool_t              isAtomic = false;
@@ -92,6 +93,72 @@
 
     // get cluster and local pointer on remote_spinlock
-    remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock );
-    cxy_t               lock_cxy = GET_CXY( lock );
+    remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp );
+    cxy_t               lock_cxy = GET_CXY( lock_xp );
+
+    // get cluster and local pointer on local thread
+    cxy_t               thread_cxy = local_cxy;
+    thread_t          * thread_ptr = CURRENT_THREAD;
+
+    // disable interrupts
+	hal_disable_irq( &mode );
+  
+    // loop until success 
+	while( isAtomic == false )
+	{
+		taken = hal_remote_lw( XPTR( lock_cxy , &lock_ptr->taken ) );
+
+        // try to take the lock if not already taken
+		if( taken == 0 )
+		{
+		    isAtomic = hal_remote_atomic_cas( XPTR( lock_cxy , &lock_ptr->taken ) , 0 , 1 );
+        }
+	}
+
+    // register lock in thread
+	thread_ptr->remote_locks++;
+
+    hal_remote_swd( XPTR( lock_cxy , &lock_ptr->owner ) ,
+                    (uint64_t)XPTR( thread_cxy , thread_ptr) );
+
+    xlist_add_first( XPTR( thread_cxy , &thread_ptr->xlocks_root ) ,
+                     XPTR( lock_cxy , &lock_ptr->list ) );
+
+    // irq_state must be restored when lock is released 
+    *irq_state = mode;
+
+}  // end remote_spinlock_lock_busy()
+
+////////////////////////////////////////////////////
+void remote_spinlock_unlock_busy( xptr_t    lock_xp,
+                                  uint32_t  irq_state )
+{
+    // get cluster and local pointer on remote_spinlock
+    remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp );
+    cxy_t               lock_cxy = GET_CXY( lock_xp );
+
+    // get pointer on local thread
+    thread_t          * thread_ptr = CURRENT_THREAD;
+
+	hal_remote_swd( XPTR( lock_cxy , &lock_ptr->owner ) , XPTR_NULL );
+
+	hal_remote_sw ( XPTR( lock_cxy , &lock_ptr->taken ) , 0 );
+
+	thread_ptr->remote_locks--;
+
+    xlist_unlink( XPTR( lock_cxy , &lock_ptr->list ) );
+
+    hal_restore_irq( irq_state );
+}
+
+///////////////////////////////////////////
+void remote_spinlock_lock( xptr_t lock_xp )
+{
+    bool_t              isAtomic = false;
+	uint32_t            mode;
+    volatile uint32_t   taken;
+
+    // get cluster and local pointer on remote_spinlock
+    remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp );
+    cxy_t               lock_cxy = GET_CXY( lock_xp );
 
     // get cluster and local pointer on local thread
@@ -133,10 +200,10 @@
 }
 
-//////////////////////////////////////////
-void remote_spinlock_unlock( xptr_t lock )
-{
-    // get cluster and local pointer on remote_spinlock
-    remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock );
-    cxy_t               lock_cxy = GET_CXY( lock );
+/////////////////////////////////////////////
+void remote_spinlock_unlock( xptr_t lock_xp )
+{
+    // get cluster and local pointer on remote_spinlock
+    remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp );
+    cxy_t               lock_cxy = GET_CXY( lock_xp );
 
     // get pointer on local thread
