comparison src/modules/thread/LuaThread.cpp @ 1304:ee1448bb9680 minor

Fix race conditions and deadlocks in Channels (hopefully) (issue #554) Also, this is a giant commit because of the official Code Style (tm) was applied.
author Bart van Strien <bart.bes+projects@gmail.com>
date Wed, 30 Jan 2013 17:15:12 +0100
parents a74672ba1320
children 4ae1deb94765
comparison
equal deleted inserted replaced
1197:1a59c21cd2f3 1304:ee1448bb9680
28 28
29 namespace love 29 namespace love
30 { 30 {
31 namespace thread 31 namespace thread
32 { 32 {
33 LuaThread::LuaThread(const std::string &name, love::Data *code) 33 LuaThread::LuaThread(const std::string &name, love::Data *code)
34 : name(name), code(code) 34 : name(name), code(code)
35 { 35 {
36 code->retain(); 36 code->retain();
37 } 37 }
38 38
39 LuaThread::~LuaThread() 39 LuaThread::~LuaThread()
40 { 40 {
41 code->release(); 41 code->release();
42 } 42 }
43 43
44 void LuaThread::threadFunction() 44 void LuaThread::threadFunction()
45 { 45 {
46 this->retain(); 46 this->retain();
47 lua_State * L = lua_open(); 47 lua_State * L = lua_open();
48 luaL_openlibs(L); 48 luaL_openlibs(L);
49 #ifdef LOVE_BUILD_STANDALONE 49 #ifdef LOVE_BUILD_STANDALONE
50 love::luax_preload(L, luaopen_love, "love"); 50 love::luax_preload(L, luaopen_love, "love");
51 luaopen_love(L); 51 luaopen_love(L);
52 #endif // LOVE_BUILD_STANDALONE 52 #endif // LOVE_BUILD_STANDALONE
53 luaopen_love_thread(L); 53 luaopen_love_thread(L);
54 if (luaL_loadbuffer(L, (const char*) code->getData(), code->getSize(), name.c_str()) != 0) 54 if (luaL_loadbuffer(L, (const char *) code->getData(), code->getSize(), name.c_str()) != 0)
55 error = luax_tostring(L, -1);
56 else
57 if (lua_pcall(L, 0, 0, 0) != 0)
55 error = luax_tostring(L, -1); 58 error = luax_tostring(L, -1);
56 else 59 lua_close(L);
57 if (lua_pcall(L, 0, 0, 0) != 0) 60 this->release();
58 error = luax_tostring(L, -1); 61 }
59 lua_close(L);
60 this->release();
61 }
62 62
63 const std::string &LuaThread::getError() 63 const std::string &LuaThread::getError()
64 { 64 {
65 return error; 65 return error;
66 } 66 }
67 } // thread 67 } // thread
68 } // love 68 } // love