Index: trunk/kernel/kern/thread.c
===================================================================
--- trunk/kernel/kern/thread.c	(revision 564)
+++ trunk/kernel/kern/thread.c	(revision 580)
@@ -1216,4 +1216,12 @@
     xptr_t        lock_xp;             // extended pointer on lock protecting  this list
 
+#if DEBUG_THREAD_GET_XPTR
+uint32_t cycle  = (uint32_t)hal_get_cycles();
+thread_t * this = CURRENT_THREAD;
+if( DEBUG_THREAD_GET_XPTR < cycle )
+printk("\n[DBG] %s : thread %x in process %x enters / pid %x / trdid %x / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, pid, trdid, cycle );
+#endif
+
     // get target cluster identifier and local thread identifier
     target_cxy         = CXY_FROM_TRDID( trdid );
@@ -1235,4 +1243,9 @@
     remote_queuelock_acquire( lock_xp );
 
+#if( DEBUG_THREAD_GET_XPTR & 1 )
+if( DEBUG_THREAD_GET_XPTR < cycle )
+printk("\n[DBG]  %s : scan processes in cluster %x :\n", __FUNCTION__, target_cxy );
+#endif
+
     // scan the list of local processes in target cluster
     xptr_t  iter;
@@ -1243,4 +1256,10 @@
         target_process_ptr = GET_PTR( target_process_xp );
         target_process_pid = hal_remote_l32( XPTR( target_cxy , &target_process_ptr->pid ) );
+
+#if( DEBUG_THREAD_GET_XPTR & 1 )
+if( DEBUG_THREAD_GET_XPTR < cycle )
+printk(" - process %x\n", target_process_pid );
+#endif
+
         if( target_process_pid == pid )
         {
@@ -1254,5 +1273,14 @@
 
     // check PID found
-    if( found == false ) return XPTR_NULL;
+    if( found == false ) 
+    {
+
+#if( DEBUG_THREAD_GET_XPTR & 1 )
+if( DEBUG_THREAD_GET_XPTR < cycle )
+printk("\n[DBG] %s : pid %x not found in cluster %x\n",
+__FUNCTION__, pid, target_cxy );
+#endif
+        return XPTR_NULL;
+    }
 
     // get target thread local pointer
@@ -1260,5 +1288,21 @@
     target_thread_ptr = (thread_t *)hal_remote_lpt( xp );
 
-    if( target_thread_ptr == NULL )  return XPTR_NULL;
+    if( target_thread_ptr == NULL )
+    {
+
+#if( DEBUG_THREAD_GET_XPTR & 1 )
+if( DEBUG_THREAD_GET_XPTR < cycle )
+printk("\n[DBG] %s : thread %x not registered in process %x in cluster %x\n",
+__FUNCTION__, trdid, pid, target_cxy );
+#endif
+        return XPTR_NULL;
+    }
+
+#if DEBUG_THREAD_GET_XPTR
+cycle  = (uint32_t)hal_get_cycles();
+if( DEBUG_THREAD_GET_XPTR < cycle )
+printk("\n[DBG] %s : thread %x in process %x exit / pid %x / trdid %x / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, pid, trdid, cycle );
+#endif
 
     return XPTR( target_cxy , target_thread_ptr );
@@ -1287,25 +1331,24 @@
         // display error message on TXT0
         nolock_printk("\n[PANIC] in %s / thread %x in process %x [%x] cannot yield : "
-        "%d busylock(s) / cycle %d\n",
+        "hold %d busylock(s) / cycle %d\n",
         func_str, thread->trdid, thread->process->pid, thread,
         thread->busylocks, (uint32_t)hal_get_cycles() );
 
 #if DEBUG_BUSYLOCK
-if( XPTR( local_cxy , thread ) == DEBUG_BUSYLOCK_THREAD_XP )
-{
-    // get root of list of taken busylocks
-    xptr_t    root_xp  = XPTR( local_cxy , &thread->busylocks_root );
-    xptr_t    iter_xp;
-
-    // scan list of busylocks
-    XLIST_FOREACH( root_xp , iter_xp )
-    {
-        xptr_t       lock_xp   = XLIST_ELEMENT( iter_xp , busylock_t , xlist );
-        cxy_t        lock_cxy  = GET_CXY( lock_xp );
-        busylock_t * lock_ptr  = GET_PTR( lock_xp );
-        uint32_t     lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->type ) );
-        nolock_printk(" - %s in cluster %x\n", lock_type_str[lock_type] , lock_cxy );
-    }
+
+// get root of list of taken busylocks
+xptr_t    root_xp  = XPTR( local_cxy , &thread->busylocks_root );
+xptr_t    iter_xp;
+
+// scan list of busylocks
+XLIST_FOREACH( root_xp , iter_xp )
+{
+    xptr_t       lock_xp   = XLIST_ELEMENT( iter_xp , busylock_t , xlist );
+    cxy_t        lock_cxy  = GET_CXY( lock_xp );
+    busylock_t * lock_ptr  = GET_PTR( lock_xp );
+    uint32_t     lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->type ) );
+    nolock_printk(" - %s in cluster %x\n", lock_type_str[lock_type] , lock_cxy );
 }
+
 #endif
 
@@ -1318,54 +1361,62 @@
 }  // end thread_assert_can yield()
 
-#if DEBUG_BUSYLOCK
-
-////////////////////////////////////////////////////
-void thread_display_busylocks( uint32_t   lock_type,
-                               bool_t     is_acquire )
-{
-    xptr_t    iter_xp;
-
-    // get cluster and local pointer of target thread
-    cxy_t      thread_cxy = GET_CXY( DEBUG_BUSYLOCK_THREAD_XP );
-    thread_t * thread_ptr = GET_PTR( DEBUG_BUSYLOCK_THREAD_XP );
-
-    // get extended pointer on root of busylocks
-    xptr_t    root_xp = XPTR( thread_cxy , &thread_ptr->busylocks_root );
-
-   // get pointers on TXT0 chdev
-    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
-    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
-    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
-
-    // get extended pointer on remote TXT0 lock
-    xptr_t  txt0_lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
-
-    // get TXT0 lock 
-    remote_busylock_acquire( txt0_lock_xp );
-
-    if( is_acquire )
-    {
-        nolock_printk("\n### thread [%x,%x] ACQUIRE lock %s / root %x / locks :\n",
-        thread_cxy, thread_ptr, lock_type_str[lock_type], GET_PTR(root_xp) );
+//////////////////////////////////////////////////
+void thread_display_busylocks( xptr_t  thread_xp )
+{
+    if( DEBUG_BUSYLOCK )
+    {
+        xptr_t    iter_xp;
+
+        // get cluster and local pointer of target thread
+        cxy_t      thread_cxy = GET_CXY( thread_xp );
+        thread_t * thread_ptr = GET_PTR( thread_xp );
+
+        // get target thread TRDID and busylocks
+        trdid_t  trdid = hal_remote_l32(XPTR( thread_cxy , &thread_ptr->trdid ));
+        uint32_t locks = hal_remote_l32(XPTR( thread_cxy , &thread_ptr->busylocks ));
+
+        // get target thread process and PID;
+        process_t * process = hal_remote_lpt(XPTR( thread_cxy , &thread_ptr->process ));
+        pid_t       pid     = hal_remote_l32(XPTR( thread_cxy , &process->pid ));
+
+        // get extended pointer on root of busylocks
+        xptr_t    root_xp = XPTR( thread_cxy , &thread_ptr->busylocks_root );
+
+        // get pointers on TXT0 chdev
+        xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
+        cxy_t     txt0_cxy = GET_CXY( txt0_xp );
+        chdev_t * txt0_ptr = GET_PTR( txt0_xp );
+
+        // get extended pointer on remote TXT0 lock
+        xptr_t  txt0_lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
+
+        // get TXT0 lock 
+        remote_busylock_acquire( txt0_lock_xp );
+
+        // display header 
+        nolock_printk("\n***** thread %x in process %x : %d busylocks at cycle %d\n",
+        trdid, pid, locks, (uint32_t)hal_get_cycles() );
+
+        // scan the xlist of busylocks when required
+        if( locks )
+        {
+            XLIST_FOREACH( root_xp , iter_xp )
+            {
+                xptr_t       lock_xp   = XLIST_ELEMENT( iter_xp , busylock_t , xlist );
+                cxy_t        lock_cxy  = GET_CXY( lock_xp );
+                busylock_t * lock_ptr  = GET_PTR( lock_xp );
+                uint32_t     lock_type = hal_remote_l32(XPTR( lock_cxy , &lock_ptr->type ));
+                nolock_printk(" - %s in cluster %x\n", lock_type_str[lock_type] , lock_cxy );
+            }
+        }
+
+        // release TXT0 lock
+        remote_busylock_release( txt0_lock_xp );
     }
     else
     {
-        nolock_printk("\n### thread [%x,%x] RELEASE lock %s / root %x / locks :\n",
-        thread_cxy, thread_ptr, lock_type_str[lock_type], GET_PTR(root_xp) );
-    }
-
-    int i;
-
-    XLIST_FOREACH( root_xp , iter_xp )
-    {
-        xptr_t       ilock_xp   = XLIST_ELEMENT( iter_xp , busylock_t , xlist );
-        cxy_t        ilock_cxy  = GET_CXY( ilock_xp );
-        busylock_t * ilock_ptr  = GET_PTR( ilock_xp );
-        uint32_t     ilock_type = hal_remote_l32( XPTR( ilock_cxy , &ilock_ptr->type ) );
-        nolock_printk(" - %s in cluster %x\n", lock_type_str[ilock_type] , ilock_cxy );
-    }
-
-    // release TXT0 lock
-    remote_busylock_release( txt0_lock_xp );
-}
-#endif
+        // display a warning
+        printk("\n[WARNING] set the DEBUG_BUSYLOCK parmeter in kernel_config.h"
+        " to use the %s function\n", __FUNCTION__ );
+    }
+}  // end thread_display_busylock()
