Mercurial > MadButterfly
comparison 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 |
comparison
equal
deleted
inserted
replaced
48:bdf711cbf0fb | 49:6a3726fa7aad |
---|---|
88 int xcon; | 88 int xcon; |
89 fd_set rds; | 89 fd_set rds; |
90 int nfds; | 90 int nfds; |
91 struct timeval tmo; | 91 struct timeval tmo; |
92 mb_timeval_t mb_tmo; | 92 mb_timeval_t mb_tmo; |
93 int r; | 93 int r, r1; |
94 | 94 |
95 XSelectInput(display, win, PointerMotionMask | ExposureMask); | 95 XSelectInput(display, win, PointerMotionMask | ExposureMask); |
96 XFlush(display); | 96 XFlush(display); |
97 | 97 |
98 xcon = XConnectionNumber(display); | 98 xcon = XConnectionNumber(display); |
99 nfds = xcon + 1; | 99 nfds = xcon + 1; |
100 | |
101 r = gettimeofday(&tmo, NULL); | |
102 if(r == -1) { | |
103 perror("gettimeofday"); | |
104 return; | |
105 } | |
106 MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); | |
107 | |
100 while(1) { | 108 while(1) { |
101 FD_ZERO(&rds); | 109 FD_ZERO(&rds); |
102 FD_SET(xcon, &rds); | 110 FD_SET(xcon, &rds); |
103 r = gettimeofday(&tmo, NULL); | 111 |
104 if(r == -1) { | |
105 perror("gettimeofday"); | |
106 return; | |
107 } | |
108 | |
109 MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); | |
110 r = mb_tman_next_timeout(tman, &mb_tmo, &mb_tmo); | 112 r = mb_tman_next_timeout(tman, &mb_tmo, &mb_tmo); |
111 if(r != OK) | 113 if(r != OK) |
112 r = select(nfds, &rds, NULL, NULL, NULL); | 114 r = select(nfds, &rds, NULL, NULL, NULL); |
113 else { | 115 else { |
114 tmo.tv_sec = MB_TIMEVAL_SEC(&mb_tmo); | 116 tmo.tv_sec = MB_TIMEVAL_SEC(&mb_tmo); |
118 | 120 |
119 if(r == -1) { | 121 if(r == -1) { |
120 perror("select"); | 122 perror("select"); |
121 return; | 123 return; |
122 } | 124 } |
125 | |
126 r1 = gettimeofday(&tmo, NULL); | |
127 if(r1 == -1) { | |
128 perror("gettimeofday"); | |
129 return; | |
130 } | |
131 MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); | |
132 | |
123 if(r == 0) { | 133 if(r == 0) { |
124 r = gettimeofday(&tmo, NULL); | |
125 if(r == -1) { | |
126 perror("gettimeofday"); | |
127 return; | |
128 } | |
129 MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); | 134 MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); |
130 mb_tman_handle_timeout(tman, &mb_tmo); | 135 mb_tman_handle_timeout(tman, &mb_tmo); |
131 rdman_redraw_changed(rdman); | 136 rdman_redraw_changed(rdman); |
132 XFlush(display); | 137 XFlush(display); |
133 } else if(FD_ISSET(xcon, &rds)) { | 138 } else if(FD_ISSET(xcon, &rds)) { |