Skip to content

Commit

Permalink
Small clean of enqueue_if_have_room in mpmc_blocking_q.h
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Jan 18, 2025
1 parent 214e26e commit af8440b
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions include/spdlog/details/mpmc_blocking_q.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,15 @@ class mpmc_blocking_queue {
}

void enqueue_if_have_room(T &&item) {
bool pushed = false;
{
std::unique_lock<std::mutex> lock(queue_mutex_);
if (!q_.full()) {
q_.push_back(std::move(item));
pushed = true;
std::unique_lock lock(queue_mutex_);
if (q_.full()) {
++discard_counter_;
return;
}
q_.push_back(std::move(item));
}

if (pushed) {
push_cv_.notify_one();
} else {
++discard_counter_;
}
push_cv_.notify_one();
}

// dequeue with a timeout.
Expand Down

0 comments on commit af8440b

Please sign in to comment.