1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-07 06:01:35 +03:00

Wakeup delayed scheduling (#6485)

* Fix for scheduling recurrent functions while inside scheduled function

* Check that fn are valid. Invoking invalid functions throws otherwise.

* Added wakeup token to scheduler. Toggling the token value breaks a scheduled function

out from a delayed execution and makes it run on the next scheduler iteration.

* Timer reset reliability fix.

* Shrink interrupts-locked regions.

Add check for periodic yield to scheduled functions run-loop.

* Ordered, more predictable, scheduling. Before, it had different ordering compared to

FastScheduler as well as sequential calls from loop().

* Optional, for the paranoid: revert changes to (non-recurrent) schedule_function() / run_scheduled_functions().

* Comment

* Adapt one-line ifs to general style in same source file.

* Fix wakeupToken handling - don't respond to toggle, but to different value

vs. that at registering function with scheduler.

* Reword comment.

* Putting aside std::atomic concerns, use a callback for scheduler alarming.

In the future, async future's .then() might take advantage of this direction.

* Drop atomic include, align function type syntax.

* Reduce flash use.

* Prefer const ref over call by value plus std::move().
This commit is contained in:
Dirk O. Kaar
2019-10-28 12:55:00 +01:00
committed by Develo
parent e4c6a7a73a
commit 6e51ef0cc8
2 changed files with 61 additions and 26 deletions

View File

@ -10,7 +10,7 @@
// in user stack (called CONT stack) without the common restrictions from
// system context. Details are below.
// The purpose of recurrent scheduled function is to independantly execute
// The purpose of recurrent scheduled function is to independently execute
// user code in CONT stack on a regular basis.
// It has been introduced with ethernet service in mind, it can also be used
// for all libraries in the need of a regular `libdaemon_handlestuff()`.
@ -58,14 +58,14 @@ void run_scheduled_functions();
// functions. However a user function returning false will cancel itself.
// * Long running operations or yield() or delay() are not allowed in the
// recurrent function.
// * A recurrent function currently must not schedule another recurrent
// functions.
bool schedule_recurrent_function_us (const std::function<bool(void)>& fn, uint32_t repeat_us);
// * If alarm is used, anytime during scheduling when it returns true,
// any remaining delay from repeat_us is disregarded, and fn is executed.
bool schedule_recurrent_function_us(const std::function<bool(void)>& fn,
uint32_t repeat_us, const std::function<bool(void)>& alarm = nullptr);
// Test recurrence and run recurrent scheduled functions.
// (internally called at every `yield()` and `loop()`)
void run_scheduled_recurrent_functions ();
void run_scheduled_recurrent_functions();
#endif // ESP_SCHEDULE_H