2023-07-04 14:10:13 +08:00

44 lines
936 B
C++

//
// Created by dongl on 23-7-1.
//
#include <thread>
#include "Syn.h"
#include "IMDataPacket.h"
MSG::Syn::Syn(SafeQueue<SynMsg *> *mTimeLine) : m_timeLine(mTimeLine) {}
MSG::Syn::Syn() : m_timeLine(new SafeQueue<SynMsg* >) {
}
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<void(std::string&& packet)>& cb) {
std::function<void()> 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();
}
}