diff options
author | Romain Guy <romainguy@google.com> | 2013-03-11 14:34:56 -0700 |
---|---|---|
committer | Alex Ray <aray@google.com> | 2013-07-30 13:57:01 -0700 |
commit | 31ba37f1c80801ee128749d4772c47f23323a3be (patch) | |
tree | d8a4c8bc38b8e8eda1e189d6de2b29b88b122b1b /include/utils | |
parent | 6090df85a8a227db0bf407b7877b2777937e6427 (diff) | |
download | system_core-31ba37f1c80801ee128749d4772c47f23323a3be.zip system_core-31ba37f1c80801ee128749d4772c47f23323a3be.tar.gz system_core-31ba37f1c80801ee128749d4772c47f23323a3be.tar.bz2 |
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
Diffstat (limited to 'include/utils')
-rw-r--r-- | include/utils/Condition.h | 13 | ||||
-rw-r--r-- | include/utils/Thread.h | 3 |
2 files changed, 16 insertions, 0 deletions
diff --git a/include/utils/Condition.h b/include/utils/Condition.h index 8852d53..e63ba7e 100644 --- a/include/utils/Condition.h +++ b/include/utils/Condition.h @@ -48,6 +48,11 @@ public: SHARED = 1 }; + enum WakeUpType { + WAKE_UP_ONE = 0, + WAKE_UP_ALL = 1 + }; + Condition(); Condition(int type); ~Condition(); @@ -57,6 +62,14 @@ public: status_t waitRelative(Mutex& mutex, nsecs_t reltime); // Signal the condition variable, allowing one thread to continue. 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. void broadcast(); diff --git a/include/utils/Thread.h b/include/utils/Thread.h index 4a34abd..df30611 100644 --- a/include/utils/Thread.h +++ b/include/utils/Thread.h @@ -67,6 +67,9 @@ public: // Do not call from this object's thread; will return WOULD_BLOCK in that case. status_t join(); + // Indicates whether this thread is running or not. + bool isRunning() const; + #ifdef HAVE_ANDROID_OS // Return the thread's kernel ID, same as the thread itself calling gettid() or // androidGetTid(), or -1 if the thread is not running. |