Skip to content

Commit

Permalink
Notify condition_variable under the lock.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed Mar 21, 2023
1 parent 517f1cb commit a4582b5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,13 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
void push_back(ro_trx_t&& trx) {
std::unique_lock<std::mutex> g( mtx );
queue.push_back(std::move(trx));
notify_waiting(g, false);
notify_waiting(false);
}

void push_front(ro_trx_t&& trx) {
std::unique_lock<std::mutex> g( mtx );
queue.push_front(std::move(trx));
notify_waiting(g, false);
notify_waiting(false);
}

bool empty() const {
Expand All @@ -445,14 +445,14 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
std::unique_lock<std::mutex> g( mtx );

if (should_exit()) {
notify_waiting(g, true);
notify_waiting(true);
return false;
}

if (queue.empty()) {
if (num_waiting + 1 == max_waiting) {
exiting_read_window = true;
notify_waiting(g, true);
notify_waiting(true);
return false;
}

Expand Down Expand Up @@ -482,9 +482,8 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
}

private:
void notify_waiting(std::unique_lock<std::mutex>& g, bool all) {
void notify_waiting(bool all) {
if (num_waiting) {
g.unlock();
all ? cond.notify_all() : cond.notify_one();
}
}
Expand Down

0 comments on commit a4582b5

Please sign in to comment.