]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#887,!572] use thread_local instead of ThreadResource 887-create-mysql-connection-thread-handle
authorRazvan Becheriu <razvan@isc.org>
Wed, 6 Nov 2019 16:21:49 +0000 (18:21 +0200)
committerRazvan Becheriu <razvan@isc.org>
Wed, 6 Nov 2019 16:21:49 +0000 (18:21 +0200)
src/lib/mysql/mysql_connection.cc
src/lib/mysql/mysql_connection.h

index 84127b195df24c1471e098454b05a240375c8855..a40aafa75a836728d15acd91cb8a7601227fd4ec 100644 (file)
@@ -128,9 +128,19 @@ MySqlTransaction::commit() {
     committed_ = true;
 }
 
+MySqlHolder&
+MySqlConnection::handle() const {
+    thread_local std::shared_ptr<MySqlHolder> result(std::make_shared<MySqlHolder>());
+    if (connected_) {
+        result->openDatabase(*(const_cast<MySqlConnection*>(this)));
+    }
+    if (prepared_) {
+        result->prepareStatements(*(const_cast<MySqlConnection*>(this)));
+    }
+    return *result;
+}
 
 // Open the database using the parameters passed to the constructor.
-
 void
 MySqlConnection::openDatabase() {
 
index 1c0d6d6b524847c99200228b793b4e4ef14066d1..be0815c71bd58ae1dcea8113159f5104aac9579f 100644 (file)
@@ -640,23 +640,11 @@ public:
     ///
     /// This field is public, because it is used heavily from MySqlConnection
     /// and from MySqlHostDataSource.
-    MySqlHolder& handle() const {
-        auto result = handles_.resource();
-        if (connected_) {
-            result->openDatabase(*(const_cast<MySqlConnection*>(this)));
-        }
-        if (prepared_) {
-            result->prepareStatements(*(const_cast<MySqlConnection*>(this)));
-        }
-        return *result;
-    }
-
+    MySqlHolder& 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<MySqlHolder> handles_;
 };
 
 }  // namespace db