@@ -27,7 +27,7 @@ struct recurrent_fn_t
27
27
recurrent_fn_t (esp8266::polledTimeout::periodicFastUs interval): callNow(interval) { }
28
28
};
29
29
30
- static recurrent_fn_t * rFirst = nullptr ; // fifo not needed
30
+ static recurrent_fn_t rFirst ( 0 ) ; // fifo not needed
31
31
32
32
// Returns a pointer to an unused sched_fn_t,
33
33
// or if none are available allocates a new one,
@@ -92,10 +92,8 @@ bool schedule_recurrent_function_us (const std::function<bool(void)>& fn, uint32
92
92
93
93
item->mFunc = fn;
94
94
95
- if (rFirst)
96
- item->mNext = rFirst;
97
-
98
- rFirst = item;
95
+ item->mNext = rFirst.mNext ;
96
+ rFirst.mNext = item;
99
97
100
98
return true ;
101
99
}
@@ -136,7 +134,8 @@ void run_scheduled_recurrent_functions ()
136
134
// its purpose is that it is never called from an interrupt
137
135
// (always on cont stack).
138
136
139
- if (!rFirst)
137
+ recurrent_fn_t * current = rFirst.mNext ;
138
+ if (!current)
140
139
return ;
141
140
142
141
static bool fence = false ;
@@ -152,10 +151,9 @@ void run_scheduled_recurrent_functions ()
152
151
fence = true ;
153
152
}
154
153
155
- recurrent_fn_t * prev = nullptr ;
156
- recurrent_fn_t * current = rFirst;
154
+ recurrent_fn_t * prev = &rFirst;
157
155
158
- while (current)
156
+ do
159
157
{
160
158
if (current->callNow && !current->mFunc ())
161
159
{
@@ -164,16 +162,11 @@ void run_scheduled_recurrent_functions ()
164
162
165
163
auto to_ditch = current;
166
164
167
- if (prev)
168
- {
169
- current = current->mNext ;
170
- prev->mNext = current;
171
- }
172
- else
173
- {
174
- rFirst = rFirst->mNext ;
175
- current = rFirst;
176
- }
165
+ // current function recursively scheduled something
166
+ if (prev->mNext != current) prev = prev->mNext ;
167
+
168
+ current = current->mNext ;
169
+ prev->mNext = current;
177
170
178
171
delete (to_ditch);
179
172
}
@@ -183,6 +176,7 @@ void run_scheduled_recurrent_functions ()
183
176
current = current->mNext ;
184
177
}
185
178
}
179
+ while (current);
186
180
187
181
fence = false ;
188
182
}
0 commit comments