always check timers in the idle handler

This commit is contained in:
Vincent Wei
2020-02-25 17:16:09 +08:00
parent 2d9b3a68b5
commit 0e9b23efec
4 changed files with 60 additions and 77 deletions
+5 -6
View File
@@ -465,14 +465,13 @@ BOOL client_IdleHandler4Client (PMSGQUEUE msg_queue, BOOL wait)
n++;
}
if (MG_UNLIKELY (msg_queue->old_tick_count == 0))
msg_queue->old_tick_count = SHAREDRES_TIMER_COUNTER;
n += __mg_check_expired_timers (msg_queue,
SHAREDRES_TIMER_COUNTER - msg_queue->old_tick_count);
msg_queue->old_tick_count = SHAREDRES_TIMER_COUNTER;
}
/* Since 5.0.0: always check timer */
n += __mg_check_expired_timers (msg_queue,
SHAREDRES_TIMER_COUNTER - msg_queue->old_tick_count);
msg_queue->old_tick_count = SHAREDRES_TIMER_COUNTER;
old_timer = __mg_tick_counter;
repeat_timeout = TIMEOUT_START_REPEAT;
+7 -29
View File
@@ -287,26 +287,15 @@ static BOOL std_idle_handler (MSGQUEUE* msg_queue, BOOL wait)
}
return FALSE;
}
else if (retval == 0) {
if (MG_UNLIKELY (msg_queue->old_tick_count == 0))
msg_queue->old_tick_count = __mg_tick_counter;
n += __mg_check_expired_timers (msg_queue,
__mg_tick_counter - msg_queue->old_tick_count);
msg_queue->old_tick_count = __mg_tick_counter;
}
else if (rsetptr || wsetptr || esetptr) {
n += __mg_check_expired_timers (msg_queue,
__mg_tick_counter - msg_queue->old_tick_count);
msg_queue->old_tick_count = __mg_tick_counter;
if (rsetptr || wsetptr || esetptr) {
n += __mg_kernel_check_listen_fds (msg_queue, rsetptr, wsetptr, esetptr);
}
#if 0
if (wait && n == 0) {
n = handle_idle_message (msg_queue);
}
else {
msg_queue->idle_counter = 0;
}
#endif
return n > 0;
}
@@ -327,21 +316,9 @@ static BOOL std_idle_handler (MSGQUEUE* msg_queue, BOOL wait)
if (timeout_ms > 0)
__mg_os_time_delay (timeout_ms);
if (MG_UNLIKELY (msg_queue->old_tick_count == 0))
msg_queue->old_tick_count = __mg_tick_counter;
n = __mg_check_expired_timers (msg_queue,
__mg_tick_counter - msg_queue->old_tick_count);
msg_queue->old_tick_count = __mg_tick_counter;
#if 0
if (wait && n == 0) {
n = handle_idle_message (msg_queue);
}
else {
msg_queue->idle_counter = 0;
}
#endif
return n > 0;
}
@@ -381,6 +358,7 @@ BOOL mg_InitMsgQueue (PMSGQUEUE pMsgQueue, int iBufferLen)
// pMsgQueue->first_timer_slot = 0;
// pMsgQueue->expired_timer_mask = 0;
// memset (pMsgQueue->timer_slots, 0, sizeof (pMsgQueue->timer_slots));
pMsgQueue->old_tick_count = __mg_tick_counter;
#ifdef HAVE_SELECT
/* Since 5.0.0, MiniGUI supports listening file descriptors
+23 -12
View File
@@ -450,8 +450,14 @@ BOOL server_IdleHandler4Server (PMSGQUEUE msg_queue, BOOL wait)
}
/* handle intput event (mouse/touch-screen or keyboard) */
if (evt & IAL_MOUSEEVENT) ParseEvent (msg_queue, IAL_MOUSEEVENT);
if (evt & IAL_KEYEVENT) ParseEvent (msg_queue, IAL_KEYEVENT);
if (evt & IAL_MOUSEEVENT) {
ParseEvent (msg_queue, IAL_MOUSEEVENT);
nevts++;
}
if (evt & IAL_KEYEVENT) {
ParseEvent (msg_queue, IAL_KEYEVENT);
nevts++;
}
if (evt & IAL_EVENT_EXTRA) {
MSG msg;
msg.hwnd = HWND_DESKTOP;
@@ -467,8 +473,10 @@ BOOL server_IdleHandler4Server (PMSGQUEUE msg_queue, BOOL wait)
msg.wParam = extra.wparams[i];
msg.lParam = extra.lparams[i];
if (__mg_check_hook_func (HOOK_EVENT_EXTRA, &msg) ==
HOOK_GOON)
HOOK_GOON) {
kernel_QueueMessage (msg_queue, &msg);
nevts++;
}
n++;
}
}
@@ -477,26 +485,29 @@ BOOL server_IdleHandler4Server (PMSGQUEUE msg_queue, BOOL wait)
msg.message = MSG_EXIN_END_CHANGES;
msg.wParam = n;
msg.lParam = 0;
if (__mg_check_hook_func (HOOK_EVENT_EXTRA, &msg) == HOOK_GOON)
if (__mg_check_hook_func (HOOK_EVENT_EXTRA, &msg) ==
HOOK_GOON) {
kernel_QueueMessage (msg_queue, &msg);
nevts++;
}
}
}
else {
if (__mg_check_hook_func (HOOK_EVENT_EXTRA, &msg) == HOOK_GOON)
if (__mg_check_hook_func (HOOK_EVENT_EXTRA, &msg) == HOOK_GOON) {
kernel_QueueMessage (msg_queue, &msg);
nevts++;
}
}
}
else if (evt == 0) {
ParseEvent (msg_queue, 0);
if (MG_UNLIKELY (msg_queue->old_tick_count == 0))
msg_queue->old_tick_count = SHAREDRES_TIMER_COUNTER;
nevts += __mg_check_expired_timers (msg_queue,
SHAREDRES_TIMER_COUNTER - msg_queue->old_tick_count);
msg_queue->old_tick_count = SHAREDRES_TIMER_COUNTER;
}
/* Since 5.0.0: Always check timers */
nevts += __mg_check_expired_timers (msg_queue,
SHAREDRES_TIMER_COUNTER - msg_queue->old_tick_count);
msg_queue->old_tick_count = SHAREDRES_TIMER_COUNTER;
/* go through registered listening fds */
nevts += __mg_kernel_check_listen_fds (msg_queue, &rset, wsetptr, esetptr);
return (nevts > 0);
+25 -30
View File
@@ -176,9 +176,6 @@ static void ParseEvent (PMSGQUEUE msg_que, int event)
}
}
extern void __mg_os_start_time_ms(void);
extern DWORD __mg_os_get_time_ms(void);
BOOL GUIAPI salone_StandAloneStartup (void)
{
/* VW: do not use signal based interval timer; since 4.0 */
@@ -238,28 +235,12 @@ BOOL salone_IdleHandler4StandAlone (PMSGQUEUE msg_queue, BOOL wait)
#ifdef __NOUNIX__
levt = IAL_WaitEvent (msg_queue->maxfd, rsetptr, wsetptr, esetptr,
wait?&sel_timeout:&sel_timeout_nd, &extra);
/* update __mg_tick_counter */
if (wait) {
//__mg_tick_counter += 10;
/**
10 is too fast, the "repeat_threshold" is 5, use ++, repeate 5 times
**/
__mg_tick_counter++;
}
#elif defined (_MGGAL_BF533)
levt = IAL_WaitEvent (msg_queue->maxfd, rsetptr, wsetptr, esetptr,
wait?&sel_timeout:&sel_timeout_nd, &extra);
/* update __mg_tick_counter */
if (wait) {
__mg_tick_counter += 1;
}
#else
levt = IAL_WaitEvent (msg_queue->maxfd, rsetptr, wsetptr, esetptr,
wait?&sel_timeout:&sel_timeout_nd, &extra);
/* update __mg_tick_counter */
__mg_tick_counter = __mg_os_get_time_ms()/10;
#endif
if (levt < 0) {
@@ -271,8 +252,14 @@ BOOL salone_IdleHandler4StandAlone (PMSGQUEUE msg_queue, BOOL wait)
}
/* handle intput event (mouse/touch-screen or keyboard) */
if (levt & IAL_MOUSEEVENT) ParseEvent (msg_queue, IAL_MOUSEEVENT);
if (levt & IAL_KEYEVENT) ParseEvent (msg_queue, IAL_KEYEVENT);
if (levt & IAL_MOUSEEVENT) {
nevts++;
ParseEvent (msg_queue, IAL_MOUSEEVENT);
}
if (levt & IAL_KEYEVENT) {
nevts++;
ParseEvent (msg_queue, IAL_KEYEVENT);
}
if (levt & IAL_EVENT_EXTRA) {
MSG msg;
msg.hwnd = HWND_DESKTOP;
@@ -288,35 +275,43 @@ BOOL salone_IdleHandler4StandAlone (PMSGQUEUE msg_queue, BOOL wait)
msg.wParam = extra.wparams[i];
msg.lParam = extra.lparams[i];
if (__mg_check_hook_func (HOOK_EVENT_EXTRA, &msg) ==
HOOK_GOON)
HOOK_GOON) {
kernel_QueueMessage (msg_queue, &msg);
nevts++;
}
n++;
}
}
if (n > 0) {
msg.message = MSG_EXIN_END_CHANGES;
msg.wParam = n;
msg.lParam = 0;
if (__mg_check_hook_func (HOOK_EVENT_EXTRA, &msg) == HOOK_GOON)
if (__mg_check_hook_func (HOOK_EVENT_EXTRA, &msg) == HOOK_GOON) {
kernel_QueueMessage (msg_queue, &msg);
nevts++;
}
}
}
else {
if (__mg_check_hook_func (HOOK_EVENT_EXTRA, &msg) == HOOK_GOON)
if (__mg_check_hook_func (HOOK_EVENT_EXTRA, &msg) == HOOK_GOON) {
kernel_QueueMessage (msg_queue, &msg);
nevts++;
}
}
}
else if (levt == 0) {
ParseEvent (msg_queue, 0);
if (MG_UNLIKELY (msg_queue->old_tick_count == 0))
msg_queue->old_tick_count = __mg_tick_counter;
nevts += __mg_check_expired_timers (msg_queue,
__mg_tick_counter - msg_queue->old_tick_count);
msg_queue->old_tick_count = __mg_tick_counter;
}
/* Since 5.0.0: always check timers */
__mg_update_tick_count (NULL);
nevts += __mg_check_expired_timers (msg_queue,
__mg_tick_counter - msg_queue->old_tick_count);
msg_queue->old_tick_count = __mg_tick_counter;
/* go through registered listen fds */
nevts += __mg_kernel_check_listen_fds (msg_queue, &rset, wsetptr, esetptr);
return (nevts > 0);