diff --git a/src/sema_manager.cc b/src/sema_manager.cc index dca5b03b..dbe57672 100644 --- a/src/sema_manager.cc +++ b/src/sema_manager.cc @@ -421,7 +421,8 @@ void *preambleMain(void *manager_) { auto *manager = static_cast(manager_); set_thread_name("preamble"); while (true) { - SemaManager::PreambleTask task = manager->preamble_tasks.dequeue(); + SemaManager::PreambleTask task = manager->preamble_tasks.dequeue( + g_config ? g_config->session.maxNum : 0); if (pipeline::g_quit.load(std::memory_order_relaxed)) break; diff --git a/src/threaded_queue.hh b/src/threaded_queue.hh index c2927640..d357b3d6 100644 --- a/src/threaded_queue.hh +++ b/src/threaded_queue.hh @@ -126,12 +126,14 @@ public: bool isEmpty() { return total_count_ == 0; } // Get the first element from the queue. Blocks until one is available. - T dequeue() { + T dequeue(int keep_only_latest = 0) { std::unique_lock lock(mutex_); waiter_->cv.wait(lock, [&]() { return !priority_.empty() || !queue_.empty(); }); auto execute = [&](std::deque *q) { + if (keep_only_latest > 0 && q->size() > keep_only_latest) + q->erase(q->begin(), q->end() - keep_only_latest); auto val = std::move(q->front()); q->pop_front(); --total_count_;