@@ -9,11 +9,11 @@ typedef std::function<bool(void)> mFuncT;
9
9
10
10
struct scheduled_fn_t
11
11
{
12
- scheduled_fn_t * mNext ;
12
+ scheduled_fn_t * mNext = nullptr ;
13
13
mFuncT mFunc ;
14
14
esp8266::polledTimeout::periodicFastUs callNow;
15
15
16
- scheduled_fn_t (): callNow(esp8266::polledTimeout::periodicFastUs::alwaysExpired) { }
16
+ scheduled_fn_t () : callNow(esp8266::polledTimeout::periodicFastUs::alwaysExpired) { }
17
17
};
18
18
19
19
static scheduled_fn_t * sFirst = nullptr ;
@@ -32,26 +32,26 @@ static scheduled_fn_t* get_fn_unsafe()
32
32
{
33
33
result = sUnused ;
34
34
sUnused = sUnused ->mNext ;
35
+ result->mNext = nullptr ;
35
36
}
36
37
// if no unused items, and count not too high, allocate a new one
37
38
else if (sCount < SCHEDULED_FN_MAX_COUNT)
38
39
{
39
40
result = new scheduled_fn_t ;
40
41
++sCount ;
41
42
}
42
- result->mNext = nullptr ;
43
43
return result;
44
44
}
45
45
46
46
static void recycle_fn_unsafe (scheduled_fn_t * fn)
47
47
{
48
- fn->mFunc = mFuncT ();
48
+ fn->mFunc = nullptr ; // special overload in c++ std lib
49
49
fn->mNext = sUnused ;
50
50
sUnused = fn;
51
51
}
52
52
53
- IRAM_ATTR // called from ISR
54
- bool schedule_function_us (const mFuncT & fn, uint32_t repeat_us)
53
+ IRAM_ATTR // (not only) called from ISR
54
+ bool schedule_function_us (std::function< bool ( void )>& & fn, uint32_t repeat_us)
55
55
{
56
56
assert (repeat_us < decltype (scheduled_fn_t ::callNow)::neverExpires); // ~26800000us (26.8s)
57
57
@@ -74,10 +74,20 @@ bool schedule_function_us(const mFuncT& fn, uint32_t repeat_us)
74
74
return true ;
75
75
}
76
76
77
+ bool ICACHE_RAM_ATTR schedule_function_us (const std::function<bool (void )>& fn, uint32_t repeat_us)
78
+ {
79
+ return schedule_function_us (std::function<bool (void )>(fn), repeat_us);
80
+ }
81
+
77
82
IRAM_ATTR // called from ISR
78
- bool schedule_function (const std::function<void (void )>& fn)
83
+ bool schedule_function (std::function<void (void )>&& fn)
84
+ {
85
+ return schedule_function_us ([fn]() { fn (); return false ; }, 0 );
86
+ }
87
+
88
+ bool ICACHE_RAM_ATTR schedule_function (const std::function<void (void )>& fn)
79
89
{
80
- return schedule_function_us ([fn](){ fn (); return false ; }, 0 );
90
+ return schedule_function (std::function< void ( void )>(fn) );
81
91
}
82
92
83
93
void run_scheduled_functions ()
0 commit comments