diff options
author | Razvan Becheriu <razvan@isc.org> | 2020-01-21 21:13:09 +0100 |
---|---|---|
committer | Razvan Becheriu <razvan@isc.org> | 2020-01-27 15:57:36 +0100 |
commit | 6619331f40f744e70f34245a36e02974623f7fa5 (patch) | |
tree | a415ea7bbe7ea7a7851b111c2688a2c11365feda /src/lib/mysql | |
parent | [#1073] minor changes (diff) | |
download | kea-6619331f40f744e70f34245a36e02974623f7fa5.tar.xz kea-6619331f40f744e70f34245a36e02974623f7fa5.zip |
[#1073] thread safe initialization of atexit function
Diffstat (limited to 'src/lib/mysql')
-rw-r--r-- | src/lib/mysql/mysql_connection.cc | 2 | ||||
-rw-r--r-- | src/lib/mysql/mysql_connection.h | 6 |
2 files changed, 1 insertions, 7 deletions
diff --git a/src/lib/mysql/mysql_connection.cc b/src/lib/mysql/mysql_connection.cc index 2e4020fa2d..ecf36d8824 100644 --- a/src/lib/mysql/mysql_connection.cc +++ b/src/lib/mysql/mysql_connection.cc @@ -23,7 +23,7 @@ using namespace std; namespace isc { namespace db { -bool MySqlHolder::atexit_ = false; +bool MySqlHolder::atexit_ = []{atexit([]{mysql_library_end();});return true;}; /// @todo: Migrate this default value to src/bin/dhcpX/simple_parserX.cc const int MYSQL_DEFAULT_CONNECTION_TIMEOUT = 5; // seconds diff --git a/src/lib/mysql/mysql_connection.h b/src/lib/mysql/mysql_connection.h index 9e540f99a5..bb091dc351 100644 --- a/src/lib/mysql/mysql_connection.h +++ b/src/lib/mysql/mysql_connection.h @@ -92,15 +92,10 @@ public: /// @brief Constructor /// - /// Push a call to mysql_library_end() at exit time. /// Initialize MySql and store the associated context object. /// /// @throw DbOpenError Unable to initialize MySql handle. MySqlHolder() : mysql_(mysql_init(NULL)) { - if (!atexit_) { - atexit([]{ mysql_library_end(); }); - atexit_ = true; - } if (mysql_ == NULL) { isc_throw(db::DbOpenError, "unable to initialize MySQL"); } @@ -113,7 +108,6 @@ public: if (mysql_ != NULL) { mysql_close(mysql_); } - // @note Moved the call to mysql_library_end() to atexit. } /// @brief Conversion Operator |