summaryrefslogtreecommitdiff
path: root/src/modules/extra
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-09-04 21:23:01 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-09-04 21:23:01 +0000
commit7ebfd3aa68baa1cd3611e8863bdfdd1c88b830a2 (patch)
tree31b7d1c2078745fc8abc52e11232de3eac46f7ef /src/modules/extra
parenta8fa3da65e9befa1105f616ceea16c78d605b396 (diff)
Thread is now a Thread derived class, now need to convert the mutexes. With the new Mutex class, should be pretty easy
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10387 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/extra')
-rw-r--r--src/modules/extra/m_mysql.cpp67
1 files changed, 29 insertions, 38 deletions
diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp
index 4f2f90467..121566d9d 100644
--- a/src/modules/extra/m_mysql.cpp
+++ b/src/modules/extra/m_mysql.cpp
@@ -624,7 +624,18 @@ void NotifyMainThread(SQLConnection* connection_with_new_result)
send(QueueFD, &id, 1, 0);
}
-void* DispatcherThread(void* arg);
+class ModuleSQL;
+
+class DispatcherThread : public Thread
+{
+ private:
+ ModuleSQL* Parent;
+ InspIRCd* ServerInstance;
+ public:
+ DispatcherThread(InspIRCd* Instance, ModuleSQL* CreatorModule) : Thread(), Parent(CreatorModule), ServerInstance(Instance) { }
+ ~DispatcherThread() { }
+ virtual void Run();
+};
/** Used by m_mysql to notify one thread when the other has a result
*/
@@ -711,9 +722,9 @@ class ModuleSQL : public Module
ConfigReader *Conf;
InspIRCd* PublicServerInstance;
- pthread_t Dispatcher;
int currid;
bool rehashing;
+ DispatcherThread* Dispatcher;
ModuleSQL(InspIRCd* Me)
: Module::Module(Me), rehashing(false)
@@ -727,26 +738,15 @@ class ModuleSQL : public Module
MessagePipe = new Notifier(ServerInstance);
- pthread_attr_t attribs;
- pthread_attr_init(&attribs);
- 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);
+ Dispatcher = new DispatcherThread(ServerInstance, this);
+ ServerInstance->Threads->Create(Dispatcher);
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->Logs->Log("m_mysql",DEFAULT,"SQL: Error code from pthread_join() is %d", rc);
- }
+ /* Tell worker thread to exit NOW,
+ * Automatically joins */
+ delete Dispatcher;
+
throw ModuleException("m_mysql: Unable to publish feature 'SQL'");
}
@@ -757,14 +757,7 @@ class ModuleSQL : public Module
virtual ~ModuleSQL()
{
- int rc;
- void *status;
- giveup = true;
- rc = pthread_join(Dispatcher, &status);
- if (rc)
- {
- ServerInstance->Logs->Log("m_mysql",DEFAULT,"SQL: Error code from pthread_join() is %d", rc);
- }
+ delete Dispatcher;
ClearAllConnections();
delete Conf;
ServerInstance->Modules->UnpublishInterface("SQL", this);
@@ -826,17 +819,16 @@ class ModuleSQL : public Module
};
-void* DispatcherThread(void* arg)
+void DispatcherThread::Run(void)
{
- ModuleSQL* thismodule = (ModuleSQL*)arg;
- LoadDatabases(thismodule->Conf, thismodule->PublicServerInstance);
+ LoadDatabases(Parent->Conf, Parent->PublicServerInstance);
/* Connect back to the Notifier */
if ((QueueFD = socket(AF_FAMILY, SOCK_STREAM, 0)) == -1)
{
/* crap, we're out of sockets... */
- return NULL;
+ return;
}
insp_sockaddr addr;
@@ -856,17 +848,17 @@ void* DispatcherThread(void* arg)
if (connect(QueueFD, (sockaddr*)&addr,sizeof(addr)) == -1)
{
/* wtf, we cant connect to it, but we just created it! */
- return NULL;
+ return;
}
- while (!giveup)
+ while (this->GetExitFlag() == false)
{
- if (thismodule->rehashing)
+ if (Parent->rehashing)
{
/* XXX: Lock */
pthread_mutex_lock(&queue_mutex);
- thismodule->rehashing = false;
- LoadDatabases(thismodule->Conf, thismodule->PublicServerInstance);
+ Parent->rehashing = false;
+ LoadDatabases(Parent->Conf, Parent->PublicServerInstance);
pthread_mutex_unlock(&queue_mutex);
/* XXX: Unlock */
}
@@ -899,8 +891,7 @@ void* DispatcherThread(void* arg)
usleep(1000);
}
-
- pthread_exit((void *) 0);
}
MODULE_INIT(ModuleSQL)
+