MOD_DEFINE(preempt)
-int preempt_forbid_cnt;
+/** Global preemption disabling nesting counter */
+int _preempt_forbid_cnt;
static Timer preempt_timer;
{
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?");
void proc_preempt(UNUSED_ARG(void *, param))
{
- if (!preempt_forbid_cnt)
+ if (proc_allowed())
{
IRQ_DISABLE;
/* 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);
}
#endif
-/** Global preemption disable nesting counter. */
-extern int preempt_forbid_cnt;
-
/**
* Disable preemptive task switching.
*
INLINE void proc_forbid(void)
{
#if CONFIG_KERN_PREEMPT
+ extern int _preempt_forbid_cnt;
// No need to protect against interrupts here.
- ++preempt_forbid_cnt;
+ ++_preempt_forbid_cnt;
/*
- * Make sure preempt_forbid_cnt is flushed to memory so the
+ * Make sure _preempt_forbid_cnt is flushed to memory so the
* preemption softirq will see the correct value from now on.
*/
MEMORY_BARRIER;
* flushed to memory before task switching is re-enabled.
*/
MEMORY_BARRIER;
-
+ extern int _preempt_forbid_cnt;
/* No need to protect against interrupts here. */
- --preempt_forbid_cnt;
- ASSERT(preempt_forbid_cnt >= 0);
+ --_preempt_forbid_cnt;
+ ASSERT(_preempt_forbid_cnt >= 0);
/*
- * This ensures preempt_forbid_cnt is flushed to memory immediately
+ * This ensures _preempt_forbid_cnt is flushed to memory immediately
* so the preemption interrupt sees the correct value.
*/
MEMORY_BARRIER;
#endif
}
+/**
+ * \return true if preemptive task switching is allowed.
+ * \note This accessor is needed because _preempt_forbid_cnt
+ * must be absoultely private.
+ */
+INLINE bool proc_allowed(void)
+{
+ #if CONFIG_KERN_PREEMPT
+ extern int _preempt_forbid_cnt;
+ return (_preempt_forbid_cnt == 0);
+ #else
+ return true;
+ #endif
+}
+
/**
* Execute a block of \a CODE atomically with respect to task scheduling.
*/
/* Sleeping with IRQs disabled or preemption forbidden is illegal */
IRQ_ASSERT_ENABLED();
-
- #if CONFIG_KERN_PREEMPT
- ASSERT(preempt_forbid_cnt == 0);
- #endif
+ ASSERT(proc_allowed());
/*
* This is subtle: there's a race condition where a concurrent