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

Commit 9447be65 authored by Romain Guy's avatar Romain Guy
Browse files

Add Thread::isRunning and Condition::signal(WakeUpType)

The signal() method is useful to choose whether to wake up one or
all threads.

Change-Id: I062ab6d3ddd306a9fb735549ea140e2a76eed75a
parent 175264b0
Loading
Loading
Loading
Loading
+13 −0
Original line number Original line Diff line number Diff line
@@ -48,6 +48,11 @@ public:
        SHARED = 1
        SHARED = 1
    };
    };


    enum WakeUpType {
        WAKE_UP_ONE = 0,
        WAKE_UP_ALL = 1
    };

    Condition();
    Condition();
    Condition(int type);
    Condition(int type);
    ~Condition();
    ~Condition();
@@ -57,6 +62,14 @@ public:
    status_t waitRelative(Mutex& mutex, nsecs_t reltime);
    status_t waitRelative(Mutex& mutex, nsecs_t reltime);
    // Signal the condition variable, allowing one thread to continue.
    // Signal the condition variable, allowing one thread to continue.
    void signal();
    void signal();
    // Signal the condition variable, allowing one or all threads to continue.
    void signal(WakeUpType type) {
        if (type == WAKE_UP_ONE) {
            signal();
        } else {
            broadcast();
        }
    }
    // Signal the condition variable, allowing all threads to continue.
    // Signal the condition variable, allowing all threads to continue.
    void broadcast();
    void broadcast();


+3 −0
Original line number Original line Diff line number Diff line
@@ -67,6 +67,9 @@ public:
    // Do not call from this object's thread; will return WOULD_BLOCK in that case.
    // Do not call from this object's thread; will return WOULD_BLOCK in that case.
            status_t    join();
            status_t    join();


    // Indicates whether this thread is running or not.
            bool        isRunning() const;

#ifdef HAVE_ANDROID_OS
#ifdef HAVE_ANDROID_OS
    // Return the thread's kernel ID, same as the thread itself calling gettid() or
    // Return the thread's kernel ID, same as the thread itself calling gettid() or
    // androidGetTid(), or -1 if the thread is not running.
    // androidGetTid(), or -1 if the thread is not running.
+5 −0
Original line number Original line Diff line number Diff line
@@ -871,6 +871,11 @@ status_t Thread::join()
    return mStatus;
    return mStatus;
}
}


bool Thread::isRunning() const {
    Mutex::Autolock _l(mLock);
    return mRunning;
}

#ifdef HAVE_ANDROID_OS
#ifdef HAVE_ANDROID_OS
pid_t Thread::getTid() const
pid_t Thread::getTid() const
{
{