修复dbpool内存泄漏问题
This commit is contained in:
parent
bb00288aaa
commit
3739692d07
@ -75,6 +75,33 @@ namespace f8
|
|||||||
work_thread_ = new std::thread(&DBThread::WorkThreadProc, this);
|
work_thread_ = new std::thread(&DBThread::WorkThreadProc, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UnInit()
|
||||||
|
{
|
||||||
|
terminated_ = true;
|
||||||
|
work_thread_->join();
|
||||||
|
delete work_thread_;
|
||||||
|
work_thread_ = nullptr;
|
||||||
|
|
||||||
|
if (last_query_) {
|
||||||
|
delete last_query_;
|
||||||
|
last_query_ = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (last_conn_) {
|
||||||
|
delete last_conn_;
|
||||||
|
last_conn_ = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete msg_mutex_;
|
||||||
|
msg_mutex_ = nullptr;
|
||||||
|
|
||||||
|
delete loop_cond_;
|
||||||
|
loop_cond_ = nullptr;
|
||||||
|
|
||||||
|
delete loop_mutex_;
|
||||||
|
loop_mutex_ = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void AddAsyncQuery(AsyncQueryNode* p)
|
void AddAsyncQuery(AsyncQueryNode* p)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lk(*loop_mutex_);
|
std::unique_lock<std::mutex> lk(*loop_mutex_);
|
||||||
@ -94,7 +121,7 @@ namespace f8
|
|||||||
|
|
||||||
void WorkThreadProc()
|
void WorkThreadProc()
|
||||||
{
|
{
|
||||||
while (true) {
|
while (!terminated_) {
|
||||||
CheckDB();
|
CheckDB();
|
||||||
ProcessMsg();
|
ProcessMsg();
|
||||||
WaitLoopCond();
|
WaitLoopCond();
|
||||||
@ -266,6 +293,7 @@ namespace f8
|
|||||||
int exec_async_query_msgid = 0;
|
int exec_async_query_msgid = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
volatile bool terminated_ = false;
|
||||||
std::mutex *loop_mutex_ = nullptr;
|
std::mutex *loop_mutex_ = nullptr;
|
||||||
std::condition_variable *loop_cond_ = nullptr;
|
std::condition_variable *loop_cond_ = nullptr;
|
||||||
|
|
||||||
@ -296,6 +324,14 @@ namespace f8
|
|||||||
exec_async_query_msgid = MsgQueue::Instance()->AllocIMMsgId();
|
exec_async_query_msgid = MsgQueue::Instance()->AllocIMMsgId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UnInit()
|
||||||
|
{
|
||||||
|
for (auto& db_thread : db_thread_pool) {
|
||||||
|
db_thread->UnInit();
|
||||||
|
delete db_thread;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SetThreadNum(int thread_num)
|
void SetThreadNum(int thread_num)
|
||||||
{
|
{
|
||||||
assert(thread_num > 0);
|
assert(thread_num > 0);
|
||||||
@ -424,6 +460,7 @@ namespace f8
|
|||||||
|
|
||||||
void DBPool::UnInit()
|
void DBPool::UnInit()
|
||||||
{
|
{
|
||||||
|
impl_->UnInit();
|
||||||
delete impl_;
|
delete impl_;
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user