call __mg_check_expired_timers in the idle handler

This commit is contained in:
Vincent Wei
2020-02-21 20:02:28 +08:00
parent 864be6b36d
commit c015eff8f0
3 changed files with 50 additions and 55 deletions

View File

@@ -410,7 +410,7 @@ BOOL client_IdleHandler4Client (PMSGQUEUE msg_queue, BOOL wait)
if ((n = select (msg_queue->maxfd + 1,
&rset, wsetptr, esetptr, &sel_timeout)) < 0) {
if (errno == EINTR) {
/* it is time to check message again. */
/* no event */
return FALSE;
}
__mg_err_sys ("client: select error");
@@ -428,6 +428,7 @@ BOOL client_IdleHandler4Client (PMSGQUEUE msg_queue, BOOL wait)
Msg.lParam = 0;
Msg.time = __mg_timer_counter;
kernel_QueueMessage (msg_queue, &Msg);
n++;
old_timer = __mg_timer_counter;
repeat_timeout = TIMEOUT_REPEAT;
@@ -455,14 +456,17 @@ BOOL client_IdleHandler4Client (PMSGQUEUE msg_queue, BOOL wait)
msg.message = MSG_MOUSEMOVE;
msg.wParam = buttons;
msg.lParam = MAKELONG(mouse_x, mouse_y);
QueueDeskMessage(&msg);
kernel_QueueMessage (msg_queue, &msg);
n++;
}
return FALSE;
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;
}
/* check fd only for HavePendingMessage function. */
else if (!wait)
return TRUE;
old_timer = __mg_timer_counter;
repeat_timeout = TIMEOUT_START_REPEAT;
@@ -472,32 +476,11 @@ BOOL client_IdleHandler4Client (PMSGQUEUE msg_queue, BOOL wait)
(OnTrylockClientReq && OnUnlockClientReq &&
!OnTrylockClientReq()))) {
#if 1
if ((nread = sock_read (conn_fd, &Msg, sizeof (MSG))) < 0) {
if (OnTrylockClientReq && OnUnlockClientReq)
OnUnlockClientReq();
__mg_err_sys ("client: read error on fd %d", conn_fd);
}
#else /* use recvmsg */
struct iovec iov[1];
struct msghdr msg;
iov[0].iov_base = &Msg;
iov[0].iov_len = sizeof (MSG);
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = iov;
msg.msg_iovlen = 1;
msg.msg_control = NULL;
msg.msg_controllen = 0;
if ((nread = sock_recvmsg (conn_fd, &msg, 0)) < 0) {
if (OnTrylockClientReq && OnUnlockClientReq)
OnUnlockClientReq();
__mg_err_sys ("client: read error on fd %d", conn_fd);
}
#endif
else if (nread == 0) {
if (OnTrylockClientReq && OnUnlockClientReq)
OnUnlockClientReq();
@@ -512,11 +495,11 @@ BOOL client_IdleHandler4Client (PMSGQUEUE msg_queue, BOOL wait)
}
/* go through registered listen fds */
__mg_kernel_check_listen_fds (msg_queue, &rset, wsetptr, esetptr);
n += __mg_kernel_check_listen_fds (msg_queue, &rset, wsetptr, esetptr);
check_live ();
return TRUE;
return (n > 0);
}
GHANDLE GUIAPI JoinLayer (const char* layer_name, const char* client_name,

View File

@@ -77,6 +77,7 @@
#include "server.h"
#include "sharedres.h"
#include "drawsemop.h"
#include "timer.h"
#include "license.h"
extern DWORD __mg_timer_counter;
@@ -343,7 +344,7 @@ void server_ServerCleanup (void)
BOOL server_IdleHandler4Server (PMSGQUEUE msg_queue, BOOL wait)
{
int i, n, clifd, nread;
int i, evt, clifd, nread;
pid_t pid;
uid_t uid;
struct timeval sel_timeout = {0, 0};
@@ -351,6 +352,7 @@ BOOL server_IdleHandler4Server (PMSGQUEUE msg_queue, BOOL wait)
fd_set* wsetptr = NULL;
fd_set* esetptr = NULL;
EXTRA_INPUT_EVENT extra; // Since 4.0.0; for extra input events
int nevts = 0; // Since 5.0.0; for timer and fd events
if (__mg_timer_counter != SHAREDRES_TIMER_COUNTER) {
__mg_timer_counter = SHAREDRES_TIMER_COUNTER;
@@ -379,7 +381,7 @@ BOOL server_IdleHandler4Server (PMSGQUEUE msg_queue, BOOL wait)
#endif
extra.params_mask = 0;
if ((n = IAL_WaitEvent (__mg_dsk_msg_queue->maxfd, &rset, wsetptr, esetptr,
if ((evt = IAL_WaitEvent (__mg_dsk_msg_queue->maxfd, &rset, wsetptr, esetptr,
wait?NULL:(&sel_timeout), &extra)) < 0) {
/* It is time to check event again. */
@@ -444,13 +446,10 @@ BOOL server_IdleHandler4Server (PMSGQUEUE msg_queue, BOOL wait)
}
}
if (!wait)
return (n > 0);
/* handle intput event (mouse/touch-screen or keyboard) */
if (n & IAL_MOUSEEVENT) ParseEvent (msg_queue, IAL_MOUSEEVENT);
if (n & IAL_KEYEVENT) ParseEvent (msg_queue, IAL_KEYEVENT);
if (n & IAL_EVENT_EXTRA) {
if (evt & IAL_MOUSEEVENT) ParseEvent (msg_queue, IAL_MOUSEEVENT);
if (evt & IAL_KEYEVENT) ParseEvent (msg_queue, IAL_KEYEVENT);
if (evt & IAL_EVENT_EXTRA) {
MSG msg;
msg.hwnd = HWND_DESKTOP;
msg.message = extra.event;
@@ -484,12 +483,19 @@ BOOL server_IdleHandler4Server (PMSGQUEUE msg_queue, BOOL wait)
kernel_QueueMessage (msg_queue, &msg);
}
}
else if (n == 0)
else if (evt == 0) {
ParseEvent (msg_queue, 0);
/* go through registered listening fds */
__mg_kernel_check_listen_fds (msg_queue, &rset, wsetptr, esetptr);
if (MG_UNLIKELY (msg_queue->old_tick_count == 0))
msg_queue->old_tick_count = SHAREDRES_TIMER_COUNTER;
return TRUE;
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);
}

View File

@@ -74,6 +74,7 @@
#include "cursor.h"
#include "event.h"
#include "menu.h"
#include "timer.h"
#include "ourhdr.h"
extern DWORD __mg_timer_counter;
@@ -191,7 +192,7 @@ void salone_StandAloneCleanup (void)
BOOL salone_IdleHandler4StandAlone (PMSGQUEUE msg_queue, BOOL wait)
{
int n;
int levt; // low input event flags
#ifdef __NOUNIX__
struct timeval sel_timeout = {0, 10000};
#elif defined (_MGGAL_BF533)
@@ -205,6 +206,7 @@ BOOL salone_IdleHandler4StandAlone (PMSGQUEUE msg_queue, BOOL wait)
fd_set* wsetptr = NULL;
fd_set* esetptr = NULL;
EXTRA_INPUT_EVENT extra; // Since 4.0.0; for extra input events
int nevts = 0; // Since 5.0.0; for timer and fd events
if (old_timer_counter != __mg_timer_counter) {
old_timer_counter = __mg_timer_counter;
@@ -227,7 +229,7 @@ BOOL salone_IdleHandler4StandAlone (PMSGQUEUE msg_queue, BOOL wait)
extra.params_mask = 0;
#ifdef __NOUNIX__
n = IAL_WaitEvent (msg_queue->maxfd, rsetptr, wsetptr, esetptr,
levt = IAL_WaitEvent (msg_queue->maxfd, rsetptr, wsetptr, esetptr,
wait?&sel_timeout:&sel_timeout_nd, &extra);
/* update __mg_timer_counter */
@@ -239,7 +241,7 @@ BOOL salone_IdleHandler4StandAlone (PMSGQUEUE msg_queue, BOOL wait)
__mg_timer_counter++;
}
#elif defined (_MGGAL_BF533)
n = IAL_WaitEvent (msg_queue->maxfd, rsetptr, wsetptr, esetptr,
levt = IAL_WaitEvent (msg_queue->maxfd, rsetptr, wsetptr, esetptr,
wait?&sel_timeout:&sel_timeout_nd, &extra);
/* update __mg_timer_counter */
@@ -247,26 +249,24 @@ BOOL salone_IdleHandler4StandAlone (PMSGQUEUE msg_queue, BOOL wait)
__mg_timer_counter += 1;
}
#else
n = IAL_WaitEvent (msg_queue->maxfd, rsetptr, wsetptr, esetptr,
levt = IAL_WaitEvent (msg_queue->maxfd, rsetptr, wsetptr, esetptr,
wait?&sel_timeout:&sel_timeout_nd, &extra);
/* update __mg_timer_counter */
__mg_timer_counter = __mg_os_get_time_ms()/10;
#endif
if (n < 0) {
if (levt < 0) {
/* It is time to check event again. */
if (errno == EINTR) {
ParseEvent (msg_queue, 0);
}
return FALSE;
}
else if (!wait)
return (n > 0);
/* handle intput event (mouse/touch-screen or keyboard) */
if (n & IAL_MOUSEEVENT) ParseEvent (msg_queue, IAL_MOUSEEVENT);
if (n & IAL_KEYEVENT) ParseEvent (msg_queue, IAL_KEYEVENT);
if (n & IAL_EVENT_EXTRA) {
if (levt & IAL_MOUSEEVENT) ParseEvent (msg_queue, IAL_MOUSEEVENT);
if (levt & IAL_KEYEVENT) ParseEvent (msg_queue, IAL_KEYEVENT);
if (levt & IAL_EVENT_EXTRA) {
MSG msg;
msg.hwnd = HWND_DESKTOP;
msg.message = extra.event;
@@ -300,13 +300,19 @@ BOOL salone_IdleHandler4StandAlone (PMSGQUEUE msg_queue, BOOL wait)
kernel_QueueMessage (msg_queue, &msg);
}
}
else if (n == 0)
else if (levt == 0) {
ParseEvent (msg_queue, 0);
/* go through registered listen fds */
__mg_kernel_check_listen_fds (msg_queue, &rset, wsetptr, esetptr);
if (MG_UNLIKELY (msg_queue->old_tick_count == 0))
msg_queue->old_tick_count = __mg_timer_counter;
nevts += __mg_check_expired_timers (msg_queue,
__mg_timer_counter - msg_queue->old_tick_count);
msg_queue->old_tick_count = __mg_timer_counter;
}
return (n > 0);
/* go through registered listen fds */
nevts += __mg_kernel_check_listen_fds (msg_queue, &rset, wsetptr, esetptr);
return (nevts > 0);
}
#if 0 /* deprecated code */