diff options
author | 2013-03-11 21:41:18 +0000 | |
---|---|---|
committer | 2013-03-11 21:41:18 +0000 | |
commit | 47e83a14d04290422a1740b9d3fc4e5b1242b9f1 (patch) | |
tree | 7eaec6602bcaec43690361faca7bd6ce305a61d1 | |
parent | 8a6f709e2a33a27a313487b0f3c3a7481b2d5702 (diff) | |
parent | c75412dcdd617423a033e4a647f43b35af1fc0c4 (diff) |
am c75412dc: am dbca4a0e: Merge "Add Thread::isRunning and Condition::signal(WakeUpType)" into jb-mr2-dev
* commit 'c75412dcdd617423a033e4a647f43b35af1fc0c4':
Add Thread::isRunning and Condition::signal(WakeUpType)
-rw-r--r-- | include/utils/Condition.h | 13 | ||||
-rw-r--r-- | include/utils/Thread.h | 3 | ||||
-rw-r--r-- | libs/utils/Threads.cpp | 5 |
3 files changed, 21 insertions, 0 deletions
diff --git a/include/utils/Condition.h b/include/utils/Condition.h index 8852d53330..e63ba7e69c 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 4a34abd788..df30611352 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. diff --git a/libs/utils/Threads.cpp b/libs/utils/Threads.cpp index cbf4ef628c..e0f12dc02e 100644 --- a/libs/utils/Threads.cpp +++ b/libs/utils/Threads.cpp @@ -846,6 +846,11 @@ status_t Thread::join() return mStatus; } +bool Thread::isRunning() const { + Mutex::Autolock _l(mLock); + return mRunning; +} + #ifdef HAVE_ANDROID_OS pid_t Thread::getTid() const { |