Mercurial > MadButterfly
diff src/X_main.c @ 49:6a3726fa7aad
Reduce times of invoking gettimeofday()
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sat, 09 Aug 2008 18:34:24 +0800 |
parents | bdf711cbf0fb |
children | 59a295651480 |
line wrap: on
line diff
--- 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);