#include "log_queue.h" #include log_queue::log_queue(): _working(true), _worker(&log_queue::worker_func, this) { } log_queue::~log_queue() { std::unique_lock lock(_mutex); _queue.push([]{}); _working = false; _cond.notify_one(); lock.unlock(); _worker.join(); } void log_queue::worker_func() { while(true) { std::unique_lock lock(_mutex); _cond.wait(lock, [this] { return !_queue.empty(); }); std::function func = _queue.front(); _queue.pop(); if(_queue.empty() && !_working) return; lock.unlock(); func(); } } void log_queue::add_log(const std::function& logFunc) { std::lock_guard lock(_mutex); _queue.push(logFunc); _cond.notify_one(); }