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

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

Merge "ALooper::awaitResponse gets reply and returns immediately if the looper...

Merge "ALooper::awaitResponse gets reply and returns immediately if the looper is stopped." into mnc-dr-dev
parents f6224dec b49c3852
Loading
Loading
Loading
Loading
+4 −16
Original line number Original line Diff line number Diff line
@@ -234,31 +234,19 @@ sp<AReplyToken> ALooper::createReplyToken() {


// to be called by AMessage::postAndAwaitResponse only
// to be called by AMessage::postAndAwaitResponse only
status_t ALooper::awaitResponse(const sp<AReplyToken> &replyToken, sp<AMessage> *response) {
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
    // return status in case we want to handle an interrupted wait
    Mutex::Autolock autoLock(mRepliesLock);
    Mutex::Autolock autoLock(mRepliesLock);
    CHECK(replyToken != NULL);
    CHECK(replyToken != NULL);
    bool gotReply;
    while (!replyToken->retrieveReply(response)) {
    bool shouldContinue = true;
    while (!(gotReply = replyToken->retrieveReply(response)) && shouldContinue) {
        mRepliesCondition.wait(mRepliesLock);

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

    return OK;
    return gotReply ? OK : -ENOENT;
}
}


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