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_
4242#if DEVICE_LPTICKER
4343volatile bool expired;
4444
45- void callback (void )
45+ void set_flag_true (void )
4646{
4747 expired = true ;
4848}
@@ -72,7 +72,7 @@ void rtc_sleep_test_support(bool deepsleep_mode)
7272
7373 rtc_write (start);
7474
75- timeout.attach (callback , DELAY_4S);
75+ timeout.attach (set_flag_true , DELAY_4S);
7676
7777 TEST_ASSERT (sleep_manager_can_deep_sleep_test_check () == deepsleep_mode);
7878
Original file line number Diff line number Diff line change 1717#ifndef MBED_TICKER_H
1818#define MBED_TICKER_H
1919
20+ #include < mstd_utility>
2021#include " drivers/TimerEvent.h"
2122#include " platform/Callback.h"
2223#include " platform/mbed_toolchain.h"
@@ -75,12 +76,17 @@ class Ticker : public TimerEvent, private NonCopyable<Ticker> {
7576
7677 /* * Attach a function to be called by the Ticker, specifying the interval in seconds
7778 *
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.
7883 * @param func pointer to the function to be called
7984 * @param t the time between calls in seconds
8085 */
81- void attach (Callback<void ()> func, float t)
86+ template <typename F>
87+ MBED_FORCEINLINE void attach (F &&func, float t)
8288 {
83- attach_us (func, t * 1000000 .0f );
89+ attach_us (std::forward<F>( func) , t * 1000000 .0f );
8490 }
8591
8692 /* * 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