diff mcabber/src/main.c @ 939:12fa2ae6445d

Get rid of "busy-waiting" (Christof Meerwald) This patch from Christof Meerwald, slightly modified, reduces mcabber CPU usage and the number of context switches per second.
author Mikael Berthe <mikael@lilotux.net>
date Tue, 11 Jul 2006 22:50:48 +0200
parents 40175f3dcef7
children fc30221b952d
line wrap: on
line diff
--- a/mcabber/src/main.c	Sat Jul 08 23:32:49 2006 +0200
+++ b/mcabber/src/main.c	Tue Jul 11 22:50:48 2006 +0200
@@ -235,10 +235,8 @@
   char *configFile = NULL;
   const char *optstring;
   int optval, optval2;
-  int key;
   unsigned int ping;
   int ret;
-  unsigned int refresh = 0;
   keycode kcode;
 
   credits();
@@ -330,27 +328,20 @@
   scr_LogPrint(LPRINT_DEBUG, "Entering into main loop...");
 
   for (ret = 0 ; ret != 255 ; ) {
+    scr_DoUpdate();
     scr_Getch(&kcode);
-    key = kcode.value;
 
-    /* The refresh is really an ugly hack, but we need to call doupdate()
-       from time to time to catch the RESIZE events, because getch keep
-       returning ERR until a real key is pressed :-(
-       However, it allows us to handle an autoaway check here...
-     */
-    if (key != ERR) {
+    if (kcode.value != ERR) {
       ret = process_key(kcode);
-      refresh = 0;
-    } else if (refresh++ > 1) {
-      doupdate();
-      refresh = 0;
+    } else {
       scr_CheckAutoAway(FALSE);
+
+      if (update_roster)
+	scr_DrawRoster();
+
+      scr_DoUpdate();
+      jb_main();
     }
-
-    if (key != KEY_RESIZE)
-      jb_main();
-    if (update_roster)
-      scr_DrawRoster();
   }
 
   jb_disconnect();