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:
		
							parent
							
								
									742d4deddf
								
							
						
					
					
						commit
						1e34ea7f98
					
				
					 1 changed files with 31 additions and 29 deletions
				
			
		| 
						 | 
					@ -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,10 +123,13 @@ 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 */
 | 
					
 | 
				
			||||||
 | 
						    while (XPending(display)) {
 | 
				
			||||||
 | 
							    XNextEvent(display, &event);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		    switch (event.type) {
 | 
							    switch (event.type) {
 | 
				
			||||||
		    case ButtonPress:
 | 
							    case ButtonPress:
 | 
				
			||||||
			    bevent = (XButtonPressedEvent *) & event;
 | 
								    bevent = (XButtonPressedEvent *) & event;
 | 
				
			||||||
| 
						 | 
					@ -145,12 +149,9 @@ int main(int argc, char **argv)
 | 
				
			||||||
		    default:		/* make gcc happy */
 | 
							    default:		/* make gcc happy */
 | 
				
			||||||
			    break;
 | 
								    break;
 | 
				
			||||||
		    }
 | 
							    }
 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
	    /* Time Out */
 | 
					 | 
				
			||||||
	    update(&wfi);
 | 
					 | 
				
			||||||
	    }
 | 
						    }
 | 
				
			||||||
 | 
						    usleep(update_interval*1000000L);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue