Skip to content

Proposed changes from review #6

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

Conversation

dok-net
Copy link

@dok-net dok-net commented May 22, 2019

It's too much to put into words, and giving you source code that compiles should be so much nicer.
What's in it:

  • initialize to nullptr instead of 0, explicitly initialize mNext in places.
  • eliminate sLastUnused, that's completely redundant.
  • "<" is often safer than "!=" : sCount < SCHEDULED_FN_MAX_COUNT
  • place recycle_fn() call into "critical section", obviates additional lock.
  • move and copy semantics for schedule_function*() (move is commented in header, relies on YET ANOTHER separate PR The use of bind in Ticker.h is prone to type inference failure esp8266/Arduino#6129 )
  • please don't mention formatting, it's. beyond. my. control.
  • in run_scheduled_functions, when there are rescheduled items before AND after an item that's done, the preceding mNext should be made to point to the next following item, instead of left dangling.

d-a-v added a commit that referenced this pull request May 23, 2019
d-a-v added a commit that referenced this pull request May 23, 2019
@d-a-v
Copy link
Owner

d-a-v commented May 23, 2019

Thanks!
especially for the last point.

please don't mention formatting, it's. beyond. my. control.

About formatting, I had to change my habits for several reasons:

  • I was asked to
  • Adapt to the repository guidelines
  • Minimize the diff so review is easy (in all repos I had to PR on)

I'm very sad I couldn't make the Allman PR smoothly indroduced into the core. I'm still thinking of how to achieve it smoothly, maybe file by file if I can make a script that list all modified files in unmerged-yet PRs.

}
// if no unused items, and count not too high, allocate a new one
else if (sCount < SCHEDULED_FN_MAX_COUNT)
{
result = new scheduled_fn_t;
++sCount;
}
result->mNext = nullptr;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise null pointer access if SCHEDULED_FN_MAX_COUNT is exhausted

return result;
}

static void recycle_fn_unsafe(scheduled_fn_t* fn)
{
fn->mFunc = mFuncT();
fn->mFunc = nullptr; // special overload in c++ std lib
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably for performance, so use this style instead of move assignment

@@ -17,11 +17,13 @@
// 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.
//bool schedule_function(std::function<void(void)>&& fn);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending PR esp8266#6129

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.
//bool schedule_function_us(std::function<bool(void)>&& fn, uint32_t repeat_us);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending PR esp8266#6129

@d-a-v d-a-v merged commit 40dbcc1 into d-a-v:recurrentscheduledfunctions May 23, 2019
@dok-net dok-net deleted the d-a-v/recurrentscheduledfunctions branch May 24, 2019 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants