Bug 743064: Shutdown FramebufferWatcher thread gracefully by using it as a pthread. r=cjones a=b2g-only

This commit is contained in:
Gene Lian 2012-04-26 16:46:52 +08:00
Родитель 3a80a3f004
Коммит 674a53d819
1 изменённых файлов: 16 добавлений и 22 удалений

Просмотреть файл

@ -79,7 +79,7 @@ static android::FramebufferNativeWindow *gNativeWindow = nsnull;
static bool sFramebufferOpen;
static bool sUsingOMTC;
static nsRefPtr<gfxASurface> sOMTCSurface;
static nsCOMPtr<nsIThread> sFramebufferWatchThread;
static pthread_t sFramebufferWatchThread;
namespace {
@ -112,17 +112,15 @@ private:
static const char* kSleepFile = "/sys/power/wait_for_fb_sleep";
static const char* kWakeFile = "/sys/power/wait_for_fb_wake";
class FramebufferWatcher : public nsRunnable {
public:
FramebufferWatcher()
: mScreenOnEvent(new ScreenOnOffEvent(true))
, mScreenOffEvent(new ScreenOnOffEvent(false))
{}
static void *frameBufferWatcher(void *) {
NS_IMETHOD Run() {
int len = 0;
char buf;
int len = 0;
char buf;
nsRefPtr<ScreenOnOffEvent> mScreenOnEvent = new ScreenOnOffEvent(true);
nsRefPtr<ScreenOnOffEvent> mScreenOffEvent = new ScreenOnOffEvent(false);
while (true) {
// Cannot use epoll here because kSleepFile and kWakeFile are
// always ready to read and blocking.
{
@ -142,17 +140,10 @@ public:
NS_WARN_IF_FALSE(len >= 0, "WAIT_FOR_FB_WAKE failed");
NS_DispatchToMainThread(mScreenOnEvent);
}
// Dispatch to ourself.
NS_DispatchToCurrentThread(this);
return NS_OK;
}
private:
nsRefPtr<ScreenOnOffEvent> mScreenOnEvent;
nsRefPtr<ScreenOnOffEvent> mScreenOffEvent;
};
return NULL;
}
} // anonymous namespace
@ -162,8 +153,11 @@ nsWindow::nsWindow()
// workaround Bug 725143
hal::SetScreenEnabled(true);
// Watching screen on/off state
NS_NewThread(getter_AddRefs(sFramebufferWatchThread), new FramebufferWatcher());
// Watching screen on/off state by using a pthread
// which implicitly calls exit() when the main thread ends
if (pthread_create(&sFramebufferWatchThread, NULL, frameBufferWatcher, NULL)) {
NS_RUNTIMEABORT("Failed to create framebufferWatcherThread, aborting...");
}
sUsingOMTC = Preferences::GetBool("layers.offmainthreadcomposition.enabled", false);