use std::queue for queues

This commit is contained in:
Syping 2024-01-30 04:22:48 +01:00
parent f871441b78
commit 3800da9b00
4 changed files with 8 additions and 6 deletions

View file

@ -34,7 +34,7 @@ inline bot::translated_message make_translated_message(const bot::message &messa
void bot::message_queue::add(const bot::message &message)
{
m_mutex.lock();
m_queue.push_back(message);
m_queue.push(message);
m_mutex.unlock();
}
@ -45,7 +45,7 @@ void bot::message_queue::run(bot::settings::settings *settings, bot::submit_queu
m_mutex.lock();
if (!m_queue.empty()) {
const bot::message message = m_queue.front();
m_queue.erase(m_queue.begin());
m_queue.pop();
m_mutex.unlock();
std::unique_ptr<bot::translate::translator> translator = settings->get_translator();

View file

@ -21,6 +21,7 @@
#include <dpp/dpp.h>
#include <mutex>
#include <string>
#include <queue>
#include <vector>
#include "settings.h"
#include "submit_queue.h"
@ -44,7 +45,7 @@ namespace bot {
private:
bool m_running;
std::mutex m_mutex;
std::vector<bot::message> m_queue;
std::queue<bot::message> m_queue;
};
}

View file

@ -24,7 +24,7 @@ using namespace std::chrono_literals;
void bot::submit_queue::add(const bot::translated_message &message)
{
m_mutex.lock();
m_queue.push_back(message);
m_queue.push(message);
m_mutex.unlock();
}
@ -35,7 +35,7 @@ void bot::submit_queue::run(dpp::cluster *bot)
m_mutex.lock();
if (!m_queue.empty()) {
const bot::translated_message message = m_queue.front();
m_queue.erase(m_queue.begin());
m_queue.pop();
m_mutex.unlock();
webhook_push::run(message, bot);

View file

@ -21,6 +21,7 @@
#include <dpp/dpp.h>
#include <mutex>
#include <string>
#include <queue>
#include <vector>
namespace bot {
@ -40,7 +41,7 @@ namespace bot {
private:
bool m_running;
std::mutex m_mutex;
std::vector<bot::translated_message> m_queue;
std::queue<bot::translated_message> m_queue;
};
}