diff options
| author | moteus <mimir@newmail.ru> | 2013-12-31 11:05:54 +0400 |
|---|---|---|
| committer | moteus <mimir@newmail.ru> | 2013-12-31 11:19:39 +0400 |
| commit | 1de7313ade8b0a6f6e3dc395eed5dd65c44a7829 (patch) | |
| tree | 6ab9998a0c35c023c311a05e2eca449b99091037 | |
| parent | 24a0d330a1d7c34269ce987999e221e99171b35c (diff) | |
| download | lua-llthreads2-1de7313ade8b0a6f6e3dc395eed5dd65c44a7829.tar.gz lua-llthreads2-1de7313ade8b0a6f6e3dc395eed5dd65c44a7829.tar.bz2 lua-llthreads2-1de7313ade8b0a6f6e3dc395eed5dd65c44a7829.zip | |
Change. Implement 2 rockspecs llthreads2 and llthreads2-compat.
| -rw-r--r-- | .travis.yml | 2 | ||||
| -rw-r--r-- | rockspecs/lua-llthreads2-compat-scm-0.rockspec | 44 | ||||
| -rw-r--r-- | rockspecs/lua-llthreads2-scm-0.rockspec | 8 | ||||
| -rw-r--r-- | src/llthread.c | 28 |
4 files changed, 71 insertions, 11 deletions
diff --git a/.travis.yml b/.travis.yml index e5d2f0f..95708f1 100644 --- a/.travis.yml +++ b/.travis.yml | |||
| @@ -40,7 +40,7 @@ before_install: | |||
| 40 | 40 | ||
| 41 | install: | 41 | install: |
| 42 | - sudo luarocks install lunitx | 42 | - sudo luarocks install lunitx |
| 43 | - sudo luarocks make rockspecs/lua-llthreads2-scm-0.rockspec | 43 | - sudo luarocks make rockspecs/lua-llthreads2-compat-scm-0.rockspec |
| 44 | 44 | ||
| 45 | script: | 45 | script: |
| 46 | - cd test | 46 | - 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 @@ | |||
| 1 | package = "lua-llthreads2-compat" | ||
| 2 | version = "scm-0" | ||
| 3 | source = { | ||
| 4 | url = "https://github.com/moteus/lua-llthreads2/archive/master.zip", | ||
| 5 | dir = "lua-llthreads2-master", | ||
| 6 | } | ||
| 7 | description = { | ||
| 8 | summary = "Low-Level threads for Lua", | ||
| 9 | homepage = "http://github.com/moteus/lua-llthreads2", | ||
| 10 | license = "MIT/X11", | ||
| 11 | detailed = [[ | ||
| 12 | This is drop-in replacement for `lua-llthread` module. | ||
| 13 | In additional module supports: thread join with zero timeout; logging thread errors with | ||
| 14 | custom logger; run detached joinable threads; pass cfunctions as argument to child thread. | ||
| 15 | ]], | ||
| 16 | } | ||
| 17 | dependencies = { | ||
| 18 | "lua >= 5.1, < 5.3", | ||
| 19 | } | ||
| 20 | build = { | ||
| 21 | type = "builtin", | ||
| 22 | platforms = { | ||
| 23 | unix = { | ||
| 24 | modules = { | ||
| 25 | llthreads = { | ||
| 26 | libraries = {"pthread"}, | ||
| 27 | } | ||
| 28 | } | ||
| 29 | }, | ||
| 30 | windows = { | ||
| 31 | modules = { | ||
| 32 | llthreads = { | ||
| 33 | libraries = {"kernel32"}, | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | }, | ||
| 38 | modules = { | ||
| 39 | llthreads = { | ||
| 40 | sources = { "src/l52util.c", "src/llthread.c" }, | ||
| 41 | defines = { "LLTHREAD_MODULE_NAME=llthreads" }, | ||
| 42 | } | ||
| 43 | } | ||
| 44 | } \ 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 = { | |||
| 8 | summary = "Low-Level threads for Lua", | 8 | summary = "Low-Level threads for Lua", |
| 9 | homepage = "http://github.com/moteus/lua-llthreads2", | 9 | homepage = "http://github.com/moteus/lua-llthreads2", |
| 10 | license = "MIT/X11", | 10 | license = "MIT/X11", |
| 11 | detailed = [[ | ||
| 12 | This is drop-in replacement for `lua-llthread` module but the module called `llthreads2`. | ||
| 13 | In additional module supports: thread join with zero timeout; logging thread errors with | ||
| 14 | custom logger; run detached joinable threads; pass cfunctions as argument to child thread. | ||
| 15 | ]], | ||
| 11 | } | 16 | } |
| 12 | dependencies = { | 17 | dependencies = { |
| 13 | "lua >= 5.1, < 5.3", | 18 | "lua >= 5.1, < 5.3", |
| @@ -31,8 +36,9 @@ build = { | |||
| 31 | } | 36 | } |
| 32 | }, | 37 | }, |
| 33 | modules = { | 38 | modules = { |
| 34 | llthreads = { | 39 | llthreads2 = { |
| 35 | sources = { "src/l52util.c", "src/llthread.c" }, | 40 | sources = { "src/l52util.c", "src/llthread.c" }, |
| 41 | defines = { "LLTHREAD_MODULE_NAME=llthreads2" }, | ||
| 36 | } | 42 | } |
| 37 | } | 43 | } |
| 38 | } \ No newline at end of file | 44 | } \ 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; | |||
| 80 | #define ALLOC_STRUCT(S) (S*)calloc(1, sizeof(S)) | 80 | #define ALLOC_STRUCT(S) (S*)calloc(1, sizeof(S)) |
| 81 | #define FREE_STRUCT(O) free(O) | 81 | #define FREE_STRUCT(O) free(O) |
| 82 | 82 | ||
| 83 | LLTHREADS_EXPORT_API int luaopen_llthreads(lua_State *L); | 83 | #ifndef LLTHREAD_MODULE_NAME |
| 84 | # define LLTHREAD_MODULE_NAME llthreads | ||
| 85 | #endif | ||
| 86 | |||
| 87 | #define CAT(S1,S2) S1##S2 | ||
| 88 | |||
| 89 | #define LLTHREAD_OPEN_NAME_IMPL(NAME) CAT(luaopen_, NAME) | ||
| 90 | |||
| 91 | #define LLTHREAD_OPEN_NAME LLTHREAD_OPEN_NAME_IMPL(LLTHREAD_MODULE_NAME) | ||
| 92 | |||
| 93 | LLTHREADS_EXPORT_API int LLTHREAD_OPEN_NAME(lua_State *L); | ||
| 84 | 94 | ||
| 85 | #define LLTHREAD_T_NAME "LLThread" | 95 | #define LLTHREAD_NAME "LLThread" |
| 86 | static const char *LLTHREAD_T = LLTHREAD_T_NAME; | 96 | static const char *LLTHREAD_TAG = LLTHREAD_NAME; |
| 87 | static const char *LLTHREAD_LOGGER_HOLDER = LLTHREAD_T_NAME " logger holder"; | 97 | static const char *LLTHREAD_LOGGER_HOLDER = LLTHREAD_NAME " logger holder"; |
| 88 | 98 | ||
| 89 | typedef struct llthread_child_t { | 99 | typedef struct llthread_child_t { |
| 90 | lua_State *L; | 100 | lua_State *L; |
| @@ -476,7 +486,7 @@ static llthread_t *llthread_create(lua_State *L, const char *code, size_t code_l | |||
| 476 | //{ Lua interface to llthread | 486 | //{ Lua interface to llthread |
| 477 | 487 | ||
| 478 | static llthread_t *l_llthread_at (lua_State *L, int i) { | 488 | static llthread_t *l_llthread_at (lua_State *L, int i) { |
| 479 | llthread_t **this = (llthread_t **)lutil_checkudatap (L, i, LLTHREAD_T); | 489 | llthread_t **this = (llthread_t **)lutil_checkudatap (L, i, LLTHREAD_TAG); |
| 480 | luaL_argcheck (L, this != NULL, i, "thread expected"); | 490 | luaL_argcheck (L, this != NULL, i, "thread expected"); |
| 481 | luaL_argcheck (L, *this != NULL, i, "thread expected"); | 491 | luaL_argcheck (L, *this != NULL, i, "thread expected"); |
| 482 | // luaL_argcheck (L, !(counter->flags & FLAG_DESTROYED), 1, "PDH Counter is destroyed"); | 492 | // 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) { | |||
| 484 | } | 494 | } |
| 485 | 495 | ||
| 486 | static int l_llthread_delete(lua_State *L) { | 496 | static int l_llthread_delete(lua_State *L) { |
| 487 | llthread_t **pthis = (llthread_t **)lutil_checkudatap (L, 1, LLTHREAD_T); | 497 | llthread_t **pthis = (llthread_t **)lutil_checkudatap (L, 1, LLTHREAD_TAG); |
| 488 | luaL_argcheck (L, pthis != NULL, 1, "thread expected"); | 498 | luaL_argcheck (L, pthis != NULL, 1, "thread expected"); |
| 489 | if(*pthis == NULL) return 0; | 499 | if(*pthis == NULL) return 0; |
| 490 | llthread_destroy(*pthis); | 500 | llthread_destroy(*pthis); |
| @@ -579,7 +589,7 @@ static int l_llthread_join(lua_State *L) { | |||
| 579 | 589 | ||
| 580 | static int l_llthread_new(lua_State *L) { | 590 | static int l_llthread_new(lua_State *L) { |
| 581 | size_t lua_code_len; const char *lua_code = luaL_checklstring(L, 1, &lua_code_len); | 591 | size_t lua_code_len; const char *lua_code = luaL_checklstring(L, 1, &lua_code_len); |
| 582 | llthread_t **this = lutil_newudatap(L, llthread_t*, LLTHREAD_T); | 592 | llthread_t **this = lutil_newudatap(L, llthread_t*, LLTHREAD_TAG); |
| 583 | lua_insert(L, 2); /*move self prior args*/ | 593 | lua_insert(L, 2); /*move self prior args*/ |
| 584 | *this = llthread_create(L, lua_code, lua_code_len); | 594 | *this = llthread_create(L, lua_code, lua_code_len); |
| 585 | 595 | ||
| @@ -611,9 +621,9 @@ static const struct luaL_Reg l_llthreads_lib[] = { | |||
| 611 | {NULL, NULL} | 621 | {NULL, NULL} |
| 612 | }; | 622 | }; |
| 613 | 623 | ||
| 614 | LLTHREADS_EXPORT_API int luaopen_llthreads(lua_State *L) { | 624 | LLTHREADS_EXPORT_API int LLTHREAD_OPEN_NAME(lua_State *L) { |
| 615 | int top = lua_gettop(L); | 625 | int top = lua_gettop(L); |
| 616 | lutil_createmetap(L, LLTHREAD_T, l_llthread_meth, 0); | 626 | lutil_createmetap(L, LLTHREAD_TAG, l_llthread_meth, 0); |
| 617 | lua_settop(L, top); | 627 | lua_settop(L, top); |
| 618 | 628 | ||
| 619 | lua_newtable(L); | 629 | lua_newtable(L); |
