From 9bc734b739043f6cccbb0b400dae1dedcd52033e Mon Sep 17 00:00:00 2001 From: brain Date: Thu, 21 Feb 2008 21:41:20 +0000 Subject: These are just copies of the pthread engine right now, will probably make them work tomorrow night git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8988 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/threadengines/threadengine_win32.h | 58 +++++++++++++++++++ src/threadengines/threadengine_pthread.cpp | 1 - src/threadengines/threadengine_win32.cpp | 93 ++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+), 1 deletion(-) diff --git a/include/threadengines/threadengine_win32.h b/include/threadengines/threadengine_win32.h index e69de29bb..c426372a9 100644 --- a/include/threadengines/threadengine_win32.h +++ b/include/threadengines/threadengine_win32.h @@ -0,0 +1,58 @@ +/* +------------------------------------+ + * | 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 +#include "inspircd_config.h" +#include "base.h" +#include "threadengine.h" + +class InspIRCd; + +class CoreExport Win32ThreadEngine : public ThreadEngine +{ + public: + + Win32ThreadEngine(InspIRCd* Instance); + + virtual ~Win32ThreadEngine(); + + bool Mutex(bool enable); + + void Run(); + + static void* Entry(void* parameter); + + void Create(Thread* thread_to_init); + + void FreeThread(Thread* thread); + + const std::string GetName() + { + return "windows-thread"; + } +}; + +class ThreadEngineFactory : public classbase +{ + public: + ThreadEngine* Create(InspIRCd* ServerInstance) + { + return new Win32ThreadEngine(ServerInstance); + } +}; + +#endif + diff --git a/src/threadengines/threadengine_pthread.cpp b/src/threadengines/threadengine_pthread.cpp index 8bdcd6d96..9dc203dec 100644 --- a/src/threadengines/threadengine_pthread.cpp +++ b/src/threadengines/threadengine_pthread.cpp @@ -54,7 +54,6 @@ void PThreadEngine::Create(Thread* thread_to_init) PThreadEngine::~PThreadEngine() { - //pthread_kill(this->MyPThread, SIGKILL); } void PThreadEngine::Run() diff --git a/src/threadengines/threadengine_win32.cpp b/src/threadengines/threadengine_win32.cpp index e69de29bb..5bc88fce0 100644 --- a/src/threadengines/threadengine_win32.cpp +++ b/src/threadengines/threadengine_win32.cpp @@ -0,0 +1,93 @@ +/* +------------------------------------+ + * | 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_win32.h" +#include + +pthread_mutex_t MyMutex = PTHREAD_MUTEX_INITIALIZER; + +Win32ThreadEngine::Win32ThreadEngine(InspIRCd* Instance) : ThreadEngine(Instance) +{ +} + +void Win32ThreadEngine::Create(Thread* thread_to_init) +{ + pthread_attr_t attribs; + pthread_attr_init(&attribs); + pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_JOINABLE); + pthread_t* MyPThread = new pthread_t; + + if (pthread_create(MyPThread, &attribs, Win32ThreadEngine::Entry, (void*)this) != 0) + { + delete MyPThread; + throw CoreException("Unable to create new Win32ThreadEngine: " + std::string(strerror(errno))); + } + + pthread_attr_destroy(&attribs); + + NewThread = thread_to_init; + NewThread->Creator = this; + NewThread->Extend("pthread", MyPThread); +} + +Win32ThreadEngine::~Win32ThreadEngine() +{ +} + +void Win32ThreadEngine::Run() +{ + NewThread->Run(); +} + +bool Win32ThreadEngine::Mutex(bool enable) +{ + if (enable) + pthread_mutex_lock(&MyMutex); + else + pthread_mutex_unlock(&MyMutex); + + return false; +} + +void* Win32ThreadEngine::Entry(void* parameter) +{ + ThreadEngine * pt = (ThreadEngine*)parameter; + pt->Run(); + return NULL; +} + +void Win32ThreadEngine::FreeThread(Thread* thread) +{ + pthread_t* pthread = NULL; + if (thread->GetExt("pthread", pthread)) + { + thread->SetExitFlag(); + int rc; + void* status; + rc = pthread_join(*pthread, &status); + delete pthread; + } +} + -- cgit v1.2.3