wmwifi: call usleep() directly in main loop

I noticed using powertop that the number of wakeups per second
generated by wmwifi did not correlate well with the update interval,
where I'd expect approximately 1 wakeup if the update interval was 1 sec.

Strangely enough, calling the function

dockapp_nextevent_or_timeout(&event, update_interval * 1000)

in the main loop (note that I already replaced * 100 by * 1000 above)
with update_interval = 1 generates around 15 wakeups/sec here.

Calling usleep() in the loop instead leads to fewer wakeups, around 1/sec.

Signed-off-by: Carlos R. Mafra <crmafra@gmail.com>
This commit is contained in:
Carlos R. Mafra 2019-01-12 15:22:06 +00:00
parent 742d4deddf
commit 1e34ea7f98

View file

@ -65,6 +65,7 @@ struct theme {
struct theme tcur; struct theme tcur;
struct theme blgt; struct theme blgt;
struct wifi lwfi; struct wifi lwfi;
time_t last_update = 0;
/* prototypes */ /* prototypes */
static void update(struct wifi *wfi); static void update(struct wifi *wfi);
@ -122,36 +123,36 @@ int main(int argc, char **argv)
draw_text("link", 32, 47, False); draw_text("link", 32, 47, False);
/* Main loop */ /* Main loop */
for (i = 0;; i++) { while (1) {
/* CHANGED */ if (time(NULL) != last_update)
if (dockapp_nextevent_or_timeout(&event, update_interval * 100)) { update(&wfi);
/* Next Event */
switch (event.type) {
case ButtonPress:
bevent = (XButtonPressedEvent *) & event;
switch (bevent->button & 0xff) {
case Button1:
scroll = (scroll) ? False : True;
count = 0;
break;
case Button2:
next_if(&wfi);
break;
case Button3:
switch_interface(&wfi);
break;
}
break;
default: /* make gcc happy */
break;
}
} else {
/* Time Out */
update(&wfi);
}
}
return 0; while (XPending(display)) {
XNextEvent(display, &event);
switch (event.type) {
case ButtonPress:
bevent = (XButtonPressedEvent *) & event;
switch (bevent->button & 0xff) {
case Button1:
scroll = (scroll) ? False : True;
count = 0;
break;
case Button2:
next_if(&wfi);
break;
case Button3:
switch_interface(&wfi);
break;
}
break;
default: /* make gcc happy */
break;
}
}
usleep(update_interval*1000000L);
}
return 0;
} }
static void do_theme(struct theme thm) static void do_theme(struct theme thm)
@ -288,6 +289,7 @@ static void update(struct wifi *wfi)
/* show */ /* show */
} }
dockapp_copy2window(pixmap); dockapp_copy2window(pixmap);
time(&last_update);
} }
static void refresh(struct theme thm) static void refresh(struct theme thm)
{ {