Fix deadlock issue with mingw in async logger
This commit is contained in:
parent
2880eceeae
commit
8bfec30d48
@ -33,36 +33,30 @@ public:
|
|||||||
// try to enqueue and block if no room left
|
// try to enqueue and block if no room left
|
||||||
void enqueue(T &&item)
|
void enqueue(T &&item)
|
||||||
{
|
{
|
||||||
{
|
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
pop_cv_.wait(lock, [this] { return !this->q_.full(); });
|
||||||
pop_cv_.wait(lock, [this] { return !this->q_.full(); });
|
q_.push_back(std::move(item));
|
||||||
q_.push_back(std::move(item));
|
push_cv_.notify_one();
|
||||||
}
|
|
||||||
push_cv_.notify_one();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// enqueue immediately. overrun oldest message in the queue if no room left.
|
// enqueue immediately. overrun oldest message in the queue if no room left.
|
||||||
void enqueue_nowait(T &&item)
|
void enqueue_nowait(T &&item)
|
||||||
{
|
{
|
||||||
{
|
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
q_.push_back(std::move(item));
|
||||||
q_.push_back(std::move(item));
|
push_cv_.notify_one();
|
||||||
}
|
|
||||||
push_cv_.notify_one();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to dequeue item. if no item found. wait upto timeout and try again
|
// try to dequeue item. if no item found. wait upto timeout and try again
|
||||||
// Return true, if succeeded dequeue item, false otherwise
|
// Return true, if succeeded dequeue item, false otherwise
|
||||||
bool dequeue_for(T &popped_item, std::chrono::milliseconds wait_duration)
|
bool dequeue_for(T &popped_item, std::chrono::milliseconds wait_duration)
|
||||||
{
|
{
|
||||||
{
|
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
if (!push_cv_.wait_for(lock, wait_duration, [this] { return !this->q_.empty(); }))
|
||||||
if (!push_cv_.wait_for(lock, wait_duration, [this] { return !this->q_.empty(); }))
|
{
|
||||||
{
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
q_.pop_front(popped_item);
|
||||||
q_.pop_front(popped_item);
|
|
||||||
}
|
|
||||||
pop_cv_.notify_one();
|
pop_cv_.notify_one();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user