comparison 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
comparison
equal deleted inserted replaced
938:40175f3dcef7 939:12fa2ae6445d
233 int main(int argc, char **argv) 233 int main(int argc, char **argv)
234 { 234 {
235 char *configFile = NULL; 235 char *configFile = NULL;
236 const char *optstring; 236 const char *optstring;
237 int optval, optval2; 237 int optval, optval2;
238 int key;
239 unsigned int ping; 238 unsigned int ping;
240 int ret; 239 int ret;
241 unsigned int refresh = 0;
242 keycode kcode; 240 keycode kcode;
243 241
244 credits(); 242 credits();
245 243
246 signal(SIGTERM, sig_handler); 244 signal(SIGTERM, sig_handler);
328 } 326 }
329 327
330 scr_LogPrint(LPRINT_DEBUG, "Entering into main loop..."); 328 scr_LogPrint(LPRINT_DEBUG, "Entering into main loop...");
331 329
332 for (ret = 0 ; ret != 255 ; ) { 330 for (ret = 0 ; ret != 255 ; ) {
331 scr_DoUpdate();
333 scr_Getch(&kcode); 332 scr_Getch(&kcode);
334 key = kcode.value; 333
335 334 if (kcode.value != ERR) {
336 /* The refresh is really an ugly hack, but we need to call doupdate()
337 from time to time to catch the RESIZE events, because getch keep
338 returning ERR until a real key is pressed :-(
339 However, it allows us to handle an autoaway check here...
340 */
341 if (key != ERR) {
342 ret = process_key(kcode); 335 ret = process_key(kcode);
343 refresh = 0; 336 } else {
344 } else if (refresh++ > 1) {
345 doupdate();
346 refresh = 0;
347 scr_CheckAutoAway(FALSE); 337 scr_CheckAutoAway(FALSE);
338
339 if (update_roster)
340 scr_DrawRoster();
341
342 scr_DoUpdate();
343 jb_main();
348 } 344 }
349
350 if (key != KEY_RESIZE)
351 jb_main();
352 if (update_roster)
353 scr_DrawRoster();
354 } 345 }
355 346
356 jb_disconnect(); 347 jb_disconnect();
357 scr_TerminateCurses(); 348 scr_TerminateCurses();
358 349