summaryrefslogtreecommitdiff
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
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
-rwxr-xr-xconfigure15
-rw-r--r--include/threadengine.h53
-rw-r--r--include/threadengines/threadengine_pthread.h45
-rw-r--r--include/threadengines/threadengine_win32.h0
-rw-r--r--src/threadengine.cpp30
-rw-r--r--src/threadengines/threadengine_pthread.cpp78
-rw-r--r--src/threadengines/threadengine_win32.cpp0
7 files changed, 215 insertions, 6 deletions
diff --git a/configure b/configure
index 3b3926df5..72719a478 100755
--- a/configure
+++ b/configure
@@ -1542,14 +1542,17 @@ sub write_dynamic_makefile
}
elsif ($line =~ /\/\* \$If: (\w+) \*\//i)
{
- if (($config{$1} !~ /y/i) and ($config{$1} ne "1"))
+ if (defined $config{$1})
{
- # Skip to 'endif'
- while (defined($line = <CPP>))
+ if (($config{$1} !~ /y/i) and ($config{$1} ne "1"))
{
- chomp($line);
- die ("\$If buildsystem instruction within another \$If in file $dir/$name") if ($line =~ /\/\* \$If: (\w+) \*\//i);
- last if ($line =~ /\/\* \$EndIf \*\//i);
+ # Skip to 'endif'
+ while (defined($line = <CPP>))
+ {
+ chomp($line);
+ die ("\$If buildsystem instruction within another \$If in file $dir/$name") if ($line =~ /\/\* \$If: (\w+) \*\//i);
+ last if ($line =~ /\/\* \$EndIf \*\//i);
+ }
}
}
}
diff --git a/include/threadengine.h b/include/threadengine.h
new file mode 100644
index 000000000..7d27b867a
--- /dev/null
+++ b/include/threadengine.h
@@ -0,0 +1,53 @@
+/* +------------------------------------+
+ * | 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.
+ *
+ * ---------------------------------------------------
+ */
+
+#ifndef __THREADENGINE__
+#define __THREADENGINE__
+
+#include <vector>
+#include <string>
+#include <map>
+#include "inspircd_config.h"
+#include "base.h"
+
+class InspIRCd;
+
+class CoreExport Thread : public Extensible
+{
+ public:
+ Thread() { };
+ virtual ~Thread() { };
+ virtual void Run() = 0;
+};
+
+class CoreExport ThreadEngine : public Extensible
+{
+ protected:
+
+ InspIRCd* ServerInstance;
+ Thread* NewThread;
+
+ public:
+
+ ThreadEngine(InspIRCd* Instance);
+
+ virtual ~ThreadEngine();
+
+ virtual bool Mutex(bool enable) = 0;
+
+ virtual void Run() = 0;
+
+ virtual void Create(Thread* thread_to_init) = 0;
+};
+
+#endif
diff --git a/include/threadengines/threadengine_pthread.h b/include/threadengines/threadengine_pthread.h
new file mode 100644
index 000000000..db32acbcc
--- /dev/null
+++ b/include/threadengines/threadengine_pthread.h
@@ -0,0 +1,45 @@
+/* +------------------------------------+
+ * | 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.
+ *
+ * ---------------------------------------------------
+ */
+
+#ifndef __THREADENGINE_PTHREAD__
+#define __THREADENGINE_PTHREAD__
+
+#include <pthread.h>
+#include "inspircd_config.h"
+#include "base.h"
+#include "threadengine.h"
+
+class InspIRCd;
+
+class CoreExport PThreadEngine : public ThreadEngine
+{
+ private:
+
+ pthread_t MyPThread;
+
+ public:
+
+ PThreadEngine(InspIRCd* Instance);
+
+ virtual ~PThreadEngine();
+
+ bool Mutex(bool enable);
+
+ void Run();
+
+ static void* Entry(void* parameter);
+
+ void Create(Thread* thread_to_init);
+};
+
+#endif
diff --git a/include/threadengines/threadengine_win32.h b/include/threadengines/threadengine_win32.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/include/threadengines/threadengine_win32.h
diff --git a/src/threadengine.cpp b/src/threadengine.cpp
new file mode 100644
index 000000000..f16b50985
--- /dev/null
+++ b/src/threadengine.cpp
@@ -0,0 +1,30 @@
+/* +------------------------------------+
+ * | 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: threadengines/threadengine_pthread.cpp */
+/* $ExtraObjects: threadengine_pthread.o */
+
+#include "inspircd.h"
+#include "threadengine.h"
+
+ThreadEngine::ThreadEngine(InspIRCd* Instance) : ServerInstance(Instance)
+{
+}
+
+ThreadEngine::~ThreadEngine()
+{
+}
+
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;
+}
+
diff --git a/src/threadengines/threadengine_win32.cpp b/src/threadengines/threadengine_win32.cpp
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/threadengines/threadengine_win32.cpp