[hackers] [st] Remove timeout in the main loop || "Roberto E. Vargas Caballero"

From: <hg_AT_suckless.org>
Date: Sun, 16 Sep 2012 12:25:53 +0200 (CEST)

changeset: 305:d07c4a426bc3
user: "Roberto E. Vargas Caballero" <k0ga_AT_shike2.com>
date: Sun Sep 16 10:47:21 2012 +0200
files: TODO st.c
description:
Remove timeout in the main loop
The main loop waits until there is some data to read in file descriptors of
the X server or the pseudo tty. But it uses a timeout in select(), which
causes that st awake each 20 ms, even it doesn't have something to do. This
patch removes this problem removing the timeout, which is not needed.
---
 TODO |    1 -
 st.c |   27 +++------------------------
 2 files changed, 3 insertions(+), 25 deletions(-)
diff -r c1b9fca11b7a -r d07c4a426bc3 TODO
--- a/TODO	Sun Sep 16 10:46:08 2012 +0200
+++ b/TODO	Sun Sep 16 10:47:21 2012 +0200
_AT_@ -15,7 +15,6 @@
 
 * clean selection code
 * clean and complete terminfo entry
-* remove the timeouts in the main loop
 
 bugs
 ----
diff -r c1b9fca11b7a -r d07c4a426bc3 st.c
--- a/st.c	Sun Sep 16 10:46:08 2012 +0200
+++ b/st.c	Sun Sep 16 10:47:21 2012 +0200
_AT_@ -53,8 +53,6 @@
 #define XK_NO_MOD     UINT_MAX
 #define XK_ANY_MOD    0
 
-#define SELECT_TIMEOUT (20*1000) /* 20 ms */
-#define DRAW_TIMEOUT  (20*1000) /* 20 ms */
 #define REDRAW_TIMEOUT (80*1000) /* 80 ms */
 
 #define SERRNO strerror(errno)
_AT_@ -205,7 +203,6 @@
 	int ch; /* char height */
 	int cw; /* char width  */
 	char state; /* focus, redraw, visible */
-	struct timeval lastdraw;
 } XWindow;
 
 typedef struct {
_AT_@ -250,7 +247,6 @@
 static void execsh(void);
 static void sigchld(int);
 static void run(void);
-static bool last_draw_too_old(void);
 
 static void csidump(void);
 static void csihandle(void);
_AT_@ -2158,7 +2154,6 @@
 draw() {
 	drawregion(0, 0, term.col, term.row);
 	xcopy();
-	gettimeofday(&xw.lastdraw, NULL);
 }
 
 void
_AT_@ -2345,41 +2340,25 @@
 	ttyresize(col, row);
 }
 
-bool
-last_draw_too_old(void) {
-	struct timeval now;
-	gettimeofday(&now, NULL);
-	return TIMEDIFF(now, xw.lastdraw) >= DRAW_TIMEOUT/1000;
-}
-
 void
 run(void) {
 	XEvent ev;
 	fd_set rfd;
 	int xfd = XConnectionNumber(xw.dpy);
-	struct timeval timeout = {0};
-	bool stuff_to_print = 0;
 
 	for(;;) {
 		FD_ZERO(&rfd);
 		FD_SET(cmdfd, &rfd);
 		FD_SET(xfd, &rfd);
-		timeout.tv_sec  = 0;
-		timeout.tv_usec = SELECT_TIMEOUT;
-		if(select(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, &timeout) < 0) {
+		if(select(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, NULL) < 0) {
 			if(errno == EINTR)
 				continue;
 			die("select failed: %s\n", SERRNO);
 		}
-		if(FD_ISSET(cmdfd, &rfd)) {
+		if(FD_ISSET(cmdfd, &rfd))
 			ttyread();
-			stuff_to_print = 1;
-		}
 
-		if(stuff_to_print && last_draw_too_old()) {
-			stuff_to_print = 0;
-			draw();
-		}
+		draw();
 
 		while(XPending(xw.dpy)) {
 			XNextEvent(xw.dpy, &ev);
Received on Sun Sep 16 2012 - 12:25:53 CEST

This archive was generated by hypermail 2.3.0 : Sun Sep 16 2012 - 12:36:08 CEST