-
Notifications
You must be signed in to change notification settings - Fork 13.3k
scheduled functions: fixes #6137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3da6edb
scheduled functions: properly reset structure
d-a-v 2b5381b
fence against recursion, rename variables for clarity
d-a-v 087be17
update comments
d-a-v 626c5d7
Merge branch 'master' into fixschedule
d-a-v 79b77ee
Merge branch 'master' into fixschedule
d-a-v File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,38 @@ | |
|
||
#include <functional> | ||
|
||
#define SCHEDULED_FN_MAX_COUNT 32 | ||
// This API is stabilizing | ||
// Function signatures may change, internal queue will remain FIFO. | ||
// | ||
// * Add the given lambda to a fifo list of lambdas, which is run when | ||
// - `loop` function returns, | ||
// - or `yield` is called, | ||
// - or `run_scheduled_functions` is called. | ||
// | ||
// * Use lambdas to pass arguments to a function, or call a class/static | ||
// member function. | ||
// | ||
// * Please ensure variables or instances used from inside lambda will exist | ||
// when lambda is later called | ||
// | ||
// * There is no mechanism for cancelling scheduled functions. | ||
// | ||
// * `yield` can be called from inside lambdas | ||
// | ||
// * Returns false if the number of scheduled functions exceeds | ||
// SCHEDULED_FN_MAX_COUNT. | ||
|
||
// This API was not considered stable but is now stabilizing. | ||
// Function signatures may change, queue must stay FIFO. | ||
// You have been warned. | ||
#define SCHEDULED_FN_MAX_COUNT 32 | ||
|
||
// Run given function ONCE next time `loop` function returns, | ||
// or `yield` is called, | ||
// or `run_scheduled_functions` is called. | ||
// Use std::bind to pass arguments to a function, or call a class member function. | ||
// Note: there is no mechanism for cancelling scheduled functions. | ||
// Keep that in mind when binding functions to objects which may have short lifetime. | ||
// Returns false if the number of scheduled functions exceeds SCHEDULED_FN_MAX_COUNT. | ||
// * Run the lambda only once next time | ||
//bool schedule_function(std::function<void(void)>&& fn); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
bool schedule_function(const std::function<void(void)>& fn); | ||
|
||
// Run given function periodically about every <repeat_us> microseconds until it returns false. | ||
// Note that it may be more than <repeat_us> microseconds between calls if `yield` is not called | ||
// frequently, and therefore should not be used for timing critical operations. | ||
// * Run the lambda periodically about every <repeat_us> microseconds until | ||
// it returns false. | ||
// * Note that it may be more than <repeat_us> microseconds between calls if | ||
// `yield` is not called frequently, and therefore should not be used for | ||
// timing critical operations. | ||
//bool schedule_function_us(std::function<bool(void)>&& fn, uint32_t repeat_us); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
bool schedule_function_us(const std::function<bool(void)>& fn, uint32_t repeat_us); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.