From 4ba513b67957ea49e14e4f1fe1481246703fe960 Mon Sep 17 00:00:00 2001 From: rude Date: Wed, 24 Feb 2010 20:40:59 +0100 Subject: [PATCH] Bye-bye ThreadModuleRegistrar. An abstract ThreadModule will do that job. --- platform/msvc2008/love.vcproj | 4 +++ platform/msvc2008/thread/thread.vcproj | 4 +++ src/modules/thread/ThreadModule.h | 41 ++++++++++++++++++++++++++ src/modules/thread/sdl/Thread.cpp | 16 +++++----- src/modules/thread/sdl/Thread.h | 22 +++++--------- 5 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 src/modules/thread/ThreadModule.h diff --git a/platform/msvc2008/love.vcproj b/platform/msvc2008/love.vcproj index 46ec8e992..3a4a54bff 100644 --- a/platform/msvc2008/love.vcproj +++ b/platform/msvc2008/love.vcproj @@ -3232,6 +3232,10 @@ + + diff --git a/platform/msvc2008/thread/thread.vcproj b/platform/msvc2008/thread/thread.vcproj index 8866848b8..809af69b4 100644 --- a/platform/msvc2008/thread/thread.vcproj +++ b/platform/msvc2008/thread/thread.vcproj @@ -205,6 +205,10 @@ > + + diff --git a/src/modules/thread/ThreadModule.h b/src/modules/thread/ThreadModule.h new file mode 100644 index 000000000..cc26a4f1c --- /dev/null +++ b/src/modules/thread/ThreadModule.h @@ -0,0 +1,41 @@ +/** +* Copyright (c) 2006-2010 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +**/ + +#ifndef LOVE_THREAD_THREAD_H +#define LOVE_THREAD_THREAD_H + +#include +#include + +namespace love +{ +namespace thread +{ + class ThreadModule : public Module + { + public: + virtual ~ThreadModule(){}; + virtual void unregister(std::string name) = 0; + }; // ThreadModule + +} // thread +} // love + +#endif // LOVE_THREAD_THREAD_H diff --git a/src/modules/thread/sdl/Thread.cpp b/src/modules/thread/sdl/Thread.cpp index 99cc030fa..602fad526 100644 --- a/src/modules/thread/sdl/Thread.cpp +++ b/src/modules/thread/sdl/Thread.cpp @@ -164,10 +164,10 @@ namespace sdl shared[name] = v; } - Thread::Thread(ThreadModuleRegistrar *reg, std::string name, love::Data *data) - : handle(0), reg(reg), name(name), isThread(true) + Thread::Thread(love::thread::ThreadModule *module, std::string name, love::Data *data) + : handle(0), module(module), name(name), isThread(true) { - reg->retain(); + module->retain(); unsigned int len = data->getSize(); this->data = new char[len+1]; memset(this->data, 0, len+1); @@ -177,10 +177,10 @@ namespace sdl cond = SDL_CreateCond(); } - Thread::Thread(ThreadModuleRegistrar *reg, std::string name) - : handle(0), reg(reg), name(name), data(0), isThread(false) + Thread::Thread(love::thread::ThreadModule *module, std::string name) + : handle(0), module(module), name(name), data(0), isThread(false) { - reg->retain(); + module->retain(); comm = new ThreadData(name.c_str(), NULL); mutex = SDL_CreateMutex(); cond = SDL_CreateCond(); @@ -193,10 +193,10 @@ namespace sdl delete comm; if (handle) SDL_KillThread(handle); - reg->unregister(name); + module->unregister(name); SDL_DestroyMutex(mutex); SDL_DestroyCond(cond); - reg->release(); + module->release(); } void Thread::start() diff --git a/src/modules/thread/sdl/Thread.h b/src/modules/thread/sdl/Thread.h index ddc9edd0f..81f665026 100644 --- a/src/modules/thread/sdl/Thread.h +++ b/src/modules/thread/sdl/Thread.h @@ -18,8 +18,8 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#ifndef LOVE_THREAD_THREAD_H -#define LOVE_THREAD_THREAD_H +#ifndef LOVE_THREAD_SDL_THREAD_H +#define LOVE_THREAD_SDL_THREAD_H // SDL #include @@ -30,7 +30,7 @@ #include // LOVE -#include +#include #include #include @@ -40,12 +40,6 @@ namespace thread { namespace sdl { - class ThreadModuleRegistrar : public Module - { - public: - virtual void unregister(std::string name) = 0; - }; - enum ThreadVariantType { UNKNOWN = 0, @@ -98,7 +92,7 @@ namespace sdl { private: SDL_Thread *handle; - ThreadModuleRegistrar *reg; + love::thread::ThreadModule *module; ThreadData *comm; std::string name; char *data; @@ -107,8 +101,8 @@ namespace sdl bool isThread; public: - Thread(ThreadModuleRegistrar *reg, std::string name, love::Data *data); - Thread(ThreadModuleRegistrar *reg, std::string name); + Thread(love::thread::ThreadModule *module, std::string name, love::Data *data); + Thread(love::thread::ThreadModule *module, std::string name); ~Thread(); void start(); void kill(); @@ -124,7 +118,7 @@ namespace sdl typedef std::map threadlist_t; - class ThreadModule : public ThreadModuleRegistrar + class ThreadModule : public love::thread::ThreadModule { private: threadlist_t threads; @@ -142,4 +136,4 @@ namespace sdl } // thread } // love -#endif // LOVE_THREAD_THREAD_H +#endif // LOVE_THREAD_SDL_THREAD_H