Index: trunk/kernel/libk/remote_rwlock.c
===================================================================
--- trunk/kernel/libk/remote_rwlock.c	(revision 600)
+++ trunk/kernel/libk/remote_rwlock.c	(revision 603)
@@ -52,4 +52,13 @@
 
     remote_busylock_init( XPTR( lock_cxy , &lock_ptr->lock ) , type ); 
+
+#if DEBUG_RWLOCK
+thread_t * this = CURRENT_THREAD;
+if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
+printk("\n[%s] thread[%x,%x] initialise lock %s [%x,%x]\n",
+__FUNCTION__, this->process->pid, this->trdid,
+lock_type_str[type], local_cxy, lock_ptr );
+#endif
+
 }
 
@@ -85,7 +94,8 @@
 #if DEBUG_RWLOCK
 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
-printk("\n[%s] thread[%x,%x] READ BLOCK on rwlock %s [%x,%x]\n",
+printk("\n[%s] thread[%x,%x] READ BLOCK on rwlock %s [%x,%x] / taken %d / count %d\n",
 __FUNCTION__, this->process->pid, this->trdid, 
-lock_type_str[lock_type], lock_cxy, lock_ptr );
+lock_type_str[lock_type], lock_cxy, lock_ptr,
+hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) );
 #endif
         // get pointer on calling thread
@@ -108,13 +118,16 @@
     }
 
-#if DEBUG_RWLOCK
-if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
-printk("\n[%s] thread[%x,%x] READ ACQUIRE rwlock %s [%x,%x]\n",
-__FUNCTION__, this->process->pid, this->trdid,
-lock_type_str[lock_type], lock_cxy, lock_ptr );
-#endif
-
     // increment number of readers
     hal_remote_atomic_add( count_xp , 1 );
+
+    hal_fence();
+
+#if DEBUG_RWLOCK
+if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
+printk("\n[%s] thread[%x,%x] READ ACQUIRE rwlock %s [%x,%x] / taken = %d / count = %d\n",
+__FUNCTION__, this->process->pid, this->trdid,
+lock_type_str[lock_type], lock_cxy, lock_ptr,
+hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) );
+#endif
 
     // release busylock
@@ -154,8 +167,10 @@
 #if DEBUG_RWLOCK
 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
-printk("\n[%s] thread[%x,%x] WRITE BLOCK on rwlock %s [%x,%x]\n",
+printk("\n[%s] thread[%x,%x] WRITE BLOCK on rwlock %s [%x,%x] / taken %d / count %d\n",
 __FUNCTION__, this->process->pid, this->trdid, 
-lock_type_str[lock_type], lock_cxy, lock_ptr );
-#endif
+lock_type_str[lock_type], lock_cxy, lock_ptr, 
+hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) );
+#endif
+
         // get local pointer on calling thread
         thread_t * this = CURRENT_THREAD;
@@ -177,13 +192,14 @@
     }
 
-#if DEBUG_RWLOCK
-if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
-printk("\n[%s] thread[%x,%x] WRITE ACQUIRE rwlock %s [%x,%x]\n",
+    // take rwlock for write
+    hal_remote_s32( taken_xp , 1 );
+
+#if DEBUG_RWLOCK
+if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
+printk("\n[%s] thread[%x,%x] WRITE ACQUIRE rwlock %s [%x,%x] / taken %d / count %d\n",
 __FUNCTION__, this->process->pid, this->trdid, 
-lock_type_str[lock_type], lock_cxy, lock_ptr );
-#endif
-
-    // take rwlock
-    hal_remote_s32( taken_xp , 1 );
+lock_type_str[lock_type], lock_cxy, lock_ptr,
+hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) );
+#endif
 
     // release busylock
@@ -212,15 +228,17 @@
     remote_busylock_acquire( busylock_xp );
 
+	// decrement number of readers
+    hal_remote_atomic_add( count_xp , -1 );
+
 #if DEBUG_RWLOCK
 thread_t * this      = CURRENT_THREAD;
 uint32_t   lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->lock.type ) );
-if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
-printk("\n[%s] thread[%x,%x] READ RELEASE rwlock %s [%x,%x]\n",
+xptr_t     taken_xp  = XPTR( lock_cxy , &lock_ptr->taken );
+if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
+printk("\n[%s] thread[%x,%x] READ RELEASE rwlock %s [%x,%x] / taken %d / count %d\n",
 __FUNCTION__, this->process->pid, this->trdid,
-lock_type_str[lock_type], lock_cxy, lock_ptr );
-#endif
-
-	// decrement number of readers
-    hal_remote_atomic_add( count_xp , -1 );
+lock_type_str[lock_type], lock_cxy, lock_ptr,
+hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) );
+#endif
 
     // release first writer in waiting queue if no current readers
@@ -309,15 +327,17 @@
     remote_busylock_acquire( busylock_xp );
 
+    // release rwlock
+    hal_remote_s32( taken_xp , 0 );
+
 #if DEBUG_RWLOCK
 thread_t * this      = CURRENT_THREAD;
 uint32_t   lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->lock.type ) );
-if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
-printk("\n[%s] thread[%x,%x] WRITE RELEASE rwlock %s [%x,%x]\n",
+xptr_t     count_xp  = XPTR( lock_cxy , &lock_ptr->count );
+if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
+printk("\n[%s] thread[%x,%x] WRITE RELEASE rwlock %s [%x,%x] / taken %d / count %d\n",
 __FUNCTION__, this->process->pid, this->trdid,
-lock_type_str[lock_type], lock_cxy, lock_ptr );
-#endif
-
-    // release rwlock
-    hal_remote_s32( taken_xp , 0 );
+lock_type_str[lock_type], lock_cxy, lock_ptr,
+hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) );
+#endif
 
     // unblock first waiting writer thread if writers waiting queue non empty
