Restore preempt_forbid_cnt as private; supply an accessor macro.
[bertos.git] / bertos / kern / proc.h
index f8de758ffeec511879400f20d750311d3b3c992b..1a35834683c13c27db0bdc23a73bd178bd510b45 100644 (file)
@@ -85,9 +85,6 @@ const char *proc_currentName(void);
        }
 #endif
 
-/** Global preemption disable nesting counter. */
-extern int preempt_forbid_cnt;
-
 /**
  * Disable preemptive task switching.
  *
@@ -108,11 +105,12 @@ extern int preempt_forbid_cnt;
 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;
@@ -133,13 +131,13 @@ INLINE void proc_permit(void)
                 * 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;
@@ -147,6 +145,21 @@ INLINE void proc_permit(void)
        #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.
  */