diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-02-10 14:32:02 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-02-10 14:32:02 +0000 |
commit | 9dbd7d10ac81c6445c58f4abb4f0eff240a8f9d2 (patch) | |
tree | 641c1af6e75faf5c55b60b99c6e070c7d0b26d7f /src | |
parent | 59643d29385fd4fbfed7a5720e90e2c9ffd1fd21 (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')
-rw-r--r-- | src/threadengine.cpp | 30 | ||||
-rw-r--r-- | src/threadengines/threadengine_pthread.cpp | 78 | ||||
-rw-r--r-- | src/threadengines/threadengine_win32.cpp | 0 |
3 files changed, 108 insertions, 0 deletions
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 |