]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/threadengines/threadengine_pthread.cpp
Numerous fixes for m_dccallow - only the first banfile tag mattered, improper behavio...
[user/henk/code/inspircd.git] / src / threadengines / threadengine_pthread.cpp
index 3921622ff9b0d275f81c7ad61a1a3fd12b8a6cd2..69b900c5b15f6032d951f6c8c5fe6c880f5a7187 100644 (file)
@@ -14,6 +14,7 @@
 #include "inspircd.h"
 #include "threadengines/threadengine_pthread.h"
 #include <pthread.h>
+#include <signal.h>
 
 pthread_mutex_t MyMutex = PTHREAD_MUTEX_INITIALIZER;
 
@@ -82,13 +83,18 @@ bool PThreadEngine::Mutex(bool enable)
        else
                pthread_mutex_unlock(&MyMutex);
 
-       printf("OK! Mutex %s\n", enable ? "on" : "off");
-
        return false;
 }
 
 void* PThreadEngine::Entry(void* parameter)
 {
+       /* Recommended by nenolod, signal safety on a per-thread basis */
+       sigset_t set;
+       sigemptyset(&set);
+       sigaddset(&set, SIGPIPE);
+       if(pthread_sigmask(SIG_BLOCK, &set, NULL))
+               signal(SIGPIPE, SIG_IGN);
+
        ThreadEngine * pt = (ThreadEngine*)parameter;
        pt->Run();
        return NULL;
@@ -107,3 +113,29 @@ void PThreadEngine::FreeThread(Thread* thread)
        }
 }
 
+MutexFactory::MutexFactory(InspIRCd* Instance) : ServerInstance(Instance)
+{
+}
+
+Mutex* MutexFactory::CreateMutex()
+{
+       return new PosixMutex(this->ServerInstance);
+}
+
+PosixMutex::PosixMutex(InspIRCd* Instance) : Mutex(Instance)
+{
+       pthread_mutex_init(&putex, NULL);
+}
+
+PosixMutex::~PosixMutex()
+{
+       pthread_mutex_destroy(&putex);
+}
+
+void PosixMutex::Enable(bool enable)
+{
+       if (enable)
+               pthread_mutex_lock(&putex);
+       else
+               pthread_mutex_unlock(&putex);
+}