Files
ECAP_Server/module/Local_Server/server/Mode_Msg_Buffer.h
T
2026-06-16 11:18:22 +08:00

59 lines
1.3 KiB
C++

#ifndef BIN_Msg_Buffer_H
#define BIN_Msg_Buffer_H
#include "../global_include.h"
#include <stack>
struct Mode_Msg_Buffer {
void push(const std::shared_ptr<SSR::Msg>& msg) {
std::lock_guard<std::mutex> g(mtx);
msg_list_cache.push_back(msg);
}
const std::vector<std::shared_ptr<SSR::Msg>>& get_all() {
std::lock_guard<std::mutex> g(mtx);
std::swap(msg_list_cache, msg_list);
msg_list_cache.clear();
mode_s_msg_num = 0;
mode_other_msg_num = 0;
return msg_list;
}
size_t size() {
std::lock_guard<std::mutex> g(mtx);
return msg_list_cache.size();
}
std::atomic<size_t> mode_s_msg_num{};
std::atomic<size_t> mode_other_msg_num{};
Mode_Msg_Buffer() {
msg_list_cache.reserve(8 * 10240);
msg_list.reserve(8* 10240);
}
protected:
std::mutex mtx;
std::vector<std::shared_ptr<SSR::Msg>> msg_list_cache;
std::vector<std::shared_ptr<SSR::Msg>> msg_list;
};
struct BIN_Msg_Buffer {
void push(const std::string& msg);
const std::vector<std::string*>& get_all();
std::atomic<size_t> mode_s_msg_num{};
std::atomic<size_t> mode_other_msg_num{};
BIN_Msg_Buffer();
Psc::JSON state_json();
protected:
std::mutex mtx;
std::vector<std::string*> msg_list_cache;
std::vector<std::string*> msg_list;
};
#endif