summaryrefslogtreecommitdiff
path: root/src/threadengines/threadengine_pthread.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-02-10 14:32:02 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-02-10 14:32:02 +0000
commit9dbd7d10ac81c6445c58f4abb4f0eff240a8f9d2 (patch)
tree641c1af6e75faf5c55b60b99c6e070c7d0b26d7f /src/threadengines/threadengine_pthread.cpp
parent59643d29385fd4fbfed7a5720e90e2c9ffd1fd21 (diff)
Add threading engine stuff. Docs to follow, untested and not used anywhere yet
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8874 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/threadengines/threadengine_pthread.cpp')
-rw-r--r--src/threadengines/threadengine_pthread.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/threadengines/threadengine_pthread.cpp b/src/threadengines/threadengine_pthread.cpp
new file mode 100644
index 000000000..c35388cdf
--- /dev/null
+++ b/src/threadengines/threadengine_pthread.cpp
@@ -0,0 +1,78 @@
+/* +------------------------------------+
+ * | Inspire Internet Relay Chat Daemon |
+ * +------------------------------------+
+ *
+ * InspIRCd: (C) 2002-2008 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
+ * This program is free but copyrighted software; see
+ * the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
+/* $Core: libIRCDthreadengine */
+
+/********* DEFAULTS **********/
+/* $ExtraSources: socketengines/socketengine_pthread.cpp */
+/* $ExtraObjects: socketengine_pthread.o */
+
+/* $If: USE_WIN32 */
+/* $ExtraSources: socketengines/socketengine_win32.cpp */
+/* $ExtraObjects: socketengine_win32.o */
+/* $EndIf */
+
+#include "inspircd.h"
+#include "threadengines/threadengine_pthread.h"
+#include <pthread.h>
+
+pthread_mutex_t MyMutex = PTHREAD_MUTEX_INITIALIZER;
+
+PThreadEngine::PThreadEngine(InspIRCd* Instance) : ThreadEngine(Instance)
+{
+}
+
+void PThreadEngine::Create(Thread* thread_to_init)
+{
+ pthread_attr_t attribs;
+ pthread_attr_init(&attribs);
+ if (pthread_create(&this->MyPThread,
+ &attribs,
+ PThreadEngine::Entry,
+ (void*)this) != 0)
+ {
+ throw CoreException("Unable to create new PThreadEngine: " + std::string(strerror(errno)));
+ }
+ NewThread = thread_to_init;
+}
+
+PThreadEngine::~PThreadEngine()
+{
+ //pthread_kill(this->MyPThread, SIGKILL);
+}
+
+void PThreadEngine::Run()
+{
+ /* This is a factory function that will create a class of type 'Thread'. The class of type Thread just
+ * takes an InspIRCd* pointer and a ThreadEngine* pointer in its ctor (so it can easily use the Mutex
+ * methods etc) and runs asyncronously of the ircd. */
+ NewThread->Run();
+}
+
+bool PThreadEngine::Mutex(bool enable)
+{
+ if (enable)
+ pthread_mutex_lock(&MyMutex);
+ else
+ pthread_mutex_unlock(&MyMutex);
+
+ return false;
+}
+
+void* PThreadEngine::Entry(void* parameter)
+{
+ ThreadEngine * pt = (ThreadEngine*)parameter;
+ pt->Run();
+ return NULL;
+}
+