Skip to content
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

Simplify condition variable use #862

Closed
wants to merge 2 commits into from
Closed

Simplify condition variable use #862

wants to merge 2 commits into from

Conversation

heifner
Copy link
Member

@heifner heifner commented Mar 22, 2023

No description provided.

plugins/producer_plugin/producer_plugin.cpp Show resolved Hide resolved
void set_exit_criteria(uint32_t num_tasks, std::atomic<bool>* received_block, fc::time_point deadline) {
assert(num_tasks > 0 && num_waiting == 0);
void set_exit_criteria(uint32_t num_tasks, std::atomic<bool>* received_block, const fc::time_point& deadline) {
std::lock_guard<std::mutex> g( mtx );
Copy link
Contributor

Choose a reason for hiding this comment

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

std::lock_guard unnecessary as this is called from a single thread

Copy link
Member Author

Choose a reason for hiding this comment

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

True, but safer to have here in case this code is called from somewhere else. A uncontested lock is not very expensive.

@@ -473,34 +464,27 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
// - all threads would be idle
// - or the net_plugin received a block.
// - or we have reached the read_window_deadline
void set_exit_criteria(uint32_t num_tasks, std::atomic<bool>* received_block, fc::time_point deadline) {
assert(num_tasks > 0 && num_waiting == 0);
void set_exit_criteria(uint32_t num_tasks, std::atomic<bool>* received_block, const fc::time_point& deadline) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is better to pass deadline by value https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-in

plugins/producer_plugin/producer_plugin.cpp Show resolved Hide resolved
@heifner
Copy link
Member Author

heifner commented Mar 22, 2023

Comments are being included into #844

@heifner heifner closed this Mar 22, 2023
@heifner heifner deleted the gh-822-simplify branch March 22, 2023 12:38

++num_waiting;
cond.wait(g, [this]() {
return !queue.empty() || should_exit();
Copy link
Member

Choose a reason for hiding this comment

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

I like this. Earlier I was worried when switching from write window, we might end up waiting forever in some corner cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants