diff options
author | Jeff Brown <jeffbrown@google.com> | 2010-06-16 01:53:36 -0700 |
---|---|---|
committer | Alex Ray <aray@google.com> | 2013-07-30 13:56:53 -0700 |
commit | 9efaaa43595307786dbf06760823c25cb16b1925 (patch) | |
tree | 4312ce89bea39da6828c53fab8a1acf15f243646 /libs | |
parent | 80d9c1cfb0642e680c559a854d09514c2fc72edc (diff) | |
download | system_core-9efaaa43595307786dbf06760823c25cb16b1925.zip system_core-9efaaa43595307786dbf06760823c25cb16b1925.tar.gz system_core-9efaaa43595307786dbf06760823c25cb16b1925.tar.bz2 |
Even more native input dispatch work in progress.
Added more tests.
Fixed a regression in Vector.
Fixed bugs in pointer tracking.
Fixed a starvation issue in PollLoop when setting or removing callbacks.
Fixed a couple of policy nits.
Modified the internal representation of MotionEvent to be more
efficient and more consistent.
Added code to skip/cancel virtual key processing when there are multiple
pointers down. This helps to better disambiguate virtual key presses
from stray touches (such as cheek presses).
Change-Id: I2a7d2cce0195afb9125b23378baa94fd2fc6671c
Diffstat (limited to 'libs')
-rw-r--r-- | libs/utils/PollLoop.cpp | 16 | ||||
-rw-r--r-- | libs/utils/VectorImpl.cpp | 22 | ||||
-rw-r--r-- | libs/utils/tests/PollLoop_test.cpp | 42 | ||||
-rw-r--r-- | libs/utils/tests/TestHelpers.h | 35 |
4 files changed, 74 insertions, 41 deletions
diff --git a/libs/utils/PollLoop.cpp b/libs/utils/PollLoop.cpp index 90a3e8b..20a4d13 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 diff --git a/libs/utils/VectorImpl.cpp b/libs/utils/VectorImpl.cpp index b09c6ca..289c826 100644 --- a/libs/utils/VectorImpl.cpp +++ b/libs/utils/VectorImpl.cpp @@ -108,7 +108,7 @@ size_t VectorImpl::capacity() const ssize_t VectorImpl::insertVectorAt(const VectorImpl& vector, size_t index) { - return insertAt(vector.arrayImpl(), index, vector.size()); + return insertArrayAt(vector.arrayImpl(), index, vector.size()); } ssize_t VectorImpl::appendVector(const VectorImpl& vector) @@ -116,6 +116,22 @@ ssize_t VectorImpl::appendVector(const VectorImpl& vector) return insertVectorAt(vector, size()); } +ssize_t VectorImpl::insertArrayAt(const void* array, size_t index, size_t length) +{ + if (index > size()) + return BAD_INDEX; + void* where = _grow(index, length); + if (where) { + _do_copy(where, array, length); + } + return where ? index : (ssize_t)NO_MEMORY; +} + +ssize_t VectorImpl::appendArray(const void* array, size_t length) +{ + return insertArrayAt(array, size(), length); +} + ssize_t VectorImpl::insertAt(size_t index, size_t numItems) { return insertAt(0, index, numItems); @@ -220,9 +236,9 @@ ssize_t VectorImpl::add() return add(0); } -ssize_t VectorImpl::add(const void* item, size_t numItems) +ssize_t VectorImpl::add(const void* item) { - return insertAt(item, size(), numItems); + return insertAt(item, size()); } ssize_t VectorImpl::replaceAt(size_t index) diff --git a/libs/utils/tests/PollLoop_test.cpp b/libs/utils/tests/PollLoop_test.cpp index 6c719c8..4848c0f 100644 --- a/libs/utils/tests/PollLoop_test.cpp +++ b/libs/utils/tests/PollLoop_test.cpp @@ -16,34 +16,6 @@ namespace android { -class Pipe { -public: - int sendFd; - int receiveFd; - - Pipe() { - int fds[2]; - ::pipe(fds); - - receiveFd = fds[0]; - sendFd = fds[1]; - } - - ~Pipe() { - ::close(sendFd); - ::close(receiveFd); - } - - bool writeSignal() { - return ::write(sendFd, "*", 1) == 1; - } - - bool readSignal() { - char buf[1]; - return ::read(receiveFd, buf, 1) == 1; - } -}; - class DelayedWake : public DelayedTask { sp<PollLoop> mPollLoop; @@ -195,7 +167,7 @@ TEST_F(PollLoopTest, PollOnce_WhenZeroTimeoutAndSignalledFD_ImmediatelyInvokesCa Pipe pipe; StubCallbackHandler handler(true); - ASSERT_TRUE(pipe.writeSignal()); + ASSERT_EQ(OK, pipe.writeSignal()); handler.setCallback(mPollLoop, pipe.receiveFd, POLL_IN); StopWatch stopWatch("pollOnce"); @@ -243,7 +215,7 @@ TEST_F(PollLoopTest, PollOnce_WhenNonZeroTimeoutAndSignalledFDBeforeWaiting_Imme bool result = mPollLoop->pollOnce(100); int32_t elapsedMillis = ns2ms(stopWatch.elapsedTime()); - ASSERT_TRUE(pipe.readSignal()) + ASSERT_EQ(OK, pipe.readSignal()) << "signal should actually have been written"; EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should be approx. zero"; @@ -269,7 +241,7 @@ TEST_F(PollLoopTest, PollOnce_WhenNonZeroTimeoutAndSignalledFDWhileWaiting_Promp bool result = mPollLoop->pollOnce(1000); int32_t elapsedMillis = ns2ms(stopWatch.elapsedTime()); - ASSERT_TRUE(pipe.readSignal()) + ASSERT_EQ(OK, pipe.readSignal()) << "signal should actually have been written"; EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. equal signal delay"; @@ -295,7 +267,7 @@ TEST_F(PollLoopTest, PollOnce_WhenCallbackAddedThenRemoved_CallbackShouldNotBeIn bool result = mPollLoop->pollOnce(100); int32_t elapsedMillis = ns2ms(stopWatch.elapsedTime()); - ASSERT_TRUE(pipe.readSignal()) + ASSERT_EQ(OK, pipe.readSignal()) << "signal should actually have been written"; EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. equal timeout because FD was no longer registered"; @@ -318,7 +290,7 @@ TEST_F(PollLoopTest, PollOnce_WhenCallbackReturnsFalse_CallbackShouldNotBeInvoke bool result = mPollLoop->pollOnce(0); int32_t elapsedMillis = ns2ms(stopWatch.elapsedTime()); - ASSERT_TRUE(pipe.readSignal()) + ASSERT_EQ(OK, pipe.readSignal()) << "signal should actually have been written"; EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. equal zero because FD was already signalled"; @@ -334,7 +306,7 @@ TEST_F(PollLoopTest, PollOnce_WhenCallbackReturnsFalse_CallbackShouldNotBeInvoke result = mPollLoop->pollOnce(0); elapsedMillis = ns2ms(stopWatch.elapsedTime()); - ASSERT_TRUE(pipe.readSignal()) + ASSERT_EQ(OK, pipe.readSignal()) << "signal should actually have been written"; EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. equal zero because timeout was zero"; @@ -382,7 +354,7 @@ TEST_F(PollLoopTest, PollOnce_WhenCallbackAddedTwice_OnlySecondCallbackShouldBeI bool result = mPollLoop->pollOnce(100); int32_t elapsedMillis = ns2ms(stopWatch.elapsedTime()); - ASSERT_TRUE(pipe.readSignal()) + ASSERT_EQ(OK, pipe.readSignal()) << "signal should actually have been written"; EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. zero because FD was already signalled"; diff --git a/libs/utils/tests/TestHelpers.h b/libs/utils/tests/TestHelpers.h index e55af3c..d8e985e 100644 --- a/libs/utils/tests/TestHelpers.h +++ b/libs/utils/tests/TestHelpers.h @@ -21,6 +21,41 @@ namespace android { +class Pipe { +public: + int sendFd; + int receiveFd; + + Pipe() { + int fds[2]; + ::pipe(fds); + + receiveFd = fds[0]; + sendFd = fds[1]; + } + + ~Pipe() { + if (sendFd != -1) { + ::close(sendFd); + } + + if (receiveFd != -1) { + ::close(receiveFd); + } + } + + status_t writeSignal() { + ssize_t nWritten = ::write(sendFd, "*", 1); + return nWritten == 1 ? 0 : -errno; + } + + status_t readSignal() { + char buf[1]; + ssize_t nRead = ::read(receiveFd, buf, 1); + return nRead == 1 ? 0 : nRead == 0 ? -EPIPE : -errno; + } +}; + class DelayedTask : public Thread { int mDelayMillis; |