From 774e4f769fa649a98edec3876443defa8239a50d Mon Sep 17 00:00:00 2001 From: "Carlos R. Mafra" Date: Sat, 12 Jan 2019 21:22:15 +0000 Subject: [PATCH] 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. --- wmmemload/src/main.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/wmmemload/src/main.c b/wmmemload/src/main.c index ee038a9..f424398 100644 --- a/wmmemload/src/main.c +++ b/wmmemload/src/main.c @@ -53,6 +53,7 @@ static int mem_usage; static int swap_usage; static unsigned alarm_mem = 101; static unsigned alarm_swap = 101; +time_t last_update = 0; /* prototypes */ static void update(void); @@ -121,8 +122,12 @@ int main(int argc, char **argv) /* Main loop */ while (1) { - if (dockapp_nextevent_or_timeout(&event, update_interval * 1000)) { - /* Next Event */ + if (time(NULL) != last_update) + update(); + + while (XPending(display)) { + XNextEvent(display, &event); + switch (event.type) { case ButtonPress: switch_light(); @@ -130,10 +135,8 @@ int main(int argc, char **argv) default: /* make gcc happy */ break; } - } else { - /* Time Out */ - update(); } + usleep(update_interval*1000000L); } return 0; @@ -180,6 +183,7 @@ static void update(void) /* show */ dockapp_copy2window(pixmap); + time(&last_update); } /* called when mouse button pressed */