summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/foundation
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2011-03-29 11:50:24 -0700
committerAndreas Huber <andih@google.com>2011-03-29 11:50:24 -0700
commitf8be8c0c8055ead961d23b969bf46315eb93e887 (patch)
treec1c635a628b2ff76554e633f516c716097e4118f /media/libstagefright/foundation
parent51538b30da3208ecf498ce327ac3104b455f163d (diff)
downloadframeworks_av-f8be8c0c8055ead961d23b969bf46315eb93e887.zip
frameworks_av-f8be8c0c8055ead961d23b969bf46315eb93e887.tar.gz
frameworks_av-f8be8c0c8055ead961d23b969bf46315eb93e887.tar.bz2
Make sure we don't trigger a log warning if calling ALooper::stop() from the looper thread.
Change-Id: I669d589ab4521fe44a3e8f638c7ce8e79174d625 related-to-bug: 4179898
Diffstat (limited to 'media/libstagefright/foundation')
-rw-r--r--media/libstagefright/foundation/ALooper.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/media/libstagefright/foundation/ALooper.cpp b/media/libstagefright/foundation/ALooper.cpp
index b7087f8..a5b316d 100644
--- a/media/libstagefright/foundation/ALooper.cpp
+++ b/media/libstagefright/foundation/ALooper.cpp
@@ -33,18 +33,30 @@ ALooperRoster gLooperRoster;
struct ALooper::LooperThread : public Thread {
LooperThread(ALooper *looper, bool canCallJava)
: Thread(canCallJava),
- mLooper(looper) {
+ mLooper(looper),
+ mThreadId(NULL) {
+ }
+
+ virtual status_t readyToRun() {
+ mThreadId = androidGetThreadId();
+
+ return Thread::readyToRun();
}
virtual bool threadLoop() {
return mLooper->loop();
}
+ bool isCurrentThread() const {
+ return mThreadId == androidGetThreadId();
+ }
+
protected:
virtual ~LooperThread() {}
private:
ALooper *mLooper;
+ android_thread_id_t mThreadId;
DISALLOW_EVIL_CONSTRUCTORS(LooperThread);
};
@@ -136,7 +148,9 @@ status_t ALooper::stop() {
mQueueChangedCondition.signal();
- if (!runningLocally) {
+ if (!runningLocally && !thread->isCurrentThread()) {
+ // If not running locally and this thread _is_ the looper thread,
+ // the loop() function will return and never be called again.
thread->requestExitAndWait();
}
@@ -197,6 +211,11 @@ bool ALooper::loop() {
gLooperRoster.deliverMessage(event.mMessage);
+ // NOTE: It's important to note that at this point our "ALooper" object
+ // may no longer exist (its final reference may have gone away while
+ // delivering the message). We have made sure, however, that loop()
+ // won't be called again.
+
return true;
}