From 3de8f797d0e235efd20fdc9c55c8068893f4fd03 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Wed, 25 Jun 2014 10:11:17 +0500 Subject: Add. started/detached/joinable methods to thread object. --- src/llthread.c | 25 +++++++++++++++++++++++-- src/lua/llthreads2/ex.lua | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/llthread.c b/src/llthread.c index 0ffa727..33eab4f 100644 --- a/src/llthread.c +++ b/src/llthread.c @@ -4,8 +4,8 @@ #define LLTHREAD_VERSION_MAJOR 0 #define LLTHREAD_VERSION_MINOR 1 -#define LLTHREAD_VERSION_PATCH 0 -#define LLTHREAD_VERSION_COMMENT "" +#define LLTHREAD_VERSION_PATCH 2 +#define LLTHREAD_VERSION_COMMENT "dev" #ifndef USE_PTHREAD # include @@ -660,6 +660,24 @@ static int l_llthread_alive(lua_State *L) { } +static int l_llthread_started(lua_State *L) { + llthread_t *this = l_llthread_at(L, 1); + lua_pushboolean(L, IS(this, STARTED)?1:0); + return 1; +} + +static int l_llthread_detached(lua_State *L) { + llthread_t *this = l_llthread_at(L, 1); + lua_pushboolean(L, IS(this, DETACHED)?1:0); + return 1; +} + +static int l_llthread_joinable(lua_State *L) { + llthread_t *this = l_llthread_at(L, 1); + lua_pushboolean(L, IS(this, JOINABLE)?1:0); + return 1; +} + static int l_llthread_new(lua_State *L) { size_t lua_code_len; const char *lua_code = luaL_checklstring(L, 1, &lua_code_len); llthread_t **this = lutil_newudatap(L, llthread_t*, LLTHREAD_TAG); @@ -674,6 +692,9 @@ static const struct luaL_Reg l_llthread_meth[] = { {"start", l_llthread_start }, {"join", l_llthread_join }, {"alive", l_llthread_alive }, + {"started", l_llthread_started }, + {"detached", l_llthread_detached }, + {"joinable", l_llthread_joinable }, {"__gc", l_llthread_delete }, {NULL, NULL} diff --git a/src/lua/llthreads2/ex.lua b/src/lua/llthreads2/ex.lua index 06af3a5..77f8d5e 100644 --- a/src/lua/llthreads2/ex.lua +++ b/src/lua/llthreads2/ex.lua @@ -123,6 +123,24 @@ function thread_mt:alive() return self.thread:alive() end +--- Check if thread was started. +-- +function thread_mt:started() + return self.thread:started() +end + +--- Check if thread is detached. +-- This function returns valid value only for started thread. +function thread_mt:detached() + return self.thread:detached() +end + +--- Check if thread is joinable. +-- This function returns valid value only for started thread. +function thread_mt:joinable() + return self.thread:joinable() +end + end ------------------------------------------------------------------------------- -- cgit v1.2.3-55-g6feb