Index: trunk/kernel/kern/scheduler.h
===================================================================
--- trunk/kernel/kern/scheduler.h	(revision 690)
+++ trunk/kernel/kern/scheduler.h	(revision 1)
@@ -2,5 +2,5 @@
  * scheduler.h - Core scheduler definition.
  * 
- * Author    Alain Greiner       (2016,2017,2018,2019,2020)
+ * Author    Alain Greiner (2016)
  *
  * Copyright (c) UPMC Sorbonne Universites
@@ -25,7 +25,7 @@
 #define _SCHEDULER_H_
 
-#include <hal_kernel_types.h>
+#include <hal_types.h>
 #include <list.h>
-#include <busylock.h>
+#include <spinlock.h>
 
 /****  Forward declarations  ****/
@@ -34,69 +34,108 @@
 struct thread_s;
 
-/*********************************************************************************************
+/***********************************************************************************************
  * This structure define the scheduler associated to a given core.
- ********************************************************************************************/
+ * WARNING : the idle thread is executed when there is no runable thread in the list 
+ * of attached threads, but is NOT part of the list of attached threads.
+ **********************************************************************************************/
 
 typedef struct scheduler_s
 {
-    busylock_t        lock;            /*! lock protecting scheduler state                  */
-    uint32_t          u_threads_nr;    /*! total number of attached user threads            */
-    uint32_t          k_threads_nr;    /*! total number of attached kernel threads          */
-    list_entry_t      u_root;          /*! root of list of user threads                     */
-    list_entry_t      k_root;          /*! root of list of kernel threads                   */
-    list_entry_t    * u_last;          /*! pointer on list_entry for last executed k_thread */
-    list_entry_t    * k_last;          /*! pointer on list entry for last executed u_thread */
-    struct thread_s * idle;            /*! pointer on idle thread                           */
-    struct thread_s * current;         /*! pointer on current running thread                */
-    volatile bool_t   req_ack_pending; /*! sequencialize ack requests when true             */
-    bool_t            trace;           /*! context switches trace activated if true         */
+    spinlock_t        lock;         /*! readlock protecting lists of threads                  */
+    uint16_t          u_threads_nr; /*! total numbre of attached user threads                 */
+    uint16_t          k_threads_nr; /*! total number of attached kernel threads               */
+    list_entry_t      u_root;       /*! root of list of user threads for this scheduler       */
+    list_entry_t      k_root;       /*! root of list of kernel threads for this scheduler     */
+    list_entry_t    * u_last;       /*! pointer on list_entry for last executed kernel thread */
+    list_entry_t    * k_last;       /*! pointer on list entry for last executed user thread   */
+    struct thread_s * idle;         /*! pointer on idle thread                                */
+    struct thread_s * current;      /*! pointer on current running thread                     */
 }
 scheduler_t;
 
-/*********************************************************************************************
- *  This function initialises the scheduler for a given core.
- ********************************************************************************************/  
+/***********************************************************************************************
+ *  This function initialises the scheduler for a ginen core.
+ **********************************************************************************************/  
 void sched_init( struct core_s * core );
 
-/*********************************************************************************************
- * This function atomically register a new thread in a given core scheduler.
- * Note: There is no specific sched_remove_thread(), as a thread is always deleted
- * by the ched_handle_signals() function, called by the sched_yield() function.
- *********************************************************************************************
+/***********************************************************************************************
+ * This function register a new thread in a given core scheduler.
+ ***********************************************************************************************
  * @ core    : local pointer on the core descriptor.
  * @ thread  : local pointer on the thread descriptor.
- ********************************************************************************************/  
+ **********************************************************************************************/  
 void sched_register_thread( struct core_s   * core,
                             struct thread_s * thread );
 
-/********************************************************************************************* 
- * This function is the only method to make a context switch. It is called in cas of TICK,
- * or when a thread explicitely requires to be descheduled.
- * It takes the scheduler busylock to atomically update the scheduled state.
- * It calls the sched_select() private function to select a new thread. After switch, it 
- * calls the sched_handle_signals() private function to handle the pending REQ_ACK and 
- * REQ_DELETE flagss for all threads attached to the scheduler: it deletes all threads 
- * marked for delete (and the process descriptor when the deleted thread is the main thread).
- * As the REQ_DELETE flag can be asynchronously set (between the select and the handle),
- * the sched_handle-signals() function check that the thread to delete is not the new thread,
- * because a thread cannot delete itself.
- * The cause argument is only used for debug by the sched_display() functions, and indicates
- * the scheduling cause.
- *********************************************************************************************
- * @ cause    : character string defining the scheduling cause.
- ********************************************************************************************/
-void sched_yield( const char * cause );
+/*********************************************************************************************** 
+ *  This function removes a thread from the set of threads attached to a given core.
+ ***********************************************************************************************
+ * @ thread  : local pointer on the thread descriptor.
+ **********************************************************************************************/  
+void sched_remove_thread( struct thread_s * thread );
 
-/********************************************************************************************* 
- * This debug function displays on TXT0 the internal state of a scheduler, 
- * identified by the target cluster identifier <cxy> and the core local index <lid>.
- * It can be called by a thread running in any cluster, as it uses remote accesses,
- * to scan the scheduler lists of threads.
- *********************************************************************************************
- * @ cxy      : target cluster identifier
- * @ lid      : local index of target core.
- ********************************************************************************************/
-void sched_remote_display( cxy_t  cxy,
-                           lid_t  lid );
+/*********************************************************************************************** 
+ * This function handles pending signals for all registered threads, and tries to make 
+ * a context switch for the core running the calling thread.
+ * - If there is a runable thread (other than the current thread or the idle thread),
+ *   the calling thread is descheduled, but its state is not modified.
+ * - If there is no other runable thread, the calling thread continues execution.
+ * - If there is no runable thread, the idle thread is executed.
+ **********************************************************************************************/
+void sched_yield();
+
+/*********************************************************************************************** 
+ * This function handles pending signals for all registered threads, and make 
+ * a context switch to the thread defined by the <thread> argument.
+ * If the selected thread is not attached to the same core as the calling thread,
+ * or is blocked, it causes a kernel panic.
+ ***********************************************************************************************
+ * @ new   : local pointer on the thread to run.
+ **********************************************************************************************/
+void sched_switch_to( struct thread_s * new );
+
+/***********************************************************************************************
+ * This function scan all threads attached to a given core scheduler, and executes
+ * the relevant actions for pending signals, such as the THREAD_SIG_KILL signal.
+ ***********************************************************************************************
+ * @ core    : local pointer on the core descriptor.
+ **********************************************************************************************/
+void sched_handle_signals( struct core_s * core );
+
+/*********************************************************************************************** 
+ * This function is used by the scheduler of a given core to actually kill a thread that has 
+ * the SIG_KILL signal set (following a thread_exit() or a thread_kill() event).
+ * - It checks that the thread has released all locks => panic otherwise...
+ * - It detach the thread from the local process descriptor.
+ * - It removes the thread from the scheduler.
+ * - It release physical memory allocated for thread descriptor.
+ ***********************************************************************************************
+ * @ thread  : local pointer on the thread descriptor.
+ **********************************************************************************************/
+void sched_kill_thread( struct thread_s * thread );
+
+/***********************************************************************************************
+ * This function does NOT modify the scheduler state.
+ * It just select a thread in the list of attached threads, implementing the following policy: 
+ * 1) it scan the list of kernel threads, from the next thread after the last executed one,
+ *    and returns the first runnable found (can be the current thread).
+ * 2) if no kernel thread found, it scan the list of user thread, from the next thread after
+ *    the last executed one, and returns the first runable found (can be the current thread).
+ * 3) if no runable thread found, it returns the idle thread.
+ ***********************************************************************************************
+ * @ core    : local pointer on the core descriptor.
+ * @ returns pointer on selected thread descriptor
+ **********************************************************************************************/
+struct thread_s * sched_select( struct core_s * core );
+
+/*********************************************************************************************** 
+ * This function scan the list of kernel threads to find an idle (blocked) RPC thread.
+ ***********************************************************************************************
+ * @ core    : local pointer on the core descriptor.
+ * @ returns pointer on RPC thread descriptor / returns NULL if no idle RPC thread.
+ **********************************************************************************************/
+struct thread_s * sched_get_rpc_thead( struct core_s * core );
+
+
 
 #endif	/* _SCHEDULER_H_ */
