nsxiv633a4f6
check_timeouts: avoid unnecessary conversions (#273)
before we were using select, which expected `struct timeval` as arg. so we needed to do ms -> timeval conversions. but now since we're using poll, which accepts milisec as arg, there's no need to do ms -> timeval -> ms. instead have check_timeouts directly return ms.
+4 −10
2 files changed
| @@ -207,7 +207,7 @@ void reset_timeout(timeout_f handler) | |||
| 207 | 207 | } | |
| 208 | 208 | } | |
| 209 | 209 | ||
| 210 | − | static bool check_timeouts(struct timeval *t) | |
| 210 | + | static bool check_timeouts(int *t) | |
| 211 | 211 | { | |
| 212 | 212 | int i = 0, tdiff, tmin = -1; | |
| 213 | 213 | struct timeval now; | |
| @@ -228,7 +228,7 @@ static bool check_timeouts(struct timeval *t) | |||
| 228 | 228 | i++; | |
| 229 | 229 | } | |
| 230 | 230 | if (tmin > 0 && t != NULL) | |
| 231 | − | TV_SET_MSEC(t, tmin); | |
| 231 | + | *t = tmin; | |
| 232 | 232 | return tmin > 0; | |
| 233 | 233 | } | |
| 234 | 234 | ||
| @@ -703,7 +703,7 @@ static void run(void) | |||
| 703 | 703 | { | |
| 704 | 704 | enum { FD_X, FD_INFO, FD_ARL, FD_CNT }; | |
| 705 | 705 | struct pollfd pfd[FD_CNT]; | |
| 706 | − | struct timeval timeout = {0}; | |
| 706 | + | int timeout = 0; | |
| 707 | 707 | const struct timespec ten_ms = {0, 10000000}; | |
| 708 | 708 | bool discard, init_thumb, load_thumb, to_set; | |
| 709 | 709 | XEvent ev, nextev; | |
| @@ -735,7 +735,7 @@ static void run(void) | |||
| 735 | 735 | pfd[FD_ARL].fd = arl.fd; | |
| 736 | 736 | pfd[FD_X].events = pfd[FD_INFO].events = pfd[FD_ARL].events = POLLIN; | |
| 737 | 737 | ||
| 738 | − | if (poll(pfd, ARRLEN(pfd), to_set ? TV_TO_MS(&timeout) : -1) < 0) | |
| 738 | + | if (poll(pfd, ARRLEN(pfd), to_set ? timeout : -1) < 0) | |
| 739 | 739 | continue; | |
| 740 | 740 | if (pfd[FD_INFO].revents & POLLIN) | |
| 741 | 741 | read_info(); | |
| @@ -44,12 +44,6 @@ | |||
| 44 | 44 | ||
| 45 | 45 | #define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \ | |
| 46 | 46 | ((t1)->tv_usec - (t2)->tv_usec) / 1000) | |
| 47 | − | #define TV_TO_MS(tv) (((tv)->tv_sec * 1000) + ((tv)->tv_usec / 1000)) | |
| 48 | − | ||
| 49 | − | #define TV_SET_MSEC(tv,t) { \ | |
| 50 | − | (tv)->tv_sec = (t) / 1000; \ | |
| 51 | − | (tv)->tv_usec = (t) % 1000 * 1000; \ | |
| 52 | − | } | |
| 53 | 47 | ||
| 54 | 48 | #define TV_ADD_MSEC(tv,t) { \ | |
| 55 | 49 | (tv)->tv_sec += (t) / 1000; \ | |