Index: trunk/kernel/libk/rwlock.c
===================================================================
--- trunk/kernel/libk/rwlock.c	(revision 600)
+++ trunk/kernel/libk/rwlock.c	(revision 603)
@@ -49,4 +49,13 @@
 
     busylock_init( &lock->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 );
+#endif
+
 }
 
@@ -68,7 +77,7 @@
 #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",
-__FUNCTION__, this->process->pid, this->trdid, 
-lock_type_str[lock->lock.type], local_cxy, lock );
+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->lock.type], local_cxy, lock, lock->taken, lock->count );
 #endif
         // register reader thread in waiting queue
@@ -88,13 +97,13 @@
     }
 
-#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->lock.type], local_cxy, lock );
-#endif
-
     // increment number of readers
     lock->count++;
+
+#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->lock.type], local_cxy, lock, lock->taken, lock->count );
+#endif
 
     // release busylock 
@@ -120,12 +129,12 @@
 #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",
-__FUNCTION__, this->process->pid, this->trdid, 
-lock_type_str[lock->lock.type], local_cxy, lock );
+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->lock.type], local_cxy, lock, lock->taken, lock->count );
 #endif
         // register writer in waiting queue
         list_add_last( &lock->wr_root , &this->wait_list );
 
-        // block reader thread
+        // block writer thread
         thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_LOCK );
         
@@ -140,13 +149,13 @@
     }
 
-#if DEBUG_RWLOCK
-if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
-printk("\n[%s] thread[%x,%x] WRITE ACQUIRE rwlock %s [%x,%x]\n",
-__FUNCTION__, this->process->pid, this->trdid, 
-lock_type_str[lock->lock.type], local_cxy, lock );
-#endif
-
     // take the rwlock
     lock->taken = 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->lock.type], local_cxy, lock, lock->taken, lock->count );
+#endif
 
     // release busylock 
@@ -164,14 +173,14 @@
     busylock_acquire( &lock->lock );
 
-#if DEBUG_RWLOCK
-thread_t * this = CURRENT_THREAD;
-if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
-printk("\n[%s] thread[%x,%x] READ RELEASE rwlock %s [%x,%x]\n",
-__FUNCTION__, this->process->pid, this->trdid, 
-lock_type_str[lock->lock.type], local_cxy, lock );
-#endif
-
     // decrement number of readers
     lock->count--;
+
+#if DEBUG_RWLOCK
+thread_t * this = CURRENT_THREAD;
+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->lock.type], local_cxy, lock, lock->taken, lock->count );
+#endif
 
     // release first writer in waiting queue if no current readers
@@ -233,14 +242,14 @@
     busylock_acquire( &lock->lock );
 
-#if DEBUG_RWLOCK
-thread_t * this = CURRENT_THREAD;
-if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
-printk("\n[%s] thread[%x,%x] WRITE RELEASE rwlock %s [%x,%x]\n",
-__FUNCTION__, this->process->pid, this->trdid, 
-lock_type_str[lock->lock.type], local_cxy, lock );
-#endif
-
     // release the rwlock
     lock->taken = 0;
+
+#if DEBUG_RWLOCK
+thread_t * this = CURRENT_THREAD;
+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->lock.type], local_cxy, lock, lock->taken, lock->count );
+#endif
 
     // release first waiting writer thread if writers waiting queue non empty
