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

Commit d42bd87f authored by Mathias Agopian's avatar Mathias Agopian
Browse files

use broadcast() instead of signal() when signaling the condition-variable...

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.
parent a280496b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -408,6 +408,9 @@ private:
    volatile bool           mExitPending;
    volatile bool           mRunning;
            sp<Thread>      mHoldSelf;
#if HAVE_ANDROID_OS
            int             mTid;
#endif
};


+7 −2
Original line number Diff line number Diff line
@@ -655,6 +655,11 @@ int Thread::_threadLoop(void* user)
    wp<Thread> 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);