wmmemload: call usleep() directly in main loop

The reason is the same as in the analogous patch for wmwifi
in commit 1e34ea7f980; it improves considerably the efficiency.

Keeping the 'interval' unchanged (set to 1 sec), with this change
the number of wakeups as measured by powertop goes from around 14 wakeups/sec
to around 2 wakeup/sec.
This commit is contained in:
Carlos R. Mafra 2019-01-12 21:22:15 +00:00
parent dd5d59b8f9
commit 774e4f769f

View file

@ -53,6 +53,7 @@ static int mem_usage;
static int swap_usage; static int swap_usage;
static unsigned alarm_mem = 101; static unsigned alarm_mem = 101;
static unsigned alarm_swap = 101; static unsigned alarm_swap = 101;
time_t last_update = 0;
/* prototypes */ /* prototypes */
static void update(void); static void update(void);
@ -121,8 +122,12 @@ int main(int argc, char **argv)
/* Main loop */ /* Main loop */
while (1) { while (1) {
if (dockapp_nextevent_or_timeout(&event, update_interval * 1000)) { if (time(NULL) != last_update)
/* Next Event */ update();
while (XPending(display)) {
XNextEvent(display, &event);
switch (event.type) { switch (event.type) {
case ButtonPress: case ButtonPress:
switch_light(); switch_light();
@ -130,10 +135,8 @@ int main(int argc, char **argv)
default: /* make gcc happy */ default: /* make gcc happy */
break; break;
} }
} else {
/* Time Out */
update();
} }
usleep(update_interval*1000000L);
} }
return 0; return 0;
@ -180,6 +183,7 @@ static void update(void)
/* show */ /* show */
dockapp_copy2window(pixmap); dockapp_copy2window(pixmap);
time(&last_update);
} }
/* called when mouse button pressed */ /* called when mouse button pressed */