diff options
-rw-r--r-- | src/modules/extra/m_mysql.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index 0e9a3a631..03dd99342 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -68,6 +68,7 @@ class Notifier; typedef std::map<std::string, SQLConnection*> ConnMap; bool giveup = false; +bool threadfinished = false; static Module* SQLModule = NULL; static Notifier* MessagePipe = NULL; int QueueFD = -1; @@ -725,16 +726,24 @@ class ModuleSQL : public Module pthread_attr_t attribs; pthread_attr_init(&attribs); - pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_DETACHED); + pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_JOINABLE); if (pthread_create(&this->Dispatcher, &attribs, DispatcherThread, (void *)this) != 0) { throw ModuleException("m_mysql: Failed to create dispatcher thread: " + std::string(strerror(errno))); } + pthread_attr_destroy(&attribs); if (!ServerInstance->Modules->PublishFeature("SQL", this)) { /* Tell worker thread to exit NOW */ + int rc; + void *status; giveup = true; + rc = pthread_join(Dispatcher, &status); + if (rc) + { + ServerInstance->Log(DEFAULT,"SQL: Error code from pthread_join() is " + rc); + } throw ModuleException("m_mysql: Unable to publish feature 'SQL'"); } @@ -745,7 +754,14 @@ class ModuleSQL : public Module virtual ~ModuleSQL() { + int rc; + void *status; giveup = true; + rc = pthread_join(Dispatcher, &status); + if (rc) + { + ServerInstance->Log(DEFAULT,"SQL: Error code from pthread_join() is " + rc); + } ClearAllConnections(); delete Conf; ServerInstance->Modules->UnpublishInterface("SQL", this); @@ -881,7 +897,7 @@ void* DispatcherThread(void* arg) usleep(1000); } - return NULL; + pthread_exit((void *) 0); } MODULE_INIT(ModuleSQL) |