diff --git a/src/kernel/desktop-ths.c b/src/kernel/desktop-ths.c index eb4b4773..7fa5b203 100644 --- a/src/kernel/desktop-ths.c +++ b/src/kernel/desktop-ths.c @@ -142,28 +142,28 @@ BOOL mg_InitDesktop (void) #include "debug.h" -static IDLEHANDLER std_idle_handler; - +/* According to a bug report, we use sem_timedwait() instead of + calling std_idle_handler for desktop thread. + Otherwise, the desktop might not handle the request from other GUI threads + as soon as possible. */ static BOOL idle_handler_for_desktop_thread (MSGQUEUE *msg_queue, BOOL wait) { int retv, n = 0; __mg_update_tick_count (msg_queue); - n += __mg_check_expired_timers (msg_queue, - __mg_tick_counter - msg_queue->old_tick_count); - msg_queue->old_tick_count = __mg_tick_counter; + if (wait) { + struct timespec ts; + if (clock_gettime (CLOCK_REALTIME, &ts) != -1) { + ts.tv_nsec += 10 * 1000 * 1000L; // 10ms + if (ts.tv_nsec >= 1000 * 1000 * 1000L) { + ts.tv_sec += 1; + ts.tv_nsec -= 1000 * 1000 * 1000L; + } - struct timespec ts; - if (clock_gettime(CLOCK_REALTIME, &ts) != -1) { - ts.tv_nsec += 10 * 1000 * 1000L; // 10ms - if (ts.tv_nsec >= 1000 * 1000 * 1000L) { - ts.tv_sec += 1; - ts.tv_nsec -= 1000 * 1000 * 1000L; + if (sem_timedwait (&msg_queue->wait, &ts) == 0) + return TRUE; } - - if (sem_timedwait(&msg_queue->wait, &ts) == 0) - return TRUE; } return n > 0; @@ -182,7 +182,6 @@ void* __kernel_desktop_main (void* data) /* For bug reported in Issue #116, under threads mode, the idle handler for the desktop thread should call __mg_update_tick_count () */ - std_idle_handler = __mg_dsk_msg_queue->OnIdle; __mg_dsk_msg_queue->OnIdle = idle_handler_for_desktop_thread; /* init desktop window */ diff --git a/src/kernel/timer.c b/src/kernel/timer.c index 7fd1ab75..60b51d68 100644 --- a/src/kernel/timer.c +++ b/src/kernel/timer.c @@ -100,14 +100,14 @@ DWORD __mg_update_tick_count (MSGQUEUE* msg_queue) /* Since 5.0.0, the desktop only handles caret blinking in MSG_TIMEOUT message, and the interval for the timer of desktop changes to 0.05s. */ - if (msg_queue == __mg_dsk_msg_queue) { - if (ticks > __mg_dsk_msg_queue->last_ticks + + if (msg_queue == __mg_dsk_msg_queue && + ticks > __mg_dsk_msg_queue->old_tick_count + DESKTOP_TIMER_INERTVAL) { - __mg_dsk_msg_queue->dwState |= QS_DESKTIMER; + __mg_dsk_msg_queue->dwState |= QS_DESKTIMER; #ifdef _MGRM_THREADS /* only wake up desktop for threads mode */ - POST_MSGQ (__mg_dsk_msg_queue); + POST_MSGQ (__mg_dsk_msg_queue); #endif - } + __mg_dsk_msg_queue->old_tick_count = ticks; } msg_queue->last_ticks = ticks;