Index: trunk/kernel/kern/scheduler.c
===================================================================
--- trunk/kernel/kern/scheduler.c	(revision 407)
+++ trunk/kernel/kern/scheduler.c	(revision 408)
@@ -128,16 +128,13 @@
 }  // end sched_remove()
 
-////////////////////////////////////////
-thread_t * sched_select( core_t * core )
-{
-    thread_t    * thread;
-
-    scheduler_t * sched = &core->scheduler;
+//////////////////////////////////////////////
+thread_t * sched_select( scheduler_t * sched )
+{
+    thread_t     * thread;
+    list_entry_t * current;
+    list_entry_t * last;
 
     // take lock protecting sheduler lists
     spinlock_lock( &sched->lock );
-
-    list_entry_t * current;
-    list_entry_t * last;
 
     // first loop : scan the kernel threads list if not empty 
@@ -172,6 +169,7 @@
                 break;
 
-                default:          // DEV thread if non blocked
-                if( thread->blocked == 0 )
+                default:          // DEV thread if non blocked and waiting queue non empty
+                if( (thread->blocked == 0) &&
+                    (xlist_is_empty( XPTR( local_cxy , &thread->chdev->wait_root)) == 0) ) 
                 {
                     spinlock_unlock( &sched->lock );
@@ -253,4 +251,7 @@
     scheduler_t  * sched = &core->scheduler;
 
+// signal_dmsg("\n@@@ %s enter at cycle %d\n",
+// __FUNCTION__ , hal_time_stamp() );
+
     // take lock protecting threads lists
     spinlock_lock( &sched->lock );
@@ -260,5 +261,9 @@
     {
         thread = LIST_ELEMENT( iter , thread_t , sched_list );
-        if( thread->signals ) sched_kill_thread( thread );
+        if( thread->signals ) // sched_kill_thread( thread );
+        {
+            printk("\n[WARNING] %s : thread %x has signal %x at cycle %d\n",
+            __FUNCTION__, thread, thread->signals, hal_time_stamp() );
+        }
     }
 
@@ -267,5 +272,10 @@
     {
         thread = LIST_ELEMENT( iter , thread_t , sched_list );
-        if( thread->signals ) sched_kill_thread( thread );
+        if( thread->signals )  // sched_kill_thread( thread );
+        {
+            printk("\n[WARNING] %s : thread %x has signal %x at cycle %d\n",
+            __FUNCTION__, thread, thread->signals, hal_time_stamp() );
+
+        }
     }
 
@@ -273,23 +283,15 @@
     spinlock_unlock( &sched->lock );
 
+// signal_dmsg("\n@@@ %s exit at cycle %d\n",
+// __FUNCTION__ , hal_time_stamp() );
+
 } // end sched_handle_signals()
 
-//////////////////////////////////////
-void sched_update( thread_t * current,
-                   thread_t * next )
-{
-    scheduler_t * sched = &current->core->scheduler;
-
-    if( current->type == THREAD_USER ) sched->u_last = &current->sched_list;
-    else                               sched->k_last = &current->sched_list;
-
-    sched->current = next;
-}
-
-//////////////////
-void sched_yield()
+////////////////////////////////
+void sched_yield( char * cause )
 {
     thread_t    * next;
     thread_t    * current = CURRENT_THREAD;
+    scheduler_t * sched   = &current->core->scheduler;
  
 #if( CONFIG_SCHED_DEBUG & 0x1 )
@@ -304,6 +306,9 @@
     }
 
+    // enter critical section / save SR in current thread context
+    hal_disable_irq( &current->save_sr );
+
     // loop on threads to select next thread 
-    next = sched_select( current->core );
+    next = sched_select( sched );
 
     // check next thread attached to same core as the calling thread
@@ -319,15 +324,16 @@
 	if( next != current )
     {
-        // current thread desactivate IRQs
-        hal_disable_irq( &switch_save_sr[CURRENT_THREAD->core->lid] );
-
-sched_dmsg("\n[DBG] %s : core[%x,%d] / trd %x (%s) (%x,%x) => trd %x (%s) (%x,%x) / cycle %d\n",
-__FUNCTION__, local_cxy, current->core->lid, 
+
+sched_dmsg("\n[DBG] %s : core[%x,%d] / cause = %s\n"
+"      thread %x (%s) (%x,%x) => thread %x (%s) (%x,%x) / cycle %d\n",
+__FUNCTION__, local_cxy, current->core->lid, cause, 
 current, thread_type_str(current->type), current->process->pid, current->trdid,
 next   , thread_type_str(next->type)   , next->process->pid   , next->trdid,
-hal_time_stamp() );
+(uint32_t)hal_get_cycles() );
 
         // update scheduler 
-        sched_update( current , next );
+        sched->current = next;
+        if( next->type == THREAD_USER ) sched->u_last = &next->sched_list;
+        else                            sched->k_last = &next->sched_list;
 
         // handle FPU ownership
@@ -340,16 +346,19 @@
         // switch CPU from calling thread context to new thread context
         hal_do_cpu_switch( current->cpu_context, next->cpu_context );
-
-        // restore IRQs when next thread resume
-        hal_restore_irq( switch_save_sr[CURRENT_THREAD->core->lid] );
     }
     else
     {
 
-sched_dmsg("\n[DBG] %s : core[%x,%d] / thread %x (%s) continue / cycle %d\n",
-__FUNCTION__, local_cxy, current->core->lid, current->trdid, 
-thread_type_str(current->type) ,hal_time_stamp() );
-
-    }
+sched_dmsg("\n[DBG] %s : core[%x,%d] / cause = %s\n" 
+"      thread %x (%s) (%x,%x) continue / cycle %d\n",
+__FUNCTION__, local_cxy, current->core->lid, cause,
+current, thread_type_str(current->type), current->process->pid, current->trdid, 
+(uint32_t)hal_get_cycles() );
+
+    }
+
+    // exit critical section / restore SR from next thread context
+    hal_restore_irq( next->save_sr );
+
 }  // end sched_yield()
 
@@ -384,8 +393,8 @@
 
     nolock_printk("\n***** scheduler state for core[%x,%d] at cycle %d\n"
-           "kernel_threads = %d / user_threads = %d / current = %x / idle = %x\n",
+           "kernel_threads = %d / user_threads = %d / current = (%x,%x)\n",
             local_cxy , core->lid, hal_time_stamp(),
             sched->k_threads_nr, sched->u_threads_nr,
-            sched->current->trdid , sched->idle->trdid );
+            sched->current->process->pid , sched->current->trdid );
 
     // display kernel threads
@@ -393,7 +402,16 @@
     {
         thread = LIST_ELEMENT( iter , thread_t , sched_list );
-        nolock_printk(" - type = %s / trdid = %X / pid = %X / func = %X / blocked = %X\n",
-        thread_type_str( thread->type ), thread->trdid, thread->process->pid,
-        thread->entry_func, thread->blocked );
+        if (thread->type == THREAD_DEV) 
+        {
+            nolock_printk(" - %s / pid %X / trdid %X / desc %X / blocked %X / %s\n",
+            thread_type_str( thread->type ), thread->process->pid, thread->trdid,
+            thread, thread->blocked , thread->chdev->name );
+        }
+        else
+        {
+            nolock_printk(" - %s / pid %X / trdid %X / desc %X / blocked %X\n",
+            thread_type_str( thread->type ), thread->process->pid, thread->trdid,
+            thread, thread->blocked );
+        }
     }
 
@@ -402,7 +420,7 @@
     {
         thread = LIST_ELEMENT( iter , thread_t , sched_list );
-        nolock_printk(" - type = %s / trdid = %X / pid = %X / func = %X / blocked = %X\n",
-        thread_type_str( thread->type ), thread->trdid, thread->process->pid,
-        thread->entry_func, thread->blocked );
+        nolock_printk(" - %s / pid %X / trdid %X / desc %X / blocked %X\n",
+        thread_type_str( thread->type ), thread->process->pid, thread->trdid,
+        thread, thread->blocked );
     }
 
