Added Thread:isRunning

This commit is contained in:
Alex Szpakowski
2013-07-16 00:18:04 -03:00
parent 719e9253da
commit 8ac288876d
10 changed files with 42 additions and 11 deletions
+2 -1
View File
@@ -93,9 +93,10 @@ bool LuaThread::start(Variant **args, int nargs)
return Threadable::start();
}
const std::string &LuaThread::getError()
const std::string &LuaThread::getError() const
{
return error;
}
} // thread
} // love
+1 -1
View File
@@ -40,7 +40,7 @@ public:
LuaThread(const std::string &name, love::Data *code);
~LuaThread();
void threadFunction();
const std::string &getError();
const std::string &getError() const;
bool start(Variant **args, int nargs);
+3
View File
@@ -33,9 +33,12 @@ namespace thread
class Thread
{
public:
virtual ~Thread() {}
virtual bool start() = 0;
virtual void wait() = 0;
virtual bool isRunning() = 0;
}; // ThreadObject
} // thread
+6
View File
@@ -68,6 +68,12 @@ void Thread::wait()
thread = 0;
}
bool Thread::isRunning()
{
Lock l(mutex);
return running;
}
int Thread::thread_runner(void *data)
{
Thread *self = (Thread *) data; // some compilers don't like 'this'
+13 -7
View File
@@ -36,19 +36,25 @@ namespace sdl
{
class Thread : public thread::Thread
{
private:
Threadable *t;
bool running;
SDL_Thread *thread;
static int thread_runner(void *data);
Mutex mutex;
public:
Thread(Threadable *t);
~Thread();
bool start();
void wait();
bool isRunning();
private:
Threadable *t;
bool running;
SDL_Thread *thread;
Mutex mutex;
static int thread_runner(void *data);
}; // Thread
} // sdl
} // thread
} // love
+5
View File
@@ -93,5 +93,10 @@ void Threadable::wait()
owner->wait();
}
bool Threadable::isRunning() const
{
return owner->isRunning();
}
} // thread
} // love
+1
View File
@@ -82,6 +82,7 @@ public:
bool start();
void wait();
bool isRunning() const;
protected:
Thread *owner;
+2 -2
View File
@@ -48,7 +48,7 @@ int w_Channel_push(lua_State *L)
Channel *c = luax_checkchannel(L, 1);
Variant *var = lua_isnoneornil(L, 2) ? 0 : Variant::fromLua(L, 2);
if (!var)
return luaL_argerror(L, 2, "boolean, number, string, or love type expected");
return luaL_argerror(L, 2, "boolean, number, string, love type, or flat table expected");
c->push(var);
releaseVariant(c, var);
return 0;
@@ -59,7 +59,7 @@ int w_Channel_supply(lua_State *L)
Channel *c = luax_checkchannel(L, 1);
Variant *var = lua_isnoneornil(L, 2) ? 0 : Variant::fromLua(L, 2);
if (!var)
return luaL_argerror(L, 2, "boolean, number, string, or love type expected");
return luaL_argerror(L, 2, "boolean, number, string, love type, or flat table expected");
c->supply(var);
releaseVariant(c, var);
return 0;
+8
View File
@@ -65,10 +65,18 @@ int w_Thread_getError(lua_State *L)
return 1;
}
int w_Thread_isRunning(lua_State *L)
{
LuaThread *t = luax_checkthread(L, 1);
luax_pushboolean(L, t->isRunning());
return 1;
}
static const luaL_Reg type_functions[] = {
{ "start", w_Thread_start },
{ "wait", w_Thread_wait },
{ "getError", w_Thread_getError },
{ "isRunning", w_Thread_isRunning },
{ 0, 0 }
};
+1
View File
@@ -33,6 +33,7 @@ LuaThread *luax_checkthread(lua_State *L, int idx);
int w_Thread_start(lua_State *L);
int w_Thread_wait(lua_State *L);
int w_Thread_getError(lua_State *L);
int w_Thread_isRunning(lua_State *L);
extern "C" int luaopen_thread(lua_State *L);