preempt_forbid_cnt: make it of type cpuatomic_t
authorbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 29 Aug 2008 20:36:39 +0000 (20:36 +0000)
committerbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 29 Aug 2008 20:36:39 +0000 (20:36 +0000)
This takes care of archs such as the AVR, where int is bigger than the
word size, and updating preempt_forbid_cnt might actually result in two
independent writes.

git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1760 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/kern/preempt.c
bertos/kern/proc.h

index 2c44373b0517b7c66b1e1d5f1baa9f93061730a4..69b555a998422b460a4bc552170016e189aad948 100644 (file)
@@ -65,8 +65,8 @@ CONFIG_DEPEND(CONFIG_KERN_PREEMPT,    CONFIG_KERN_SCHED && CONFIG_TIMER_EVENTS &
 
 MOD_DEFINE(preempt)
 
 
 MOD_DEFINE(preempt)
 
-/** Global preemption disabling nesting counter */
-int _preempt_forbid_cnt;
+/// Global preemption disabling nesting counter
+cpuatomic_t _preempt_forbid_cnt;
 
 static Timer preempt_timer;
 
 
 static Timer preempt_timer;
 
index 5c26465257f075b4ef71213095266f421e5396cd..4efdf9df8e073e4d0a1ff41783dcdf9b32d7c2b0 100644 (file)
@@ -108,7 +108,7 @@ const char *proc_currentName(void);
 INLINE void proc_forbid(void)
 {
        #if CONFIG_KERN_PREEMPT
 INLINE void proc_forbid(void)
 {
        #if CONFIG_KERN_PREEMPT
-               extern int _preempt_forbid_cnt;
+               extern cpuatomic_t _preempt_forbid_cnt;
                /*
                 * We don't need to protect the counter against other processes.
                 * The reason why is a bit subtle.
                /*
                 * We don't need to protect the counter against other processes.
                 * The reason why is a bit subtle.
@@ -156,7 +156,7 @@ INLINE void proc_permit(void)
                 * flushed to memory before task switching is re-enabled.
                 */
                MEMORY_BARRIER;
                 * flushed to memory before task switching is re-enabled.
                 */
                MEMORY_BARRIER;
-               extern int _preempt_forbid_cnt;
+               extern cpuatomic_t _preempt_forbid_cnt;
                /* No need to protect against interrupts here. */
                ASSERT(_preempt_forbid_cnt != 0);
                --_preempt_forbid_cnt;
                /* No need to protect against interrupts here. */
                ASSERT(_preempt_forbid_cnt != 0);
                --_preempt_forbid_cnt;
@@ -178,7 +178,7 @@ INLINE void proc_permit(void)
 INLINE bool proc_allowed(void)
 {
        #if CONFIG_KERN_PREEMPT
 INLINE bool proc_allowed(void)
 {
        #if CONFIG_KERN_PREEMPT
-               extern int _preempt_forbid_cnt;
+               extern cpuatomic_t _preempt_forbid_cnt;
                return (_preempt_forbid_cnt == 0);
        #else
                return true;
                return (_preempt_forbid_cnt == 0);
        #else
                return true;