aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/llthread.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/llthread.c b/src/llthread.c
index 492766e..0ff39d7 100644
--- a/src/llthread.c
+++ b/src/llthread.c
@@ -2,20 +2,21 @@
2# define USE_PTHREAD 2# define USE_PTHREAD
3#endif 3#endif
4 4
5#include <stdlib.h>
6#include <memory.h>
7#include <assert.h>
8#include <errno.h>
9
10#ifndef USE_PTHREAD 5#ifndef USE_PTHREAD
11# include <windows.h> 6# include <windows.h>
12# include <stdio.h>
13# include <process.h> 7# include <process.h>
14#else 8#else
15# include <pthread.h> 9# include <pthread.h>
16# include <stdio.h>
17#endif 10#endif
18 11
12#include <stdlib.h>
13#include <stdio.h>
14#include <memory.h>
15#include <assert.h>
16#include <errno.h>
17#include <lualib.h>
18#include "l52util.h"
19
19/*export*/ 20/*export*/
20#ifdef _WIN32 21#ifdef _WIN32
21# define LLTHREADS_EXPORT_API __declspec(dllexport) 22# define LLTHREADS_EXPORT_API __declspec(dllexport)
@@ -40,7 +41,7 @@
40#endif 41#endif
41 42
42#ifndef USE_PTHREAD 43#ifndef USE_PTHREAD
43# define OS_THREAD_RETURT unsigned int __stdcall 44# define OS_THREAD_RETURN unsigned int __stdcall
44# define INVALID_THREAD INVALID_HANDLE_VALUE 45# define INVALID_THREAD INVALID_HANDLE_VALUE
45# define INFINITE_JOIN_TIMEOUT INFINITE 46# define INFINITE_JOIN_TIMEOUT INFINITE
46# define JOIN_OK 0 47# define JOIN_OK 0
@@ -49,8 +50,7 @@
49typedef DWORD join_timeout_t; 50typedef DWORD join_timeout_t;
50typedef HANDLE os_thread_t; 51typedef HANDLE os_thread_t;
51#else 52#else
52# define OS_THREAD_RETURT void * 53# define OS_THREAD_RETURN void *
53# define INVALID_THREAD 0
54# define INFINITE_JOIN_TIMEOUT -1 54# define INFINITE_JOIN_TIMEOUT -1
55# define JOIN_OK 0 55# define JOIN_OK 0
56# define JOIN_ETIMEDOUT ETIMEDOUT 56# define JOIN_ETIMEDOUT ETIMEDOUT
@@ -58,8 +58,6 @@ typedef int join_timeout_t;
58typedef pthread_t os_thread_t; 58typedef pthread_t os_thread_t;
59#endif 59#endif
60 60
61#include "l52util.h"
62#include <lualib.h>
63 61
64LLTHREADS_EXPORT_API int luaopen_llthreads(lua_State *L); 62LLTHREADS_EXPORT_API int luaopen_llthreads(lua_State *L);
65 63
@@ -389,10 +387,8 @@ static llthread_child_t *llthread_child_new() {
389 387
390 /* create new lua_State for the thread. */ 388 /* create new lua_State for the thread. */
391 /* open standard libraries. */ 389 /* open standard libraries. */
392 /* push traceback function as first value on stack. */
393 this->L = luaL_newstate(); 390 this->L = luaL_newstate();
394 open_thread_libs(this->L); 391 open_thread_libs(this->L);
395 lua_pushcfunction(this->L, traceback);
396 392
397 return this; 393 return this;
398} 394}
@@ -402,10 +398,14 @@ static void llthread_child_destroy(llthread_child_t *this) {
402 FREE_STRUCT(this); 398 FREE_STRUCT(this);
403} 399}
404 400
405static OS_THREAD_RETURT llthread_child_thread_run(void *arg) { 401static OS_THREAD_RETURN llthread_child_thread_run(void *arg) {
406 llthread_child_t *this = (llthread_child_t *)arg; 402 llthread_child_t *this = (llthread_child_t *)arg;
407 lua_State *L = this->L; 403 lua_State *L = this->L;
408 int nargs = lua_gettop(L) - 2; 404 int nargs = lua_gettop(L) - 1;
405
406 /* push traceback function as first value on stack. */
407 lua_pushcfunction(this->L, traceback);
408 lua_insert(L, 1);
409 409
410 this->status = lua_pcall(L, nargs, LUA_MULTRET, 1); 410 this->status = lua_pcall(L, nargs, LUA_MULTRET, 1);
411 411
@@ -485,8 +485,6 @@ static int llthread_push_results(lua_State *L, llthread_child_t *child, int idx,
485static int llthread_detach(llthread_t *this){ 485static int llthread_detach(llthread_t *this){
486 int rc = 0; 486 int rc = 0;
487 this->child = NULL; 487 this->child = NULL;
488 FLAG_SET(this, TSTATE_DETACHED);
489 FLAG_UNSET(this, FLAG_JOIN_LUA);
490#ifdef USE_PTHREAD 488#ifdef USE_PTHREAD
491 rc = pthread_detach(this->thread); 489 rc = pthread_detach(this->thread);
492#endif 490#endif