-
Notifications
You must be signed in to change notification settings - Fork 71
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
Conversation
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 ); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
Comments are being included into #844 |
|
||
++num_waiting; | ||
cond.wait(g, [this]() { | ||
return !queue.empty() || should_exit(); |
There was a problem hiding this comment.
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.
No description provided.