Skip to content

Commit 24474c8

Browse files
committed
pass lambdas with const refs
1 parent 65603a3 commit 24474c8

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

cores/esp8266/Schedule.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static void recycle_fn_unsafe(scheduled_fn_t* fn)
5151
}
5252

5353
IRAM_ATTR // called from ISR
54-
bool schedule_function_us(mFuncT fn, uint32_t repeat_us)
54+
bool schedule_function_us(const mFuncT& fn, uint32_t repeat_us)
5555
{
5656
assert(repeat_us < decltype(scheduled_fn_t::callNow)::neverExpires); //~26800000us (26.8s)
5757

@@ -75,9 +75,9 @@ bool schedule_function_us(mFuncT fn, uint32_t repeat_us)
7575
}
7676

7777
IRAM_ATTR // called from ISR
78-
bool schedule_function(std::function<void(void)> fn)
78+
bool schedule_function(const std::function<void(void)>& fn)
7979
{
80-
return schedule_function_us([&fn](){ fn(); return false; }, 0);
80+
return schedule_function_us([fn](){ fn(); return false; }, 0);
8181
}
8282

8383
void run_scheduled_functions()

cores/esp8266/Schedule.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
// Note: there is no mechanism for cancelling scheduled functions.
1818
// Keep that in mind when binding functions to objects which may have short lifetime.
1919
// Returns false if the number of scheduled functions exceeds SCHEDULED_FN_MAX_COUNT.
20-
bool schedule_function(std::function<void(void)> fn);
20+
bool schedule_function(const std::function<void(void)>& fn);
2121

2222
// Run given function periodically about every <repeat_us> microseconds until it returns false.
2323
// Note that it may be more than <repeat_us> microseconds between calls if `yield` is not called
2424
// frequently, and therefore should not be used for timing critical operations.
25-
bool schedule_function_us(std::function<bool(void)> fn, uint32_t repeat_us);
25+
bool schedule_function_us(const std::function<bool(void)>& fn, uint32_t repeat_us);
2626

2727
// Run all scheduled functions.
2828
// Use this function if your are not using `loop`, or `loop` does not return

0 commit comments

Comments
 (0)