@@ -27,14 +27,34 @@ using namespace com::centreon::exceptions;
2727using namespace com ::centreon::broker;
2828using namespace com ::centreon::broker::database;
2929
30+ mysql_manager* mysql_manager::_instance{nullptr };
31+
3032/* *
3133 * @brief The function to use to call the unique instance of mysql_manager.
3234 *
3335 * @return A reference to the mysql_manager object.
3436 */
3537mysql_manager& mysql_manager::instance () {
36- static mysql_manager _singleton;
37- return _singleton;
38+ assert (_instance);
39+ return *_instance;
40+ }
41+
42+ /* *
43+ * @brief Load the instance of mysql_manager
44+ */
45+ void mysql_manager::load () {
46+ if (!_instance)
47+ _instance = new mysql_manager ();
48+ }
49+
50+ /* *
51+ * @brief Unload the instance of mysql_manager
52+ */
53+ void mysql_manager::unload () {
54+ if (_instance) {
55+ delete _instance;
56+ _instance = nullptr ;
57+ }
3858}
3959
4060/* *
@@ -87,7 +107,7 @@ std::vector<std::shared_ptr<mysql_connection>> mysql_manager::get_connections(
87107 {
88108 uint32_t current_connection{0 };
89109 std::lock_guard<std::mutex> lock (_cfg_mutex);
90- for (std::shared_ptr<mysql_connection> c : _connection) {
110+ for (auto c : _connection) {
91111 // Is this thread matching what the configuration needs?
92112 if (c->match_config (db_cfg) && !c->is_finished () &&
93113 !c->is_finish_asked () && !c->is_in_error ()) {
@@ -123,7 +143,7 @@ void mysql_manager::clear() {
123143 conn->finish ();
124144 } catch (const std::exception& e) {
125145 log_v2::sql ()->info (" mysql_manager: Unable to stop a connection: {}" ,
126- e.what ());
146+ e.what ());
127147 }
128148 }
129149 log_v2::sql ()->debug (" mysql_manager: clear finished" );
0 commit comments