| 5997 | } |
| 5998 | |
| 5999 | static int emu_exec_time(lua_State *L) |
| 6000 | { |
| 6001 | int count = (int)luaL_checkinteger(L,1); |
| 6002 | |
| 6003 | readyEvent = CreateEvent(0,true,false,0); |
| 6004 | goEvent = CreateEvent(0,true,false,0); |
| 6005 | DWORD threadid; |
| 6006 | HANDLE thread = CreateThread(0,0,emu_exec_time_proc,(LPVOID)L,0,&threadid); |
| 6007 | SetThreadAffinityMask(thread,1); |
| 6008 | //wait for the lua thread to start |
| 6009 | WaitForSingleObject(readyEvent,INFINITE); |
| 6010 | ResetEvent(readyEvent); |
| 6011 | //tell the lua thread to proceed |
| 6012 | SetEvent(goEvent); |
| 6013 | //wait for the lua thread to finish, but no more than the specified amount of time |
| 6014 | WaitForSingleObject(readyEvent,count); |
| 6015 | |
| 6016 | //kill lua (if it hasnt already been killed) |
| 6017 | lua_sethook(L, emu_exec_time_hook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); |
| 6018 | |
| 6019 | //keep on waiting for the lua thread to come back |
| 6020 | WaitForSingleObject(readyEvent,count); |
| 6021 | |
| 6022 | //clear the lua thread-killer |
| 6023 | lua_sethook(L, NULL, 0, 0); |
| 6024 | |
| 6025 | CloseHandle(readyEvent); |
| 6026 | CloseHandle(goEvent); |
| 6027 | CloseHandle(thread); |
| 6028 | |
| 6029 | return 1; |
| 6030 | } |
| 6031 | |
| 6032 | #else |
| 6033 | static int emu_exec_time(lua_State *L) { return 0; } |
nothing calls this directly
no test coverage detected