summaryrefslogtreecommitdiff
path: root/libs/utils/PollLoop.cpp
diff options
context:
space:
mode:
author Jeff Brown <jeffbrown@google.com> 2010-06-17 13:31:07 -0700
committer Android Git Automerger <android-git-automerger@android.com> 2010-06-17 13:31:07 -0700
commit42bb545a54d89f0ddbb230d7a01ea4210c0f6c00 (patch)
tree081cfa7e6ae56ae6cdc67f4c95cfb6f0171bb434 /libs/utils/PollLoop.cpp
parent747f75dc0882138828ac2b2752c2872ccae49747 (diff)
parent5c225b1680e696ae8bbf505a1997d6f720672f74 (diff)
am 5c225b16: Even more native input dispatch work in progress.
Merge commit '5c225b1680e696ae8bbf505a1997d6f720672f74' into gingerbread-plus-aosp * commit '5c225b1680e696ae8bbf505a1997d6f720672f74': Even more native input dispatch work in progress.
Diffstat (limited to 'libs/utils/PollLoop.cpp')
-rw-r--r--libs/utils/PollLoop.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/libs/utils/PollLoop.cpp b/libs/utils/PollLoop.cpp
index 90a3e8b35374..20a4d1385bd1 100644
--- a/libs/utils/PollLoop.cpp
+++ b/libs/utils/PollLoop.cpp
@@ -11,7 +11,7 @@
#define DEBUG_POLL_AND_WAKE 0
// Debugs callback registration and invocation.
-#define DEBUG_CALLBACKS 1
+#define DEBUG_CALLBACKS 0
#include <cutils/log.h>
#include <utils/PollLoop.h>
@@ -22,7 +22,7 @@
namespace android {
PollLoop::PollLoop() :
- mPolling(false) {
+ mPolling(false), mWaiters(0) {
openWakePipe();
}
@@ -68,6 +68,9 @@ void PollLoop::closeWakePipe() {
bool PollLoop::pollOnce(int timeoutMillis) {
mLock.lock();
+ while (mWaiters != 0) {
+ mResume.wait(mLock);
+ }
mPolling = true;
mLock.unlock();
@@ -156,7 +159,9 @@ bool PollLoop::pollOnce(int timeoutMillis) {
Done:
mLock.lock();
mPolling = false;
- mAwake.broadcast();
+ if (mWaiters != 0) {
+ mAwake.broadcast();
+ }
mLock.unlock();
if (result) {
@@ -258,10 +263,15 @@ ssize_t PollLoop::getRequestIndexLocked(int fd) {
void PollLoop::wakeAndLock() {
mLock.lock();
+ mWaiters += 1;
while (mPolling) {
wake();
mAwake.wait(mLock);
}
+ mWaiters -= 1;
+ if (mWaiters == 0) {
+ mResume.signal();
+ }
}
} // namespace android