fix a bug: MSG_TIMEOUT for desktop thread was not fired correctly

This commit is contained in:
Vincent Wei
2025-05-27 14:45:53 +08:00
parent 4c55f2eac3
commit b7525f3001
2 changed files with 19 additions and 20 deletions
+14 -15
View File
@@ -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 */
+5 -5
View File
@@ -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;