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

Commit 0983d691 authored by Ronghua Wu's avatar Ronghua Wu Committed by Android (Google) Code Review
Browse files

Merge "Allow ALooper::awaitResponse to return immediately if the looper is...

Merge "Allow ALooper::awaitResponse to return immediately if the looper is stopped." into mnc-dr-dev
parents f8dc6433 0abb2aa4
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -600,7 +600,12 @@ status_t MediaCodec::reclaim(bool force) {
    msg->setInt32("force", force ? 1 : 0);

    sp<AMessage> response;
    return PostAndAwaitResponse(msg, &response);
    status_t ret = PostAndAwaitResponse(msg, &response);
    if (ret == -ENOENT) {
        ALOGD("MediaCodec looper is gone, skip reclaim");
        ret = OK;
    }
    return ret;
}

status_t MediaCodec::release() {
+24 −2
Original line number Diff line number Diff line
@@ -151,6 +151,10 @@ status_t ALooper::stop() {
    }

    mQueueChangedCondition.signal();
    {
        Mutex::Autolock autoLock(mRepliesLock);
        mRepliesCondition.broadcast();
    }

    if (!runningLocally && !thread->isCurrentThread()) {
        // If not running locally and this thread _is_ the looper thread,
@@ -230,13 +234,31 @@ sp<AReplyToken> ALooper::createReplyToken() {

// to be called by AMessage::postAndAwaitResponse only
status_t ALooper::awaitResponse(const sp<AReplyToken> &replyToken, sp<AMessage> *response) {
    {
        Mutex::Autolock autoLock(mLock);
        if (mThread == NULL) {
            return -ENOENT;
        }
    }

    // return status in case we want to handle an interrupted wait
    Mutex::Autolock autoLock(mRepliesLock);
    CHECK(replyToken != NULL);
    while (!replyToken->retrieveReply(response)) {
    bool gotReply;
    bool shouldContinue = true;
    while (!(gotReply = replyToken->retrieveReply(response)) && shouldContinue) {
        mRepliesCondition.wait(mRepliesLock);

        {
            Mutex::Autolock autoLock(mLock);
            if (mThread == NULL) {
                shouldContinue = false;
                // continue and try to get potential reply one more time before break the loop
            }
    return OK;
        }
    }

    return gotReply ? OK : -ENOENT;
}

status_t ALooper::postReply(const sp<AReplyToken> &replyToken, const sp<AMessage> &reply) {