summaryrefslogtreecommitdiff
path: root/src/lua-interface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua-interface.cpp')
-rw-r--r--src/lua-interface.cpp80
1 files changed, 2 insertions, 78 deletions
diff --git a/src/lua-interface.cpp b/src/lua-interface.cpp
index 5bb1615..3343b98 100644
--- a/src/lua-interface.cpp
+++ b/src/lua-interface.cpp
@@ -225,45 +225,6 @@ int my_getc (FILE * stream)
bool interactive = false, hserver = false, tserver = false, mserver = false;
-class threaded_Lua : public Lua {
- public:
- threaded_Lua() {
- init_mutex();
- }
- virtual ~threaded_Lua() {
- pthread_mutex_destroy(&mutex);
- }
- virtual void lock() {
- pthread_mutex_lock(&mutex);
- }
- virtual void unlock() {
- pthread_mutex_unlock(&mutex);
- }
- protected:
- virtual Lua * spawn_from_thread(lua_State * __L) {
- return new threaded_Lua(__L);
- }
- private:
- threaded_Lua(lua_State * __L) : Lua(__L) {
- init_mutex();
- }
- static void init_mutex() {
- if (did_init)
- return;
- did_init = true;
- pthread_mutexattr_t attr;
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init(&mutex, &attr);
- pthread_mutexattr_destroy(&attr);
- }
- static pthread_mutex_t mutex;
- static bool did_init;
-};
-
-pthread_mutex_t threaded_Lua::mutex;
-bool threaded_Lua::did_init = false;
-
class LuaStderrPrinter : public LuaPrinter {
public:
LuaStderrPrinter() { }
@@ -291,7 +252,6 @@ enum baselua_interface_t {
BASELUA_INTERFACE_PRELOAD,
BASELUA_INTERFACE_LOADMODULE,
BASELUA_INTERFACE_UNLINK,
- BASELUA_INTERFACE_NEWTHREAD,
};
struct lua_functypes_t baselua_interface_functions[] = {
@@ -299,25 +259,17 @@ struct lua_functypes_t baselua_interface_functions[] = {
{ BASELUA_INTERFACE_PRELOAD, "preload", 0, 1, { BLUA_STRING | BLUA_OBJECT } },
{ BASELUA_INTERFACE_LOADMODULE, "loadmodule", 1, 1, { BLUA_STRING } },
{ BASELUA_INTERFACE_UNLINK, "unlink", 1, 1, { BLUA_STRING } },
- { BASELUA_INTERFACE_NEWTHREAD, "newthread", 1, 1, { BLUA_STRING } },
{ -1, 0, 0, 0, 0 }
};
-struct thread_info_t {
- Lua * L;
- char * execstr;
-};
-
class sLua_baselua_interface : public Base {
public:
DECLARE_FUNCTION(baselua_interface, BASELUA_INTERFACE_LOAD);
DECLARE_FUNCTION(baselua_interface, BASELUA_INTERFACE_PRELOAD);
DECLARE_FUNCTION(baselua_interface, BASELUA_INTERFACE_LOADMODULE);
DECLARE_FUNCTION(baselua_interface, BASELUA_INTERFACE_UNLINK);
- DECLARE_FUNCTION(baselua_interface, BASELUA_INTERFACE_NEWTHREAD);
private:
static int baselua_interface_proceed_statics(Lua * L, int n, int caller);
- static void * spawn_thread(void *);
};
void Luabaselua_interface::pushstatics(Lua * L) throw (GeneralException ) {
@@ -327,30 +279,12 @@ void Luabaselua_interface::pushstatics(Lua * L) throw (GeneralException ) {
PUSH_FUNCTION(baselua_interface, BASELUA_INTERFACE_PRELOAD);
PUSH_FUNCTION(baselua_interface, BASELUA_INTERFACE_LOADMODULE);
PUSH_FUNCTION(baselua_interface, BASELUA_INTERFACE_UNLINK);
- PUSH_FUNCTION(baselua_interface, BASELUA_INTERFACE_NEWTHREAD);
-}
-
-void * sLua_baselua_interface::spawn_thread(void * _ti) {
- thread_info_t * ti = (thread_info_t *) _ti;
-
- try {
- ti->L->load(ti->execstr, true);
- }
- catch (GeneralException e) {
- printm(M_ERROR, "Got an exception during a thread: %s\n", e.GetMsg());
- }
-
- free(ti);
-
- return NULL;
}
int sLua_baselua_interface::baselua_interface_proceed_statics(Lua * L, int n, int caller) {
int r = 0;
String filename;
const char * t;
- thread_info_t * ti;
- pthread_t pt;
switch (caller) {
case BASELUA_INTERFACE_LOAD:
@@ -439,15 +373,6 @@ int sLua_baselua_interface::baselua_interface_proceed_statics(Lua * L, int n, in
L->push((lua_Number) unlink(t));
r = 1;
break;
- case BASELUA_INTERFACE_NEWTHREAD:
- ti = (thread_info_t *) malloc(sizeof(thread_info_t));
- ti->L = L->thread();
- ti->execstr = L->tostring(1).strdup();
- if (pthread_create(&pt, 0, sLua_baselua_interface::spawn_thread, ti)) {
- L->error("Error creating thread");
- }
- pthread_detach(pt);
- break;
}
return r;
}
@@ -594,7 +519,7 @@ CODE_BEGINS
/* That's the basic lua starter for non interactive mode */
Lua * start_basic_lua(bool nested = false) {
LUAJIT_VERSION_SYM();
- Lua * L = new threaded_Lua();
+ Lua * L = new Lua();
L->lock();
@@ -1015,8 +940,7 @@ virtual int startup() throw (GeneralException) {
if (interactive) {
if (mserver || tserver || hserver) {
- pthread_create(&interactive_thread, NULL, interactive_prompt, L->thread(true));
- L->pop();
+ pthread_create(&interactive_thread, NULL, interactive_prompt, L);
} else {
interactive_prompt(L);
}