Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5161eb7b authored by Glenn Kasten's avatar Glenn Kasten Committed by Android (Google) Code Review
Browse files

Merge "Add Thread::join"

parents 55aaccd7 697283e9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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;
+19 −0
Original line number Diff line number Diff line
@@ -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);