Skip to content

Commit bfb084a

Browse files
committed
Use Delegate instead of std::function
1 parent 8e75ef9 commit bfb084a

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

cores/esp8266/Schedule.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "interrupts.h"
2424
#include "coredecls.h"
2525

26-
typedef std::function<void(void)> mSchedFuncT;
26+
typedef Delegate<> mSchedFuncT;
2727
struct scheduled_fn_t
2828
{
2929
scheduled_fn_t* mNext = nullptr;
@@ -35,13 +35,13 @@ static scheduled_fn_t* sLast = nullptr;
3535
static scheduled_fn_t* sUnused = nullptr;
3636
static int sCount = 0;
3737

38-
typedef std::function<bool(void)> mRecFuncT;
38+
typedef Delegate<bool> mRecFuncT;
3939
struct recurrent_fn_t
4040
{
4141
recurrent_fn_t* mNext = nullptr;
4242
mRecFuncT mFunc;
4343
esp8266::polledTimeout::periodicFastUs callNow;
44-
std::function<bool(void)> alarm = nullptr;
44+
Delegate<bool> alarm = nullptr;
4545
recurrent_fn_t(esp8266::polledTimeout::periodicFastUs interval) : callNow(interval) { }
4646
};
4747

@@ -73,13 +73,13 @@ static scheduled_fn_t* get_fn_unsafe()
7373

7474
static void recycle_fn_unsafe(scheduled_fn_t* fn)
7575
{
76-
fn->mFunc = nullptr; // special overload in c++ std lib
76+
fn->mFunc = nullptr; // special overload in Delegate
7777
fn->mNext = sUnused;
7878
sUnused = fn;
7979
}
8080

8181
IRAM_ATTR // (not only) called from ISR
82-
bool schedule_function(const std::function<void(void)>& fn)
82+
bool schedule_function(const Delegate<>& fn)
8383
{
8484
if (!fn)
8585
return false;
@@ -103,8 +103,8 @@ bool schedule_function(const std::function<void(void)>& fn)
103103
}
104104

105105
IRAM_ATTR // (not only) called from ISR
106-
bool schedule_recurrent_function_us(const std::function<bool(void)>& fn,
107-
uint32_t repeat_us, const std::function<bool(void)>& alarm)
106+
bool schedule_recurrent_function_us(const Delegate<bool>& fn,
107+
uint32_t repeat_us, const Delegate<bool>& alarm)
108108
{
109109
assert(repeat_us < decltype(recurrent_fn_t::callNow)::neverExpires); //~26800000us (26.8s)
110110

cores/esp8266/Schedule.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifndef ESP_SCHEDULE_H
2020
#define ESP_SCHEDULE_H
2121

22-
#include <functional>
22+
#include <Delegate.h>
2323
#include <stdint.h>
2424

2525
#define SCHEDULED_FN_MAX_COUNT 32
@@ -55,7 +55,7 @@
5555
// * Run the lambda only once next time.
5656
// * A scheduled function can schedule a function.
5757

58-
bool schedule_function (const std::function<void(void)>& fn);
58+
bool schedule_function (const Delegate<>& fn);
5959

6060
// Run all scheduled functions.
6161
// Use this function if your are not using `loop`,
@@ -80,8 +80,8 @@ void run_scheduled_functions();
8080
// * If alarm is used, anytime during scheduling when it returns true,
8181
// any remaining delay from repeat_us is disregarded, and fn is executed.
8282

83-
bool schedule_recurrent_function_us(const std::function<bool(void)>& fn,
84-
uint32_t repeat_us, const std::function<bool(void)>& alarm = nullptr);
83+
bool schedule_recurrent_function_us(const Delegate<bool>& fn,
84+
uint32_t repeat_us, const Delegate<bool>& alarm = nullptr);
8585

8686
// Test recurrence and run recurrent scheduled functions.
8787
// (internally called at every `yield()` and `loop()`)

0 commit comments

Comments
 (0)