diff options
-rw-r--r-- | include/threadengine.h | 28 | ||||
-rw-r--r-- | include/threadengines/threadengine_pthread.h | 6 | ||||
-rw-r--r-- | include/threadengines/threadengine_win32.h | 6 | ||||
-rw-r--r-- | src/configreader.cpp | 36 |
4 files changed, 45 insertions, 31 deletions
diff --git a/include/threadengine.h b/include/threadengine.h index d41ad98d3..a8b66ad98 100644 --- a/include/threadengine.h +++ b/include/threadengine.h @@ -40,10 +40,21 @@ class CoreExport ThreadEngine : public Extensible /** Creator instance */ InspIRCd* ServerInstance; + /** New Thread being created. */ Thread* NewThread; + /** Enable or disable system-wide mutex for threading. + * Remember that if you toggle the mutex you MUST UNSET + * IT LATER otherwise the program will DEADLOCK! + * It is recommended that you AVOID USE OF THIS METHOD + * and use your own Mutex class, this function is mainly + * reserved for use by the core and by the Thread engine + * itself. + * @param enable True to lock the mutex. + */ + virtual bool Mutex(bool enable) = 0; public: /** Constructor. @@ -55,16 +66,15 @@ class CoreExport ThreadEngine : public Extensible */ virtual ~ThreadEngine(); - /** Enable or disable system-wide mutex for threading. - * Remember that if you toggle the mutex you MUST UNSET - * IT LATER otherwise the program will DEADLOCK! - * It is recommended that you AVOID USE OF THIS METHOD - * and use your own Mutex class, this function is mainly - * reserved for use by the core and by the Thread engine - * itself. - * @param enable True to lock the mutex. + /** Lock the system wide mutex. See the documentation for + * ThreadEngine::Mutex(). + */ + void Lock() { this->Mutex(true); } + + /** Unlock the system wide mutex. See the documentation for + * ThreadEngine::Mutex() */ - virtual bool Mutex(bool enable) = 0; + void Unlock() { this->Mutex(false); } /** Run the newly created thread. */ diff --git a/include/threadengines/threadengine_pthread.h b/include/threadengines/threadengine_pthread.h index 76548c252..bd07f0ea9 100644 --- a/include/threadengines/threadengine_pthread.h +++ b/include/threadengines/threadengine_pthread.h @@ -23,14 +23,16 @@ class InspIRCd; class CoreExport PThreadEngine : public ThreadEngine { + private: + + bool Mutex(bool enable); + public: PThreadEngine(InspIRCd* Instance); virtual ~PThreadEngine(); - bool Mutex(bool enable); - void Run(); static void* Entry(void* parameter); diff --git a/include/threadengines/threadengine_win32.h b/include/threadengines/threadengine_win32.h index 9179d1fcf..1915ecc7b 100644 --- a/include/threadengines/threadengine_win32.h +++ b/include/threadengines/threadengine_win32.h @@ -22,14 +22,16 @@ class InspIRCd; class CoreExport Win32ThreadEngine : public ThreadEngine { + protected: + + bool Mutex(bool enable); + public: Win32ThreadEngine(InspIRCd* Instance); virtual ~Win32ThreadEngine(); - bool Mutex(bool enable); - void Run(); static DWORD WINAPI Entry(void* parameter); diff --git a/src/configreader.cpp b/src/configreader.cpp index 9ec8aa367..1e8e0a7e9 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -1019,7 +1019,7 @@ void ServerConfig::Read(bool bail, User* user) if (!Values[Index].validation_function(this, Values[Index].tag, Values[Index].value, vi)) throw CoreException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information."); - ServerInstance->Threads->Mutex(true); + ServerInstance->Threads->Lock(); switch (dt) { case DT_NOSPACES: @@ -1048,7 +1048,7 @@ void ServerConfig::Read(bool bail, User* user) ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val; if (*(vi.GetString()) && !ServerInstance->IsChannel(vi.GetString(), MAXBUF)) { - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); throw CoreException("The value of <"+std::string(Values[Index].tag)+":"+Values[Index].value+"> is not a valid channel name"); } vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1); @@ -1081,7 +1081,7 @@ void ServerConfig::Read(bool bail, User* user) } /* We're done with this now */ delete Values[Index].val; - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); } /* Read the multiple-tag items (class tags, connect tags, etc) @@ -1090,9 +1090,9 @@ void ServerConfig::Read(bool bail, User* user) */ for (int Index = 0; MultiValues[Index].tag; ++Index) { - ServerInstance->Threads->Mutex(true); + ServerInstance->Threads->Lock(); MultiValues[Index].init_function(this, MultiValues[Index].tag); - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); int number_of_tags = ConfValueEnum(newconfig, MultiValues[Index].tag); @@ -1107,7 +1107,7 @@ void ServerConfig::Read(bool bail, User* user) dt &= ~DT_ALLOW_NEWLINE; dt &= ~DT_ALLOW_WILD; - ServerInstance->Threads->Mutex(true); + ServerInstance->Threads->Lock(); /* We catch and rethrow any exception here just so we can free our mutex */ try @@ -1186,10 +1186,10 @@ void ServerConfig::Read(bool bail, User* user) } catch (CoreException &e) { - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); throw e; } - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); } MultiValues[Index].validation_function(this, MultiValues[Index].tag, (char**)MultiValues[Index].items, vl, MultiValues[Index].datatype); } @@ -1209,7 +1209,7 @@ void ServerConfig::Read(bool bail, User* user) return; } - ServerInstance->Threads->Mutex(true); + ServerInstance->Threads->Lock(); for (int i = 0; i < ConfValueEnum(newconfig, "type"); ++i) { char item[MAXBUF], classn[MAXBUF], classes[MAXBUF]; @@ -1248,7 +1248,7 @@ void ServerConfig::Read(bool bail, User* user) /* If we succeeded, set the ircd config to the new one */ this->config_data = newconfig; - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); // write once here, to try it out and make sure its ok ServerInstance->WritePID(this->PID); @@ -1269,7 +1269,7 @@ void ServerConfig::Read(bool bail, User* user) if (pl.size() && user) { - ServerInstance->Threads->Mutex(true); + ServerInstance->Threads->Lock(); user->WriteServ("NOTICE %s :*** Not all your client ports could be bound.", user->nick.c_str()); user->WriteServ("NOTICE %s :*** The following port(s) failed to bind:", user->nick.c_str()); int j = 1; @@ -1277,10 +1277,10 @@ void ServerConfig::Read(bool bail, User* user) { user->WriteServ("NOTICE %s :*** %d. Address: %s Reason: %s", user->nick.c_str(), j, i->first.empty() ? "<all>" : i->first.c_str(), i->second.c_str()); } - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); } - ServerInstance->Threads->Mutex(true); + ServerInstance->Threads->Lock(); if (!removed_modules.empty()) { for (std::vector<std::string>::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++) @@ -1325,16 +1325,16 @@ void ServerConfig::Read(bool bail, User* user) ServerInstance->Logs->Log("CONFIG", DEFAULT, "Successfully unloaded %lu of %lu modules and loaded %lu of %lu modules.",(unsigned long)rem,(unsigned long)removed_modules.size(),(unsigned long)add,(unsigned long)added_modules.size()); - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); } if (bail) { /** Note: This is safe, the method checks for user == NULL */ - ServerInstance->Threads->Mutex(true); + ServerInstance->Threads->Lock(); ServerInstance->Parser->SetupCommandTable(user); - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); } else { @@ -2363,8 +2363,8 @@ void ConfigReaderThread::Run() { /* TODO: TheUser may be invalid by the time we get here! Check its validity, or pass a UID would be better */ ServerInstance->Config->Read(do_bail, TheUser); - ServerInstance->Threads->Mutex(true); + ServerInstance->Threads->Lock(); this->SetExitFlag(); - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); } |