From 5629efa910db86b1e13f75dd0c081b89d2f3e021 Mon Sep 17 00:00:00 2001 From: an-tao <20741618@qq.com> Date: Mon, 18 Feb 2019 23:27:30 +0800 Subject: [PATCH] Fix a bug in the DbClientLockFree class --- orm_lib/src/DbClientLockFree.cc | 10 +++++++--- orm_lib/src/DbClientLockFree.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/orm_lib/src/DbClientLockFree.cc b/orm_lib/src/DbClientLockFree.cc index 62edc30f..b3aae8e5 100644 --- a/orm_lib/src/DbClientLockFree.cc +++ b/orm_lib/src/DbClientLockFree.cc @@ -46,11 +46,15 @@ DbClientLockFree::DbClientLockFree(const std::string &connInfo, trantor::EventLo LOG_TRACE << "type=" << (int)type; if (type == ClientType::PostgreSQL) { - newConnection(); + _loop->runInLoop([this](){ + _connectionHolder=newConnection(); + }); } else if (type == ClientType::Mysql) { - newConnection(); + _loop->runInLoop([this](){ + _connectionHolder=newConnection(); + }); } else { @@ -207,7 +211,7 @@ DbConnectionPtr DbClientLockFree::newConnection() auto thisPtr = weakPtr.lock(); if (!thisPtr) return; - thisPtr->newConnection(); + thisPtr->_connectionHolder=thisPtr->newConnection(); }); }); connPtr->setOkCallback([weakPtr](const DbConnectionPtr &okConnPtr) { diff --git a/orm_lib/src/DbClientLockFree.h b/orm_lib/src/DbClientLockFree.h index 3dbac3c6..ea5db7c9 100644 --- a/orm_lib/src/DbClientLockFree.h +++ b/orm_lib/src/DbClientLockFree.h @@ -60,6 +60,7 @@ class DbClientLockFree : public DbClient, public std::enable_shared_from_this