From 5163c2ef5fe11c9b10d230691ef429035da4c788 Mon Sep 17 00:00:00 2001 From: Jimmy Dalqvist Date: Tue, 14 Jan 2014 14:13:52 +0100 Subject: Only increase the counter when we do take a wakelock We keep track on how many wakelocks we have taken. We always just take one real wakelock but increase / decrease the counter every time we try to acquire / release a wakelock. The counter is always increased even if the power manager is not ready, leading to an incorrect counter that could cause a crash when we try to release it. Make sure we only increase the counter when a wakelock, real or counted, is taken. Change-Id: Iad940e052694932f1dad8a1a71fa63601d289d6a --- media/libstagefright/TimedEventQueue.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/media/libstagefright/TimedEventQueue.cpp b/media/libstagefright/TimedEventQueue.cpp index dedd186..0afac69 100644 --- a/media/libstagefright/TimedEventQueue.cpp +++ b/media/libstagefright/TimedEventQueue.cpp @@ -318,7 +318,7 @@ sp TimedEventQueue::removeEventFromQueue_l( void TimedEventQueue::acquireWakeLock_l() { - if (mWakeLockCount++ == 0) { + if (mWakeLockCount == 0) { CHECK(mWakeLockToken == 0); if (mPowerManager == 0) { // use checkService() to avoid blocking if power service is not up yet @@ -341,21 +341,23 @@ void TimedEventQueue::acquireWakeLock_l() IPCThreadState::self()->restoreCallingIdentity(token); if (status == NO_ERROR) { mWakeLockToken = binder; + mWakeLockCount++; } } + } else { + mWakeLockCount++; } } void TimedEventQueue::releaseWakeLock_l(bool force) { + if (mWakeLockCount == 0) { + return; + } if (force) { - if (mWakeLockCount == 0) { - return; - } // Force wakelock release below by setting reference count to 1. mWakeLockCount = 1; } - CHECK(mWakeLockCount != 0); if (--mWakeLockCount == 0) { CHECK(mWakeLockToken != 0); if (mPowerManager != 0) { -- cgit v1.1