From 697283e9177ee5730bf5c652c3c05d3aa3838ace Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Thu, 23 Jun 2011 12:55:29 -0700 Subject: Add Thread::join This new API will be used by applications that previously used the lower-level pthread APIs (including pthread_join). Centralizing on the Thread class instead of pthread will permit additional functionality to be added later in only one location. Change-Id: I8460169ac9c61ac9f85752405ed54c94651058d7 --- libs/utils/Threads.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libs/utils/Threads.cpp') diff --git a/libs/utils/Threads.cpp b/libs/utils/Threads.cpp index 15bb1d22627c..48ce5d1254dd 100644 --- a/libs/utils/Threads.cpp +++ b/libs/utils/Threads.cpp @@ -842,6 +842,25 @@ status_t Thread::requestExitAndWait() return mStatus; } +status_t Thread::join() +{ + Mutex::Autolock _l(mLock); + if (mThread == getThreadId()) { + LOGW( + "Thread (this=%p): don't call join() from this " + "Thread object's thread. It's a guaranteed deadlock!", + this); + + return WOULD_BLOCK; + } + + while (mRunning == true) { + mThreadExitedCondition.wait(mLock); + } + + return mStatus; +} + bool Thread::exitPending() const { Mutex::Autolock _l(mLock); -- cgit v1.2.3-59-g8ed1b