void start_earlysuspend_thread(void) { char buf[80]; int ret; ret = access(EARLYSUSPEND_WAIT_FOR_FB_SLEEP, F_OK); if (ret < 0) { return; } ret = access(EARLYSUSPEND_WAIT_FOR_FB_WAKE, F_OK); if (ret < 0) { return; } wait_for_fb_wake(); ALOGI("Starting early suspend unblocker thread\n"); ret = pthread_create(&earlysuspend_thread, NULL, earlysuspend_thread_func, NULL); if (ret) { strerror_r(errno, buf, sizeof(buf)); ALOGE("Error creating thread: %s\n", buf); return; } wait_for_earlysuspend = true; }
static void *earlysuspend_thread_func(void *arg) { char buf[80]; char wakeup_count[20]; int wakeup_count_len; int ret; while (1) { if (wait_for_fb_sleep()) { ALOGE("Failed reading wait_for_fb_sleep, exiting earlysuspend thread\n"); return NULL; } pthread_mutex_lock(&earlysuspend_mutex); earlysuspend_state = EARLYSUSPEND_MEM; pthread_cond_signal(&earlysuspend_cond); pthread_mutex_unlock(&earlysuspend_mutex); if (wait_for_fb_wake()) { ALOGE("Failed reading wait_for_fb_wake, exiting earlysuspend thread\n"); return NULL; } pthread_mutex_lock(&earlysuspend_mutex); earlysuspend_state = EARLYSUSPEND_ON; pthread_cond_signal(&earlysuspend_cond); pthread_mutex_unlock(&earlysuspend_mutex); } }
static void *earlysuspend_thread_func(void __unused *arg) { while (1) { if (wait_for_fb_sleep()) { ALOGE("Failed reading wait_for_fb_sleep, exiting earlysuspend thread\n"); return NULL; } pthread_mutex_lock(&earlysuspend_mutex); earlysuspend_state = EARLYSUSPEND_MEM; pthread_cond_signal(&earlysuspend_cond); pthread_mutex_unlock(&earlysuspend_mutex); if (wait_for_fb_wake()) { ALOGE("Failed reading wait_for_fb_wake, exiting earlysuspend thread\n"); return NULL; } pthread_mutex_lock(&earlysuspend_mutex); earlysuspend_state = EARLYSUSPEND_ON; pthread_cond_signal(&earlysuspend_cond); pthread_mutex_unlock(&earlysuspend_mutex); } }