diff options
| author | Glenn Kasten <gkasten@google.com> | 2011-06-23 12:55:29 -0700 |
|---|---|---|
| committer | Alex Ray <aray@google.com> | 2013-07-30 13:56:57 -0700 |
| commit | 6839e8e9ee894191e3fa857859311337357fe191 (patch) | |
| tree | 76c1c6dc6e672093bf7e8f174a861cd180494bf8 /libs/utils | |
| parent | 5e0243f4d6313419fdc3affc205b790a2a965208 (diff) | |
| download | system_core-6839e8e9ee894191e3fa857859311337357fe191.zip system_core-6839e8e9ee894191e3fa857859311337357fe191.tar.gz system_core-6839e8e9ee894191e3fa857859311337357fe191.tar.bz2 | |
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
Diffstat (limited to 'libs/utils')
| -rw-r--r-- | libs/utils/Threads.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libs/utils/Threads.cpp b/libs/utils/Threads.cpp index 71352a8..50312e7 100644 --- a/libs/utils/Threads.cpp +++ b/libs/utils/Threads.cpp @@ -846,6 +846,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); |
