diff options
author | Ronghua Wu <ronghuawu@google.com> | 2015-10-21 13:42:59 -0700 |
---|---|---|
committer | Ronghua Wu <ronghuawu@google.com> | 2015-10-22 13:42:02 -0700 |
commit | 0abb2aa4859ced9165c77324cb83d1cd94f5f20c (patch) | |
tree | cf4ac64347e3eecb3e8be4adb49aaa5b116e43bc /media/libstagefright/foundation | |
parent | e710ae53001bbbf1e1afd6b3f5c3478c673afd0e (diff) | |
download | frameworks_av-0abb2aa4859ced9165c77324cb83d1cd94f5f20c.zip frameworks_av-0abb2aa4859ced9165c77324cb83d1cd94f5f20c.tar.gz frameworks_av-0abb2aa4859ced9165c77324cb83d1cd94f5f20c.tar.bz2 |
Allow ALooper::awaitResponse to return immediately if the looper is stopped.
Bug: 25088488
Change-Id: I63e69886a8e9cffcaad675ca1a5642c0abf3b466
Diffstat (limited to 'media/libstagefright/foundation')
-rw-r--r-- | media/libstagefright/foundation/ALooper.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/media/libstagefright/foundation/ALooper.cpp b/media/libstagefright/foundation/ALooper.cpp index 90b5f68..5c2e9f9 100644 --- a/media/libstagefright/foundation/ALooper.cpp +++ b/media/libstagefright/foundation/ALooper.cpp @@ -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) { |