Skip to content

Commit 87b151c

Browse files
committed
Protect Ticker attach with a critical section
Add a critical section to attach_us so setting _function and locking deep sleep are done atomically.
1 parent ea46885 commit 87b151c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/Ticker.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "platform/NonCopyable.h"
2323
#include "platform/mbed_sleep.h"
2424
#include "hal/lp_ticker_api.h"
25+
#include "platform/mbed_critical.h"
2526

2627
namespace mbed {
2728
/** \addtogroup drivers */
@@ -113,12 +114,14 @@ class Ticker : public TimerEvent, private NonCopyable<Ticker> {
113114
*
114115
*/
115116
void attach_us(Callback<void()> func, us_timestamp_t t) {
117+
core_util_critical_section_enter();
116118
// lock only for the initial callback setup and this is not low power ticker
117119
if(!_function && _lock_deepsleep) {
118120
sleep_manager_lock_deep_sleep();
119121
}
120122
_function = func;
121123
setup(t);
124+
core_util_critical_section_exit();
122125
}
123126

124127
/** Attach a member function to be called by the Ticker, specifying the interval in micro-seconds

0 commit comments

Comments
 (0)