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
This commit is contained in:
parent
5e0243f4d6
commit
6839e8e9ee
|
@ -510,6 +510,10 @@ public:
|
|||
// that case.
|
||||
status_t requestExitAndWait();
|
||||
|
||||
// Wait until this object's thread exits. Returns immediately if not yet running.
|
||||
// Do not call from this object's thread; will return WOULD_BLOCK in that case.
|
||||
status_t join();
|
||||
|
||||
protected:
|
||||
// exitPending() returns true if requestExit() has been called.
|
||||
bool exitPending() const;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue