From 74e2ba2168f9cebed97b0255065be8e9680cfa1b Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Wed, 2 Jan 2013 16:32:23 -0800 Subject: [PATCH] AP_HAL_AVR Scheduler: _in_timer_proc is volatile protected * and AVRSemaphore is a friend, so it can read _in_timer_proc to know the current context. --- libraries/AP_HAL_AVR/Scheduler.cpp | 2 +- libraries/AP_HAL_AVR/Scheduler.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/AP_HAL_AVR/Scheduler.cpp b/libraries/AP_HAL_AVR/Scheduler.cpp index fcf7888737..1293afd37f 100644 --- a/libraries/AP_HAL_AVR/Scheduler.cpp +++ b/libraries/AP_HAL_AVR/Scheduler.cpp @@ -22,9 +22,9 @@ AVRTimer AVRScheduler::_timer; AP_HAL::TimedProc AVRScheduler::_failsafe = NULL; volatile bool AVRScheduler::_timer_suspended = false; +volatile bool AVRScheduler::_in_timer_proc = false; AP_HAL::TimedProc AVRScheduler::_timer_proc[AVR_SCHEDULER_MAX_TIMER_PROCS] = {NULL}; uint8_t AVRScheduler::_num_timer_procs = 0; -bool AVRScheduler::_in_timer_proc = false; AVRScheduler::AVRScheduler() : diff --git a/libraries/AP_HAL_AVR/Scheduler.h b/libraries/AP_HAL_AVR/Scheduler.h index 24bff6f1d9..cc18ba289b 100644 --- a/libraries/AP_HAL_AVR/Scheduler.h +++ b/libraries/AP_HAL_AVR/Scheduler.h @@ -18,6 +18,8 @@ public: /* Scheduler implementation: */ class AP_HAL_AVR::AVRScheduler : public AP_HAL::Scheduler { + /* AVRSemaphore gets access to _in_timer_proc */ + friend class AVRSemaphore; public: AVRScheduler(); /* AP_HAL::Scheduler methods */ @@ -39,6 +41,9 @@ public: void panic(const prog_char_t *errormsg); void reboot(); +protected: + static volatile bool _in_timer_proc; + private: static AVRTimer _timer; @@ -54,7 +59,6 @@ private: static volatile bool _timer_suspended; static AP_HAL::TimedProc _timer_proc[AVR_SCHEDULER_MAX_TIMER_PROCS]; static uint8_t _num_timer_procs; - static bool _in_timer_proc; uint8_t _nested_atomic_ctr;