Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34713c04 authored by Shuzhen Wang's avatar Shuzhen Wang
Browse files

Camera: Do not signal AutoConditionLock if acquisition times out

It's possible for AutoConditionLock to time out in waitAndAcquire
while waiting for the condition. In this case, we don't want to
reset the state because others may be holding the condition without
lock.

Bug: 28295136
Change-Id: Ife90232daef8fd0d31acf9e52cfbcf542987e3fa
parent c3c06c4f
Loading
Loading
Loading
Loading
+7 −3
Original line number Original line Diff line number Diff line
@@ -24,14 +24,16 @@ WaitableMutexWrapper::~WaitableMutexWrapper() {}


// Locks manager-owned mutex
// Locks manager-owned mutex
AutoConditionLock::AutoConditionLock(const std::shared_ptr<WaitableMutexWrapper>& manager) :
AutoConditionLock::AutoConditionLock(const std::shared_ptr<WaitableMutexWrapper>& manager) :
        mManager{manager}, mAutoLock{manager->mMutex} {}
        mManager{manager}, mAutoLock{manager->mMutex}, mAcquired(false) {}


// Unlocks manager-owned mutex
// Unlocks manager-owned mutex
AutoConditionLock::~AutoConditionLock() {
AutoConditionLock::~AutoConditionLock() {
    // Unset the condition and wake everyone up before releasing lock
    // Unset the condition and wake everyone up before releasing lock
    if (mAcquired) {
        mManager->mState = false;
        mManager->mState = false;
        mManager->mCondition.broadcast();
        mManager->mCondition.broadcast();
    }
    }
}


std::unique_ptr<AutoConditionLock> AutoConditionLock::waitAndAcquire(
std::unique_ptr<AutoConditionLock> AutoConditionLock::waitAndAcquire(
        const std::shared_ptr<WaitableMutexWrapper>& manager, nsecs_t waitTime) {
        const std::shared_ptr<WaitableMutexWrapper>& manager, nsecs_t waitTime) {
@@ -59,6 +61,7 @@ std::unique_ptr<AutoConditionLock> AutoConditionLock::waitAndAcquire(


    // Set the condition and return
    // Set the condition and return
    manager->mState = true;
    manager->mState = true;
    scopedLock->mAcquired = true;
    return scopedLock;
    return scopedLock;
}
}


@@ -84,6 +87,7 @@ std::unique_ptr<AutoConditionLock> AutoConditionLock::waitAndAcquire(


    // Set the condition and return
    // Set the condition and return
    manager->mState = true;
    manager->mState = true;
    scopedLock->mAcquired = true;
    return scopedLock;
    return scopedLock;
}
}


+1 −0
Original line number Original line Diff line number Diff line
@@ -92,6 +92,7 @@ private:


    std::shared_ptr<WaitableMutexWrapper> mManager;
    std::shared_ptr<WaitableMutexWrapper> mManager;
    Mutex::Autolock mAutoLock;
    Mutex::Autolock mAutoLock;
    bool mAcquired;
};
};


}; // namespace android
}; // namespace android