# HG changeset patch # User Thinker K.F. Li # Date 1218278064 -28800 # Node ID 6a3726fa7aadda10f4b92fab8b04ed21736115d3 # Parent bdf711cbf0fb1d07dde28a9d7724ed813a24d791 Reduce times of invoking gettimeofday() diff -r bdf711cbf0fb -r 6a3726fa7aad src/X_main.c --- a/src/X_main.c Sat Aug 09 18:26:20 2008 +0800 +++ b/src/X_main.c Sat Aug 09 18:34:24 2008 +0800 @@ -90,23 +90,25 @@ int nfds; struct timeval tmo; mb_timeval_t mb_tmo; - int r; + int r, r1; XSelectInput(display, win, PointerMotionMask | ExposureMask); XFlush(display); xcon = XConnectionNumber(display); nfds = xcon + 1; + + r = gettimeofday(&tmo, NULL); + if(r == -1) { + perror("gettimeofday"); + return; + } + MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); + while(1) { FD_ZERO(&rds); FD_SET(xcon, &rds); - r = gettimeofday(&tmo, NULL); - if(r == -1) { - perror("gettimeofday"); - return; - } - MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); r = mb_tman_next_timeout(tman, &mb_tmo, &mb_tmo); if(r != OK) r = select(nfds, &rds, NULL, NULL, NULL); @@ -120,12 +122,15 @@ perror("select"); return; } + + r1 = gettimeofday(&tmo, NULL); + if(r1 == -1) { + perror("gettimeofday"); + return; + } + MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); + if(r == 0) { - r = gettimeofday(&tmo, NULL); - if(r == -1) { - perror("gettimeofday"); - return; - } MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); mb_tman_handle_timeout(tman, &mb_tmo); rdman_redraw_changed(rdman);