From 1de7313ade8b0a6f6e3dc395eed5dd65c44a7829 Mon Sep 17 00:00:00 2001 From: moteus Date: Tue, 31 Dec 2013 11:05:54 +0400 Subject: Change. Implement 2 rockspecs llthreads2 and llthreads2-compat. --- .travis.yml | 2 +- rockspecs/lua-llthreads2-compat-scm-0.rockspec | 44 ++++++++++++++++++++++++++ rockspecs/lua-llthreads2-scm-0.rockspec | 8 ++++- src/llthread.c | 28 ++++++++++------ 4 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 rockspecs/lua-llthreads2-compat-scm-0.rockspec diff --git a/.travis.yml b/.travis.yml index e5d2f0f..95708f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ before_install: install: - sudo luarocks install lunitx - - sudo luarocks make rockspecs/lua-llthreads2-scm-0.rockspec + - sudo luarocks make rockspecs/lua-llthreads2-compat-scm-0.rockspec script: - cd test diff --git a/rockspecs/lua-llthreads2-compat-scm-0.rockspec b/rockspecs/lua-llthreads2-compat-scm-0.rockspec new file mode 100644 index 0000000..ac81a15 --- /dev/null +++ b/rockspecs/lua-llthreads2-compat-scm-0.rockspec @@ -0,0 +1,44 @@ +package = "lua-llthreads2-compat" +version = "scm-0" +source = { + url = "https://github.com/moteus/lua-llthreads2/archive/master.zip", + dir = "lua-llthreads2-master", +} +description = { + summary = "Low-Level threads for Lua", + homepage = "http://github.com/moteus/lua-llthreads2", + license = "MIT/X11", + detailed = [[ + This is drop-in replacement for `lua-llthread` module. + In additional module supports: thread join with zero timeout; logging thread errors with + custom logger; run detached joinable threads; pass cfunctions as argument to child thread. + ]], +} +dependencies = { + "lua >= 5.1, < 5.3", +} +build = { + type = "builtin", + platforms = { + unix = { + modules = { + llthreads = { + libraries = {"pthread"}, + } + } + }, + windows = { + modules = { + llthreads = { + libraries = {"kernel32"}, + } + } + } + }, + modules = { + llthreads = { + sources = { "src/l52util.c", "src/llthread.c" }, + defines = { "LLTHREAD_MODULE_NAME=llthreads" }, + } + } +} \ No newline at end of file diff --git a/rockspecs/lua-llthreads2-scm-0.rockspec b/rockspecs/lua-llthreads2-scm-0.rockspec index e543dc3..9810118 100644 --- a/rockspecs/lua-llthreads2-scm-0.rockspec +++ b/rockspecs/lua-llthreads2-scm-0.rockspec @@ -8,6 +8,11 @@ description = { summary = "Low-Level threads for Lua", homepage = "http://github.com/moteus/lua-llthreads2", license = "MIT/X11", + detailed = [[ + This is drop-in replacement for `lua-llthread` module but the module called `llthreads2`. + In additional module supports: thread join with zero timeout; logging thread errors with + custom logger; run detached joinable threads; pass cfunctions as argument to child thread. + ]], } dependencies = { "lua >= 5.1, < 5.3", @@ -31,8 +36,9 @@ build = { } }, modules = { - llthreads = { + llthreads2 = { sources = { "src/l52util.c", "src/llthread.c" }, + defines = { "LLTHREAD_MODULE_NAME=llthreads2" }, } } } \ No newline at end of file diff --git a/src/llthread.c b/src/llthread.c index 0c4a107..88d3805 100644 --- a/src/llthread.c +++ b/src/llthread.c @@ -80,11 +80,21 @@ typedef pthread_t os_thread_t; #define ALLOC_STRUCT(S) (S*)calloc(1, sizeof(S)) #define FREE_STRUCT(O) free(O) -LLTHREADS_EXPORT_API int luaopen_llthreads(lua_State *L); +#ifndef LLTHREAD_MODULE_NAME +# define LLTHREAD_MODULE_NAME llthreads +#endif + +#define CAT(S1,S2) S1##S2 + +#define LLTHREAD_OPEN_NAME_IMPL(NAME) CAT(luaopen_, NAME) + +#define LLTHREAD_OPEN_NAME LLTHREAD_OPEN_NAME_IMPL(LLTHREAD_MODULE_NAME) + +LLTHREADS_EXPORT_API int LLTHREAD_OPEN_NAME(lua_State *L); -#define LLTHREAD_T_NAME "LLThread" -static const char *LLTHREAD_T = LLTHREAD_T_NAME; -static const char *LLTHREAD_LOGGER_HOLDER = LLTHREAD_T_NAME " logger holder"; +#define LLTHREAD_NAME "LLThread" +static const char *LLTHREAD_TAG = LLTHREAD_NAME; +static const char *LLTHREAD_LOGGER_HOLDER = LLTHREAD_NAME " logger holder"; typedef struct llthread_child_t { lua_State *L; @@ -476,7 +486,7 @@ static llthread_t *llthread_create(lua_State *L, const char *code, size_t code_l //{ Lua interface to llthread static llthread_t *l_llthread_at (lua_State *L, int i) { - llthread_t **this = (llthread_t **)lutil_checkudatap (L, i, LLTHREAD_T); + llthread_t **this = (llthread_t **)lutil_checkudatap (L, i, LLTHREAD_TAG); luaL_argcheck (L, this != NULL, i, "thread expected"); luaL_argcheck (L, *this != NULL, i, "thread expected"); // luaL_argcheck (L, !(counter->flags & FLAG_DESTROYED), 1, "PDH Counter is destroyed"); @@ -484,7 +494,7 @@ static llthread_t *l_llthread_at (lua_State *L, int i) { } static int l_llthread_delete(lua_State *L) { - llthread_t **pthis = (llthread_t **)lutil_checkudatap (L, 1, LLTHREAD_T); + llthread_t **pthis = (llthread_t **)lutil_checkudatap (L, 1, LLTHREAD_TAG); luaL_argcheck (L, pthis != NULL, 1, "thread expected"); if(*pthis == NULL) return 0; llthread_destroy(*pthis); @@ -579,7 +589,7 @@ static int l_llthread_join(lua_State *L) { 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_T); + llthread_t **this = lutil_newudatap(L, llthread_t*, LLTHREAD_TAG); lua_insert(L, 2); /*move self prior args*/ *this = llthread_create(L, lua_code, lua_code_len); @@ -611,9 +621,9 @@ static const struct luaL_Reg l_llthreads_lib[] = { {NULL, NULL} }; -LLTHREADS_EXPORT_API int luaopen_llthreads(lua_State *L) { +LLTHREADS_EXPORT_API int LLTHREAD_OPEN_NAME(lua_State *L) { int top = lua_gettop(L); - lutil_createmetap(L, LLTHREAD_T, l_llthread_meth, 0); + lutil_createmetap(L, LLTHREAD_TAG, l_llthread_meth, 0); lua_settop(L, top); lua_newtable(L); -- cgit v1.2.3-55-g6feb