mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +02:00
Fix a potential crash when a Thread ends (resolves issue #1219).
This commit is contained in:
@@ -131,7 +131,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
PoolThread(Pool *pool);
|
PoolThread(Pool *pool);
|
||||||
~PoolThread();
|
virtual ~PoolThread();
|
||||||
void setFinish();
|
void setFinish();
|
||||||
void threadFunction();
|
void threadFunction();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ LuaThread::~LuaThread()
|
|||||||
|
|
||||||
void LuaThread::threadFunction()
|
void LuaThread::threadFunction()
|
||||||
{
|
{
|
||||||
this->retain();
|
|
||||||
error.clear();
|
error.clear();
|
||||||
|
|
||||||
lua_State *L = luaL_newstate();
|
lua_State *L = luaL_newstate();
|
||||||
@@ -83,8 +82,6 @@ void LuaThread::threadFunction()
|
|||||||
|
|
||||||
if (!error.empty())
|
if (!error.empty())
|
||||||
onError();
|
onError();
|
||||||
|
|
||||||
this->release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaThread::start(const std::vector<Variant> &args)
|
bool LuaThread::start(const std::vector<Variant> &args)
|
||||||
|
|||||||
@@ -36,12 +36,12 @@ namespace love
|
|||||||
namespace thread
|
namespace thread
|
||||||
{
|
{
|
||||||
|
|
||||||
class LuaThread : public love::Object, public Threadable
|
class LuaThread : public Threadable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
LuaThread(const std::string &name, love::Data *code);
|
LuaThread(const std::string &name, love::Data *code);
|
||||||
~LuaThread();
|
virtual ~LuaThread();
|
||||||
void threadFunction();
|
void threadFunction();
|
||||||
const std::string &getError() const;
|
const std::string &getError() const;
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace sdl
|
|||||||
Thread::Thread(Threadable *t)
|
Thread::Thread(Threadable *t)
|
||||||
: t(t)
|
: t(t)
|
||||||
, running(false)
|
, running(false)
|
||||||
, thread(0)
|
, thread(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,9 +74,16 @@ bool Thread::isRunning()
|
|||||||
int Thread::thread_runner(void *data)
|
int Thread::thread_runner(void *data)
|
||||||
{
|
{
|
||||||
Thread *self = (Thread *) data; // some compilers don't like 'this'
|
Thread *self = (Thread *) data; // some compilers don't like 'this'
|
||||||
|
self->t->retain();
|
||||||
|
|
||||||
self->t->threadFunction();
|
self->t->threadFunction();
|
||||||
Lock l(self->mutex);
|
|
||||||
self->running = false;
|
{
|
||||||
|
Lock l(self->mutex);
|
||||||
|
self->running = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
self->t->release();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} // sdl
|
} // sdl
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ private:
|
|||||||
Mutex *mutex;
|
Mutex *mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Threadable
|
class Threadable : public love::Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Threadable();
|
Threadable();
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class Video : public love::video::Video
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Video();
|
Video();
|
||||||
~Video();
|
virtual ~Video();
|
||||||
|
|
||||||
// Implements Module
|
// Implements Module
|
||||||
virtual const char *getName() const;
|
virtual const char *getName() const;
|
||||||
@@ -58,7 +58,7 @@ class Worker : public love::thread::Threadable
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Worker();
|
Worker();
|
||||||
~Worker();
|
virtual ~Worker();
|
||||||
|
|
||||||
// Implements Threadable
|
// Implements Threadable
|
||||||
void threadFunction();
|
void threadFunction();
|
||||||
|
|||||||
Reference in New Issue
Block a user