From: Razvan Becheriu Date: Wed, 6 Nov 2019 16:30:36 +0000 (+0200) Subject: [#888,!573] use thread_local instead of ThreadResource X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba8060b97ea2edf1cc3dabc202a54f569c27b632;p=thirdparty%2Fkea.git [#888,!573] use thread_local instead of ThreadResource --- diff --git a/src/lib/pgsql/pgsql_connection.cc b/src/lib/pgsql/pgsql_connection.cc index 38318843f9..a2d7e6c56e 100644 --- a/src/lib/pgsql/pgsql_connection.cc +++ b/src/lib/pgsql/pgsql_connection.cc @@ -188,6 +188,18 @@ PgSqlTransaction::commit() { committed_ = true; } +PgSqlHolder& +PgSqlConnection::handle() const { + thread_local std::shared_ptr result(std::make_shared()); + if (connected_) { + result->openDatabase(*(const_cast(this))); + } + if (prepared_) { + result->prepareStatements(*(const_cast(this))); + } + return *result; +} + PgSqlConnection::~PgSqlConnection() { statements_.clear(); handle().clear(); diff --git a/src/lib/pgsql/pgsql_connection.h b/src/lib/pgsql/pgsql_connection.h index 54dd23cac1..c344f71d59 100644 --- a/src/lib/pgsql/pgsql_connection.h +++ b/src/lib/pgsql/pgsql_connection.h @@ -426,23 +426,11 @@ public: /// /// This field is public, because it is used heavily from PgSqlLeaseMgr /// and from PgSqlHostDataSource. - PgSqlHolder& handle() const { - auto result = handles_.resource(); - if (connected_) { - result->openDatabase(*(const_cast(this))); - } - if (prepared_) { - result->prepareStatements(*(const_cast(this))); - } - return *result; - } - + PgSqlHolder& handle() const; private: bool connected_; ///< Flag to indicate openDatabase has been called bool prepared_; ///< Flag to indicate prepareStatements has been called - - mutable isc::dhcp::ThreadResource handles_; }; } // namespace db