mirror of https://github.com/ARMmbed/mbed-os.git
Protect Ticker attach with a critical section
Add a critical section to attach_us so setting _function and locking deep sleep are done atomically.pull/5220/head
parent
ea468856c4
commit
87b151c8a0
|
@ -22,6 +22,7 @@
|
||||||
#include "platform/NonCopyable.h"
|
#include "platform/NonCopyable.h"
|
||||||
#include "platform/mbed_sleep.h"
|
#include "platform/mbed_sleep.h"
|
||||||
#include "hal/lp_ticker_api.h"
|
#include "hal/lp_ticker_api.h"
|
||||||
|
#include "platform/mbed_critical.h"
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
/** \addtogroup drivers */
|
/** \addtogroup drivers */
|
||||||
|
@ -113,12 +114,14 @@ public:
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void attach_us(Callback<void()> func, us_timestamp_t t) {
|
void attach_us(Callback<void()> func, us_timestamp_t t) {
|
||||||
|
core_util_critical_section_enter();
|
||||||
// lock only for the initial callback setup and this is not low power ticker
|
// lock only for the initial callback setup and this is not low power ticker
|
||||||
if(!_function && _lock_deepsleep) {
|
if(!_function && _lock_deepsleep) {
|
||||||
sleep_manager_lock_deep_sleep();
|
sleep_manager_lock_deep_sleep();
|
||||||
}
|
}
|
||||||
_function = func;
|
_function = func;
|
||||||
setup(t);
|
setup(t);
|
||||||
|
core_util_critical_section_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Attach a member function to be called by the Ticker, specifying the interval in micro-seconds
|
/** Attach a member function to be called by the Ticker, specifying the interval in micro-seconds
|
||||||
|
|
Loading…
Reference in New Issue