Switch to new kernel config files.
[bertos.git] / bertos / kern / preempt.c
index 85aab8ea05a3e19eab9d976efbbbff753f1d42c7..a92460bdf07620a1d6c18976886d390e01909562 100644 (file)
  * \author Bernie Innocenti <bernie@codewiz.org>
  */
 
-#include <cfg/cfg_kern.h>
+#include "cfg/cfg_proc.h"
 
 #if CONFIG_KERN_PREEMPT
 
 #include "proc_p.h"
 #include "proc.h"
+#include "idle.h"
 
 #include <kern/irq.h>
 #include <kern/monitor.h>
 #include <cfg/depend.h>    // CONFIG_DEPEND()
 
 // Check config dependencies
-CONFIG_DEPEND(CONFIG_KERN_PREEMPT,    CONFIG_KERN_SCHED && CONFIG_TIMER_EVENTS && CONFIG_KERN_IRQ);
+CONFIG_DEPEND(CONFIG_KERN_PREEMPT, CONFIG_KERN && CONFIG_TIMER_EVENTS && CONFIG_KERN_IRQ);
 
 MOD_DEFINE(preempt)
 
-int preempt_forbid_cnt;
+/// Global preemption disabling nesting counter
+cpu_atomic_t _preempt_forbid_cnt;
 
 static Timer preempt_timer;
 
 
-// fwd decl from idle.c
-void idle_init(void);
-
-
 void proc_schedule(void)
 {
        IRQ_DISABLE;
 
-       ASSERT(preempt_forbid_cnt == 0);
+       ASSERT(proc_allowed());
        LIST_ASSERT_VALID(&ProcReadyList);
        CurrentProcess = (struct Process *)list_remHead(&ProcReadyList);
        ASSERT2(CurrentProcess, "no idle proc?");
@@ -89,7 +87,7 @@ void proc_schedule(void)
 
 void proc_preempt(UNUSED_ARG(void *, param))
 {
-       if (!preempt_forbid_cnt)
+       if (proc_allowed())
        {
                IRQ_DISABLE;
 
@@ -125,7 +123,7 @@ void proc_switch(void)
 
        /* Sleeping with IRQs disabled or preemption forbidden is illegal */
        IRQ_ASSERT_ENABLED();
-       ASSERT(preempt_forbid_cnt == 0);
+       ASSERT(proc_allowed());
 
        // Will invoke proc_switch() in interrupt context
        kill(0, SIGUSR1);