* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd: (C) 2002-2008 InspIRCd Development Team
+ * InspIRCd: (C) 2002-2009 InspIRCd Development Team
* See: http://www.inspircd.org/wiki/index.php/Credits
*
* This program is free but copyrighted software; see
#include "inspircd.h"
#include "threadengines/threadengine_pthread.h"
#include <pthread.h>
+#include <signal.h>
pthread_mutex_t MyMutex = PTHREAD_MUTEX_INITIALIZER;
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;
}
}
+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);
+}