优化消息队列内存泄漏问题
This commit is contained in:
parent
f2c74b2a7b
commit
e37e25567e
@ -19,6 +19,15 @@ namespace f8
|
|||||||
int curr_im_msgid = 10000;
|
int curr_im_msgid = 10000;
|
||||||
std::map<int, list_head> msg_handlers;
|
std::map<int, list_head> msg_handlers;
|
||||||
|
|
||||||
|
~MsgQueueImp()
|
||||||
|
{
|
||||||
|
for (auto& pair : msg_handlers) {
|
||||||
|
while (!list_empty(&pair.second)) {
|
||||||
|
MsgQueue::Instance()->RemoveCallBack(pair.second.next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ProcessMsg(int msgid, const a8::XParams& param)
|
void ProcessMsg(int msgid, const a8::XParams& param)
|
||||||
{
|
{
|
||||||
auto itr = msg_handlers.find(msgid);
|
auto itr = msg_handlers.find(msgid);
|
||||||
|
15
test/app.cc
15
test/app.cc
@ -21,12 +21,18 @@ struct IMMsgNode
|
|||||||
unsigned short msgid;
|
unsigned short msgid;
|
||||||
a8::XParams params;
|
a8::XParams params;
|
||||||
IMMsgNode* next = nullptr;
|
IMMsgNode* next = nullptr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* const PROJ_LOG_ROOT = "/data/logs/%s/logs";
|
const char* const PROJ_LOG_ROOT = "/data/logs/%s/logs";
|
||||||
const char* const PROJ_LOG_FILENAME = "log_$pid_%Y%m%d.log";
|
const char* const PROJ_LOG_FILENAME = "log_$pid_%Y%m%d.log";
|
||||||
|
|
||||||
|
static void StopApp(int signo)
|
||||||
|
{
|
||||||
|
printf("Stop App...\n");
|
||||||
|
App::Instance()->UnInit();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
void App::Init(int argc, char* argv[])
|
void App::Init(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
this->argc = argc;
|
this->argc = argc;
|
||||||
@ -52,6 +58,8 @@ void App::Init(int argc, char* argv[])
|
|||||||
f8::DBPool::Instance()->SetThreadNum(10);
|
f8::DBPool::Instance()->SetThreadNum(10);
|
||||||
|
|
||||||
a8::UdpLog::Instance()->Info("f8test starting instance_id:%d pid:%d", {instance_id, getpid()});
|
a8::UdpLog::Instance()->Info("f8test starting instance_id:%d pid:%d", {instance_id, getpid()});
|
||||||
|
|
||||||
|
signal(SIGINT, StopApp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::UnInit()
|
void App::UnInit()
|
||||||
@ -72,6 +80,11 @@ void App::UnInit()
|
|||||||
loop_mutex_ = nullptr;
|
loop_mutex_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void App::Terminate()
|
||||||
|
{
|
||||||
|
terminated = true;
|
||||||
|
}
|
||||||
|
|
||||||
int App::Run()
|
int App::Run()
|
||||||
{
|
{
|
||||||
if (terminated) {
|
if (terminated) {
|
||||||
|
@ -13,6 +13,7 @@ class App : public a8::Singleton<App>
|
|||||||
|
|
||||||
void Init(int argc, char* argv[]);
|
void Init(int argc, char* argv[]);
|
||||||
void UnInit();
|
void UnInit();
|
||||||
|
void Terminate();
|
||||||
|
|
||||||
int Run();
|
int Run();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user