Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added function for blocking suspend on process exit path
For making sure we do not accidentally allow automatic
suspend once we have decided to terminate the process.
  • Loading branch information
spiiroin committed Dec 21, 2012
1 parent b4dda54 commit a677a80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 additions & 1 deletion libwakelock.c
Expand Up @@ -107,6 +107,8 @@ void wakelock_unlock(const char *name)

static const char lwl_state_path[] = "/sys/power/state";

static int lwl_shutting_down = 0;

/** Use sysfs interface to allow automatic entry to suspend
*
* After this call the device will enter suspend mode once all
Expand All @@ -117,7 +119,7 @@ static const char lwl_state_path[] = "/sys/power/state";
*/
void wakelock_allow_suspend(void)
{
if( lwl_enabled() ) {
if( lwl_enabled() && !lwl_shutting_down ) {
lwl_write_file(lwl_state_path, "mem\n");
}
}
Expand All @@ -133,3 +135,19 @@ void wakelock_block_suspend(void)
lwl_write_file(lwl_state_path, "on\n");
}
}

/** Block automatic suspend without possibility to unblock it again
*
* For use on exit path. We want to do clean exit from mainloop and
* that might that code that re-enables autosuspend gets triggered
* while we're on exit path.
*
* By calling this function when initiating daemon shutdown we are
* protected against this.
*/

void wakelock_block_suspend_until_exit(void)
{
lwl_shutting_down = 1;
wakelock_block_suspend();
}
1 change: 1 addition & 0 deletions libwakelock.h
Expand Up @@ -18,6 +18,7 @@ void wakelock_unlock(const char *name);

void wakelock_allow_suspend(void);
void wakelock_block_suspend(void);
void wakelock_block_suspend_until_exit(void);

# ifdef __cplusplus
};
Expand Down

0 comments on commit a677a80

Please sign in to comment.