From 4de4ebf6a25b5cf1819809ffcedea331d79823e0 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 9 Sep 2009 02:38:13 -0700 Subject: use broadcast() instead of signal() when signaling the condition-variable Thread::RequestExitAndWait() is waiting for we could have several thread waiting on the condition and they all need to wake-up. also added a debug "mTid" field in the class, which contains the tid of the thread (as opposed to pthread_t), this is useful when debugging under gdb for instance. --- include/utils/threads.h | 3 +++ libs/utils/Threads.cpp | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/utils/threads.h b/include/utils/threads.h index e9b0788895..0fc533f955 100644 --- a/include/utils/threads.h +++ b/include/utils/threads.h @@ -408,6 +408,9 @@ private: volatile bool mExitPending; volatile bool mRunning; sp mHoldSelf; +#if HAVE_ANDROID_OS + int mTid; +#endif }; diff --git a/libs/utils/Threads.cpp b/libs/utils/Threads.cpp index 6be372c87e..ec3db0980d 100644 --- a/libs/utils/Threads.cpp +++ b/libs/utils/Threads.cpp @@ -655,6 +655,11 @@ int Thread::_threadLoop(void* user) wp weak(strong); self->mHoldSelf.clear(); +#if HAVE_ANDROID_OS + // this is very useful for debugging with gdb + self->mTid = gettid(); +#endif + bool first = true; do { @@ -685,7 +690,7 @@ int Thread::_threadLoop(void* user) self->mExitPending = true; self->mLock.lock(); self->mRunning = false; - self->mThreadExitedCondition.signal(); + self->mThreadExitedCondition.broadcast(); self->mLock.unlock(); break; } @@ -693,7 +698,7 @@ int Thread::_threadLoop(void* user) // Release our strong reference, to let a chance to the thread // to die a peaceful death. strong.clear(); - // And immediately, reacquire a strong reference for the next loop + // And immediately, re-acquire a strong reference for the next loop strong = weak.promote(); } while(strong != 0); -- cgit v1.2.3-59-g8ed1b