File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ static const uint32_t TOLERANCE_ACCURACY_US = (DELAY_10S *US_PER_SEC / ACCURACY_
42
42
#if DEVICE_LPTICKER
43
43
volatile bool expired;
44
44
45
- void callback (void )
45
+ void set_flag_true (void )
46
46
{
47
47
expired = true ;
48
48
}
@@ -72,7 +72,7 @@ void rtc_sleep_test_support(bool deepsleep_mode)
72
72
73
73
rtc_write (start);
74
74
75
- timeout.attach (callback , DELAY_4S);
75
+ timeout.attach (set_flag_true , DELAY_4S);
76
76
77
77
TEST_ASSERT (sleep_manager_can_deep_sleep_test_check () == deepsleep_mode);
78
78
Original file line number Diff line number Diff line change 17
17
#ifndef MBED_TICKER_H
18
18
#define MBED_TICKER_H
19
19
20
+ #include < mstd_utility>
20
21
#include " drivers/TimerEvent.h"
21
22
#include " platform/Callback.h"
22
23
#include " platform/mbed_toolchain.h"
@@ -75,12 +76,17 @@ class Ticker : public TimerEvent, private NonCopyable<Ticker> {
75
76
76
77
/* * Attach a function to be called by the Ticker, specifying the interval in seconds
77
78
*
79
+ * The method forwards its arguments to attach_us() rather than copying them which
80
+ * may not be trivial depending on the callback copied.
81
+ * The function is forcibly inlined to not use floating-point operations. This is
82
+ * possible given attach_us() expects an integer value for the callback interval.
78
83
* @param func pointer to the function to be called
79
84
* @param t the time between calls in seconds
80
85
*/
81
- void attach (Callback<void ()> func, float t)
86
+ template <typename F>
87
+ MBED_FORCEINLINE void attach (F &&func, float t)
82
88
{
83
- attach_us (func, t * 1000000 .0f );
89
+ attach_us (std::forward<F>( func) , t * 1000000 .0f );
84
90
}
85
91
86
92
/* * Attach a member function to be called by the Ticker, specifying the interval in seconds
You can’t perform that action at this time.
0 commit comments