#ifndef BIN_Msg_Buffer_H #define BIN_Msg_Buffer_H #include "../global_include.h" #include struct Mode_Msg_Buffer { void push(const std::shared_ptr &msg) { std::lock_guard g(mtx); msg_list_cache.push_back(msg); } const std::vector> &get_all() { std::lock_guard 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 g(mtx); return msg_list_cache.size(); } std::atomic mode_s_msg_num{}; std::atomic mode_other_msg_num{}; Mode_Msg_Buffer() { msg_list_cache.reserve(8 * 10240); msg_list.reserve(8 * 10240); } protected: std::mutex mtx; std::vector> msg_list_cache; std::vector> msg_list; }; struct BIN_Msg_Buffer { void push(const std::string &msg); const std::vector &get_all(); std::atomic mode_s_msg_num{}; std::atomic mode_other_msg_num{}; BIN_Msg_Buffer(); Psc::JSON state_json(); protected: std::mutex mtx; std::vector msg_list_cache; std::vector msg_list; }; #endif