diff options
Diffstat (limited to 'plugins/MirLua')
-rw-r--r-- | plugins/MirLua/src/m_schedule.cpp | 46 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.cpp | 1 |
2 files changed, 32 insertions, 15 deletions
diff --git a/plugins/MirLua/src/m_schedule.cpp b/plugins/MirLua/src/m_schedule.cpp index 8d2330f626..ca9a04e271 100644 --- a/plugins/MirLua/src/m_schedule.cpp +++ b/plugins/MirLua/src/m_schedule.cpp @@ -23,12 +23,39 @@ static int TaskCompare(const ScheduleTask *p1, const ScheduleTask *p2) static LIST<ScheduleTask> tasks(1, TaskCompare);
-void DestroyScheduleTask(ScheduleTask *task)
+void DestroyTask(ScheduleTask *task)
{
luaL_unref(task->L, LUA_REGISTRYINDEX, task->threadRef);
delete task;
}
+void ExecuteTaskThread(void *arg)
+{
+ ScheduleTask *task = (ScheduleTask*)arg;
+
+ lua_rawgeti(task->T, LUA_REGISTRYINDEX, task->callbackRef);
+ if (lua_pcall(task->T, 0, 2, 0))
+ CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(task->T, -1));
+
+ if (task->interval == 0)
+ {
+ DestroyTask(task);
+ return;
+ }
+
+ {
+ mir_cslock lock(threadLock);
+
+ time_t timestamp = time(NULL);
+ if(task->startTime + task->interval >= timestamp)
+ task->startTime += task->interval;
+ else
+ task->startTime = timestamp + task->interval;
+ tasks.insert(task);
+ }
+ SetEvent(hScheduleEvent);
+}
+
void ScheduleThread(void*)
{
time_t waitTime = INFINITE;
@@ -52,22 +79,11 @@ wait: WaitForSingleObject(hScheduleEvent, waitTime); if (task->endTime > 0 && task->endTime < timestamp)
{
- DestroyScheduleTask(task);
+ DestroyTask(task);
continue;
}
- lua_rawgeti(task->T, LUA_REGISTRYINDEX, task->callbackRef);
- if (lua_pcall(task->T, 0, 2, 0))
- CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(task->T, -1));
-
- if (task->interval == 0)
- {
- DestroyScheduleTask(task);
- continue;
- }
-
- task->startTime += task->interval;
- tasks.insert(task);
+ mir_forkthread(ExecuteTaskThread, task);
}
waitTime = INFINITE;
@@ -81,7 +97,7 @@ void KillModuleScheduleTasks() while (ScheduleTask *task = tasks[0])
{
tasks.remove(task);
- DestroyScheduleTask(task);
+ DestroyTask(task);
}
}
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index de7690356e..2b9ad5978e 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -67,6 +67,7 @@ void CMLua::Unload() ::KillModuleTTBButton();
::KillModuleIcons(hScriptsLangpack);
+ ::KillModuleSounds(hScriptsLangpack);
::KillModuleMenus(hScriptsLangpack);
::KillModuleHotkeys(hScriptsLangpack);
::KillObjectEventHooks(L);
|