summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross2012-06-14 14:55:47 -0500
committerColin Cross2012-06-14 17:13:10 -0500
commitf25dd878dfeba87a3c2b868e07cb550061f670b4 (patch)
tree014da632dfcc48834703bd2835e32365a27bb386 /libsuspend
parent66086a586f80e394674eb171d683d0d9677e3abf (diff)
downloadplatform-system-core-f25dd878dfeba87a3c2b868e07cb550061f670b4.tar.gz
platform-system-core-f25dd878dfeba87a3c2b868e07cb550061f670b4.tar.xz
platform-system-core-f25dd878dfeba87a3c2b868e07cb550061f670b4.zip
libsuspend: wait for earlysuspend transition to finish
Wait for the early suspend transition to finish to the point where surfaceflinger would previously have synchronized. This is important during screen on, to ensure the display early suspend handlers have completed before surfaceflinger unblanks. Change-Id: I91ac0253d9655c3f1ae3dd7f1a918c279568b23e
Diffstat (limited to 'libsuspend')
-rw-r--r--libsuspend/autosuspend_earlysuspend.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/libsuspend/autosuspend_earlysuspend.c b/libsuspend/autosuspend_earlysuspend.c
index b4401284c..1df8c6a13 100644
--- a/libsuspend/autosuspend_earlysuspend.c
+++ b/libsuspend/autosuspend_earlysuspend.c
@@ -16,6 +16,8 @@
16 16
17#include <errno.h> 17#include <errno.h>
18#include <fcntl.h> 18#include <fcntl.h>
19#include <pthread.h>
20#include <stdbool.h>
19#include <stddef.h> 21#include <stddef.h>
20#include <string.h> 22#include <string.h>
21#include <sys/types.h> 23#include <sys/types.h>
@@ -31,11 +33,17 @@
31#define EARLYSUSPEND_WAIT_FOR_FB_SLEEP "/sys/power/wait_for_fb_sleep" 33#define EARLYSUSPEND_WAIT_FOR_FB_SLEEP "/sys/power/wait_for_fb_sleep"
32#define EARLYSUSPEND_WAIT_FOR_FB_WAKE "/sys/power/wait_for_fb_wake" 34#define EARLYSUSPEND_WAIT_FOR_FB_WAKE "/sys/power/wait_for_fb_wake"
33 35
34
35static int sPowerStatefd; 36static int sPowerStatefd;
36static const char *pwr_state_mem = "mem"; 37static const char *pwr_state_mem = "mem";
37static const char *pwr_state_on = "on"; 38static const char *pwr_state_on = "on";
38static pthread_t earlysuspend_thread; 39static pthread_t earlysuspend_thread;
40static pthread_mutex_t earlysuspend_mutex = PTHREAD_MUTEX_INITIALIZER;
41static pthread_cond_t earlysuspend_cond = PTHREAD_COND_INITIALIZER;
42static bool wait_for_earlysuspend;
43static enum {
44 EARLYSUSPEND_ON,
45 EARLYSUSPEND_MEM,
46} earlysuspend_state = EARLYSUSPEND_ON;
39 47
40int wait_for_fb_wake(void) 48int wait_for_fb_wake(void)
41{ 49{
@@ -79,10 +87,19 @@ static void *earlysuspend_thread_func(void *arg)
79 ALOGE("Failed reading wait_for_fb_sleep, exiting earlysuspend thread\n"); 87 ALOGE("Failed reading wait_for_fb_sleep, exiting earlysuspend thread\n");
80 return NULL; 88 return NULL;
81 } 89 }
90 pthread_mutex_lock(&earlysuspend_mutex);
91 earlysuspend_state = EARLYSUSPEND_MEM;
92 pthread_cond_signal(&earlysuspend_cond);
93 pthread_mutex_unlock(&earlysuspend_mutex);
94
82 if (wait_for_fb_wake()) { 95 if (wait_for_fb_wake()) {
83 ALOGE("Failed reading wait_for_fb_wake, exiting earlysuspend thread\n"); 96 ALOGE("Failed reading wait_for_fb_wake, exiting earlysuspend thread\n");
84 return NULL; 97 return NULL;
85 } 98 }
99 pthread_mutex_lock(&earlysuspend_mutex);
100 earlysuspend_state = EARLYSUSPEND_ON;
101 pthread_cond_signal(&earlysuspend_cond);
102 pthread_mutex_unlock(&earlysuspend_mutex);
86 } 103 }
87} 104}
88static int autosuspend_earlysuspend_enable(void) 105static int autosuspend_earlysuspend_enable(void)
@@ -99,6 +116,14 @@ static int autosuspend_earlysuspend_enable(void)
99 goto err; 116 goto err;
100 } 117 }
101 118
119 if (wait_for_earlysuspend) {
120 pthread_mutex_lock(&earlysuspend_mutex);
121 while (earlysuspend_state != EARLYSUSPEND_MEM) {
122 pthread_cond_wait(&earlysuspend_cond, &earlysuspend_mutex);
123 }
124 pthread_mutex_unlock(&earlysuspend_mutex);
125 }
126
102 ALOGV("autosuspend_earlysuspend_enable done\n"); 127 ALOGV("autosuspend_earlysuspend_enable done\n");
103 128
104 return 0; 129 return 0;
@@ -121,6 +146,14 @@ static int autosuspend_earlysuspend_disable(void)
121 goto err; 146 goto err;
122 } 147 }
123 148
149 if (wait_for_earlysuspend) {
150 pthread_mutex_lock(&earlysuspend_mutex);
151 while (earlysuspend_state != EARLYSUSPEND_ON) {
152 pthread_cond_wait(&earlysuspend_cond, &earlysuspend_mutex);
153 }
154 pthread_mutex_unlock(&earlysuspend_mutex);
155 }
156
124 ALOGV("autosuspend_earlysuspend_disable done\n"); 157 ALOGV("autosuspend_earlysuspend_disable done\n");
125 158
126 return 0; 159 return 0;
@@ -149,12 +182,17 @@ void start_earlysuspend_thread(void)
149 return; 182 return;
150 } 183 }
151 184
185 wait_for_fb_wake();
186
152 ALOGI("Starting early suspend unblocker thread\n"); 187 ALOGI("Starting early suspend unblocker thread\n");
153 ret = pthread_create(&earlysuspend_thread, NULL, earlysuspend_thread_func, NULL); 188 ret = pthread_create(&earlysuspend_thread, NULL, earlysuspend_thread_func, NULL);
154 if (ret) { 189 if (ret) {
155 strerror_r(ret, buf, sizeof(buf)); 190 strerror_r(errno, buf, sizeof(buf));
156 ALOGE("Error creating thread: %s\n", buf); 191 ALOGE("Error creating thread: %s\n", buf);
192 return;
157 } 193 }
194
195 wait_for_earlysuspend = true;
158} 196}
159 197
160struct autosuspend_ops *autosuspend_earlysuspend_init(void) 198struct autosuspend_ops *autosuspend_earlysuspend_init(void)