// // Created by dongl on 23-7-1. // #include #include "Syn.h" #include "IMDataPacket.h" MSG::Syn::Syn(SafeQueue *mTimeLine) : m_timeLine(mTimeLine) {} MSG::Syn::Syn() : m_timeLine(new SafeQueue) { } MSG::Syn::~Syn() { delete m_timeLine; } void MSG::Syn::push(SynMsg* msg) { m_timeLine->push(msg); } void MSG::Syn::syn_push_lister_queue(const std::function& cb) { std::function fun = [&] { while (true) { while (!m_timeLine->value().empty()) { SynMsg* msg = m_timeLine->pull(); IMDataPacket imDataPacket(mp::MP_IM_NOTICE, msg->message_id, msg->time); // 执行回调 cb(imDataPacket.packet()); } } }; for (int i = 0; i < 2; ++i) { std::thread t(fun); printf("[thread id] %ld\n", t.get_id()); t.detach(); } }