diff --git a/ReadMe.txt b/ReadMe.txt index edfa85c..bd747ac 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -71,6 +71,7 @@ Version 2.0 (2020-11-XX) - Fix transparency issue (RGB -> BGR). - Fix a printer issue from Christoph Gießelink's HP82240B Printer Simulator version 1.12. - Fix the KML button Type 3 with a Background offset which was not display at the right location (Fix #15). +- Fix a timer issue. Version 1.9 (2020-09-07) diff --git a/app/src/main/assets/ReadMe.txt b/app/src/main/assets/ReadMe.txt index 9e9c9b1..4f15d42 100644 --- a/app/src/main/assets/ReadMe.txt +++ b/app/src/main/assets/ReadMe.txt @@ -71,6 +71,7 @@ Version 2.0 (2020-11-XX) - Fix transparency issue (RGB -> BGR). - Fix a printer issue from Christoph Gießelink's HP82240B Printer Simulator version 1.12. - Fix the KML button Type 3 with a Background offset which was not display at the right location (Fix #15). +- Fix a timer issue. Version 1.9 (2020-09-07) diff --git a/app/src/main/cpp/win32-layer.c b/app/src/main/cpp/win32-layer.c index a1d5d38..1ce2db3 100644 --- a/app/src/main/cpp/win32-layer.c +++ b/app/src/main/cpp/win32-layer.c @@ -2631,6 +2631,14 @@ static void initTimer() { lastTimerId = 0; } +static void dumpTimers() { + TIMER_LOGD("dumpTimers()"); + for (struct timerEvent * nextTimer = timersList.next; nextTimer != &timersList; nextTimer = nextTimer->next) { + TIMER_LOGD("\ttimerId: %d (%x), uDelay: %d, dwUser: %d, fuEvent: %d, triggerTime: %ld)", + nextTimer->timerId, nextTimer, nextTimer->uDelay, nextTimer->dwUser, nextTimer->fuEvent, nextTimer->triggerTime); + } +} + MMRESULT timeKillEvent(UINT uTimerID) { TIMER_LOGD("timeKillEvent(uTimerID: [%d])", uTimerID); @@ -2647,10 +2655,14 @@ MMRESULT timeKillEvent(UINT uTimerID) { break; } } +#if defined(TIMER_LOGD) + dumpTimers(); +#endif if(timersList.next == &timersList) { // The list is empty // Leave the thread? timerThreadToEnd = TRUE; + TIMER_LOGD("timeKillEvent(uTimerID: [%d]) timerThreadToEnd = TRUE ", uTimerID); } pthread_mutex_unlock(&timerEventsLock); @@ -2672,18 +2684,15 @@ static void insertTimer(struct timerEvent * newTimer) { newTimer->prev = nextTimer->prev; nextTimer->prev->next = newTimer; nextTimer->prev = newTimer; -} -static void dumpTimers() { - TIMER_LOGD("dumpTimers()"); - for (struct timerEvent * nextTimer = timersList.next; nextTimer != &timersList; nextTimer = nextTimer->next) { - TIMER_LOGD("\ttimerId: %d (%x), uDelay: %d, dwUser: %d, fuEvent: %d, triggerTime: %ld)", - nextTimer->timerId, nextTimer, nextTimer->uDelay, nextTimer->dwUser, nextTimer->fuEvent, nextTimer->triggerTime); - } +#if defined(TIMER_LOGD) + dumpTimers(); +#endif } static void timerThreadStart(LPVOID lpThreadParameter) { - pthread_mutex_lock(&timerEventsLock); + LOGD("timerThreadStart() START"); + pthread_mutex_lock(&timerEventsLock); while (!timerThreadToEnd) { TIMER_LOGD("timerThreadStart() %ld", GetTickCount64()); @@ -2737,12 +2746,13 @@ static void timerThreadStart(LPVOID lpThreadParameter) { continue; pthread_mutex_unlock(&timerEventsLock); - Sleep(sleep_time); + Sleep(sleep_time > 100 ? 100 : sleep_time); pthread_mutex_lock(&timerEventsLock); } timerThreadId = 0; pthread_mutex_unlock(&timerEventsLock); jniDetachCurrentThread(); + LOGD("timerThreadStart() END"); } MMRESULT timeSetEvent(UINT uDelay, UINT uResolution, LPTIMECALLBACK fptc, DWORD_PTR dwUser, UINT fuEvent) { @@ -2767,6 +2777,7 @@ MMRESULT timeSetEvent(UINT uDelay, UINT uResolution, LPTIMECALLBACK fptc, DWORD_ if(!timerThreadId) { // If not yet created, create the thread which will handle all the timers + LOGD("timeSetEvent() pthread_create"); if (pthread_create(&timerThreadId, NULL, (void *(*)(void *)) timerThreadStart, NULL) != 0) { LOGD("timeSetEvent() ERROR in pthread_create, errno: %d (EAGAIN 11 / EINVAL 22 / EPERM 1)", errno); // EAGAIN Insufficient resources to create another thread.