aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormoteus <mimir@newmail.ru>2013-12-30 12:58:48 +0400
committermoteus <mimir@newmail.ru>2013-12-30 12:58:48 +0400
commit18464f368d90b0f8ce48cb5d45def6f9d87e3432 (patch)
tree89d9c45aa5a25fe361b6ec4bd5495375664b0b81 /src
parenta087c2737441aad781be7e3d88775e688152ad4e (diff)
downloadlua-llthreads2-18464f368d90b0f8ce48cb5d45def6f9d87e3432.tar.gz
lua-llthreads2-18464f368d90b0f8ce48cb5d45def6f9d87e3432.tar.bz2
lua-llthreads2-18464f368d90b0f8ce48cb5d45def6f9d87e3432.zip
Change. does not register llthread loader.
This is because of better load dynamic library from child thread to prevent unload dynamic library if parent Lua state closes.
Diffstat (limited to 'src')
-rw-r--r--src/llthread.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/llthread.c b/src/llthread.c
index 88498a8..f7a9b59 100644
--- a/src/llthread.c
+++ b/src/llthread.c
@@ -340,17 +340,16 @@ void llthread_log(lua_State *L, const char *hdr, const char *msg){
340//{ llthread_child 340//{ llthread_child
341 341
342static void open_thread_libs(lua_State *L){ 342static void open_thread_libs(lua_State *L){
343#define L_REGLIB(L, name) lua_pushcfunction(L, luaopen_##name); lua_setfield(L, -2)
344
343 int top = lua_gettop(L); 345 int top = lua_gettop(L);
344 346
345#ifndef LLTHREAD_REGISTER_STD_LIBRARY 347#ifndef LLTHREAD_REGISTER_STD_LIBRARY
348
346 luaL_openlibs(L); 349 luaL_openlibs(L);
347 lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); lua_remove(L, -2); 350 lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); lua_remove(L, -2);
348 lua_pushcfunction(L, luaopen_llthreads); lua_setfield(L, -2, "llthreads");
349 lua_settop(L, top);
350 return;
351#else
352 351
353#define L_REGLIB(L, name, G) lua_pushcfunction(L, luaopen_##name); lua_setfield(L, -2, #name) 352#else
354 353
355 lutil_require(L, "_G", luaopen_base, 1); 354 lutil_require(L, "_G", luaopen_base, 1);
356 lutil_require(L, "package", luaopen_package, 1); 355 lutil_require(L, "package", luaopen_package, 1);
@@ -363,13 +362,12 @@ static void open_thread_libs(lua_State *L){
363 L_REGLIB(L, math, 1); 362 L_REGLIB(L, math, 1);
364 L_REGLIB(L, table, 1); 363 L_REGLIB(L, table, 1);
365 L_REGLIB(L, string, 1); 364 L_REGLIB(L, string, 1);
366 L_REGLIB(L, llthreads, 0);
367 365
368#ifdef LUA_DBLIBNAME 366#ifdef LUA_DBLIBNAME
369 L_REGLIB(L, debug, 1); 367 L_REGLIB(L, debug, 1);
370#endif 368#endif
371 369
372 /* @fixme find out luaopen_XXX in runtime */ 370 /* @fixme find out luaopen_XXX at runtime */
373#ifdef LUA_JITLIBNAME 371#ifdef LUA_JITLIBNAME
374 L_REGLIB(L, bit, 1); 372 L_REGLIB(L, bit, 1);
375 L_REGLIB(L, jit, 1); 373 L_REGLIB(L, jit, 1);
@@ -378,10 +376,15 @@ static void open_thread_libs(lua_State *L){
378 L_REGLIB(L, bit32, 1); 376 L_REGLIB(L, bit32, 1);
379#endif 377#endif
380 378
381 lua_settop(L, top); 379#endif
382#undef L_REGLIB
383 380
381#ifdef LLTHREAD_REGISTER_THREAD_LIBRARY
382 L_REGLIB(L, llthreads, 0);
384#endif 383#endif
384
385 lua_settop(L, top);
386
387#undef L_REGLIB
385} 388}
386 389
387static llthread_child_t *llthread_child_new() { 390static llthread_child_t *llthread_child_new() {
@@ -529,6 +532,7 @@ static int llthread_detach(llthread_t *this){
529 int rc = 0; 532 int rc = 0;
530 533
531 assert(FLAGS_IS_SET(this, TSTATE_STARTED)); 534 assert(FLAGS_IS_SET(this, TSTATE_STARTED));
535 assert(this->child != NULL);
532 536
533 /*we can not deatach joined thread*/ 537 /*we can not deatach joined thread*/
534 if(FLAGS_IS_SET(this, TSTATE_JOINED)) 538 if(FLAGS_IS_SET(this, TSTATE_JOINED))