From 79e00454d516acff0e4e5be97193917b4afc3fbc Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 15 May 2019 10:36:23 +0200 Subject: Refine timings --- src/main.c | 32 ++++++++++++++++++-------------- src/x11util.c | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main.c b/src/main.c index a43a2f6..cb4a47e 100644 --- a/src/main.c +++ b/src/main.c @@ -262,7 +262,7 @@ int main( int argc, char **argv ) } nextAction.deadline = 0; } else if ( ! nextAction.disarmed ) { - if ( remaining <= 3 ) { + if ( remaining <= 1 ) { // Execute! execShutdown( nextAction.action ); nextAction.disarmed = true; @@ -283,19 +283,23 @@ int main( int argc, char **argv ) } } } - // Handle requests - rpcHandle( listenFd ); - // Might have set a new scheduled action - if ( nextAction.deadline != 0 && nextAction.force ) { - int delta = nextAction.deadline - monoNOW; - CAP_SLEEP( delta ); - } - // Sleep until next run - //printf( "Sleeping %d seconds\n ", sleepTime ); - rpcWait( listenFd, sleepTime > 5 ? sleepTime : 5 ); - // Detect time changes - endWall = time( NULL ); - endMono = now(); + do { + // Handle requests + rpcHandle( listenFd ); + // Might have set a new scheduled action + if ( nextAction.deadline != 0 && nextAction.force ) { + int delta = nextAction.deadline - monoNOW; + CAP_SLEEP( delta ); + } + // Sleep until next run + //printf( "Sleeping %d seconds\n ", sleepTime ); + rpcWait( listenFd, sleepTime > 5 ? sleepTime : 5 ); + // Detect time changes + endWall = time( NULL ); + endMono = now(); + // Sloppy way of preventing we loop too fast -- handle rpc callbacks but don't run main logic + sleepTime -= ( endMono - startMono ); + } while ( endMono - startMono < 2 ); // Adjust for clock changes const int diff = ( endWall - startWall ) - ( endMono - startMono ); if ( diff != 0 ) { diff --git a/src/x11util.c b/src/x11util.c index 18e2fe4..dc230b3 100644 --- a/src/x11util.c +++ b/src/x11util.c @@ -105,7 +105,7 @@ void setScreenDpms( const char *xauth, const char *display, int mode ) } if ( ! doublefork() ) return; - sleep( 2 ); // Sleep a bit in case this was called right after enabling the screen saver + sleep( 1 ); // Sleep a bit in case this was called right after enabling the screen saver setScreenDpmsFork( xauth, display, mode ); exit( 0 ); } -- cgit v1.2.3-55-g7522