Revert "libsuspend: move to exponential backoff"
am: 23c8bab024
Change-Id: I07decd5946c8877308b8ee9d2b49536fcabf548c
This commit is contained in:
commit
4dcd461945
1 changed files with 5 additions and 19 deletions
|
@ -21,7 +21,6 @@
|
|||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
@ -35,24 +34,12 @@
|
|||
#define SYS_POWER_STATE "/sys/power/state"
|
||||
#define SYS_POWER_WAKEUP_COUNT "/sys/power/wakeup_count"
|
||||
|
||||
#define BASE_SLEEP_TIME 100000
|
||||
|
||||
static int state_fd;
|
||||
static int wakeup_count_fd;
|
||||
static pthread_t suspend_thread;
|
||||
static sem_t suspend_lockout;
|
||||
static const char *sleep_state = "mem";
|
||||
static void (*wakeup_func)(bool success) = NULL;
|
||||
static int sleep_time = BASE_SLEEP_TIME;
|
||||
|
||||
static void update_sleep_time(bool success) {
|
||||
if (success) {
|
||||
sleep_time = BASE_SLEEP_TIME;
|
||||
return;
|
||||
}
|
||||
// double sleep time after each failure up to one minute
|
||||
sleep_time = MIN(sleep_time * 2, 60000000);
|
||||
}
|
||||
|
||||
static void *suspend_thread_func(void *arg __attribute__((unused)))
|
||||
{
|
||||
|
@ -60,12 +47,10 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
|
|||
char wakeup_count[20];
|
||||
int wakeup_count_len;
|
||||
int ret;
|
||||
bool success = true;
|
||||
bool success;
|
||||
|
||||
while (1) {
|
||||
update_sleep_time(success);
|
||||
usleep(sleep_time);
|
||||
success = false;
|
||||
usleep(100000);
|
||||
ALOGV("%s: read wakeup_count\n", __func__);
|
||||
lseek(wakeup_count_fd, 0, SEEK_SET);
|
||||
wakeup_count_len = TEMP_FAILURE_RETRY(read(wakeup_count_fd, wakeup_count,
|
||||
|
@ -89,6 +74,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
|
|||
continue;
|
||||
}
|
||||
|
||||
success = true;
|
||||
ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count);
|
||||
ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len));
|
||||
if (ret < 0) {
|
||||
|
@ -97,8 +83,8 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
|
|||
} else {
|
||||
ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE);
|
||||
ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state)));
|
||||
if (ret >= 0) {
|
||||
success = true;
|
||||
if (ret < 0) {
|
||||
success = false;
|
||||
}
|
||||
void (*func)(bool success) = wakeup_func;
|
||||
if (func != NULL) {
|
||||
|
|
Loading…
Reference in a new issue