mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Bye-bye ThreadModuleRegistrar. An abstract ThreadModule will do that job.
This commit is contained in:
@@ -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 <common/Module.h>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
@@ -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()
|
||||
|
||||
@@ -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 <SDL_thread.h>
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <string>
|
||||
|
||||
// LOVE
|
||||
#include <common/Module.h>
|
||||
#include <thread/ThreadModule.h>
|
||||
#include <filesystem/File.h>
|
||||
#include <common/runtime.h>
|
||||
|
||||
@@ -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<std::string, Thread*> 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
|
||||
|
||||
Reference in New Issue
Block a user