diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-12-07 18:19:00 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-12-07 18:19:00 +0000 |
commit | 661ffca4a01883bb354e52624bed6d18be977058 (patch) | |
tree | 06c05f9f64e67615a5f8328a38c117ce1d0b2692 /plugins/MirLua/src | |
parent | b6e654822837e6c219daccea7f56761ebccdecda (diff) |
MirLua: tasks should run in thread
git-svn-id: http://svn.miranda-ng.org/main/trunk@15828 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src')
-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);
|