summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2010-09-18 00:16:29 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-09-18 00:16:29 -0700
commita2135836d1f9f134060c1cf20d5971c5cc833fc0 (patch)
treee5fea6c22a28a834ede060418732ae4ca9cc289d /libs
parentc6cb8d6dfb9273e7f4dda22b44ce86be3926a977 (diff)
parenta8d95248bdbb8ea0933ecf86d2859964324978a7 (diff)
downloadframeworks_base-a2135836d1f9f134060c1cf20d5971c5cc833fc0.zip
frameworks_base-a2135836d1f9f134060c1cf20d5971c5cc833fc0.tar.gz
frameworks_base-a2135836d1f9f134060c1cf20d5971c5cc833fc0.tar.bz2
am a8d95248: am 7d4739be: Merge "Reduce lock thrashing in native Looper." into gingerbread
Merge commit 'a8d95248bdbb8ea0933ecf86d2859964324978a7' * commit 'a8d95248bdbb8ea0933ecf86d2859964324978a7': Reduce lock thrashing in native Looper.
Diffstat (limited to 'libs')
-rw-r--r--libs/utils/Looper.cpp70
1 files changed, 38 insertions, 32 deletions
diff --git a/libs/utils/Looper.cpp b/libs/utils/Looper.cpp
index 4aa50d6..b46279e 100644
--- a/libs/utils/Looper.cpp
+++ b/libs/utils/Looper.cpp
@@ -184,44 +184,50 @@ int Looper::pollInner(int timeoutMillis) {
#if DEBUG_POLL_AND_WAKE
LOGD("%p ~ pollOnce - handling events from %d fds", this, eventCount);
#endif
- { // acquire lock
- AutoMutex _l(mLock);
- for (int i = 0; i < eventCount; i++) {
- int fd = eventItems[i].data.fd;
- uint32_t epollEvents = eventItems[i].events;
- if (fd == mWakeReadPipeFd) {
- if (epollEvents & EPOLLIN) {
+ bool acquiredLock = false;
+ for (int i = 0; i < eventCount; i++) {
+ int fd = eventItems[i].data.fd;
+ uint32_t epollEvents = eventItems[i].events;
+ if (fd == mWakeReadPipeFd) {
+ if (epollEvents & EPOLLIN) {
#if DEBUG_POLL_AND_WAKE
- LOGD("%p ~ pollOnce - awoken", this);
+ LOGD("%p ~ pollOnce - awoken", this);
#endif
- char buffer[16];
- ssize_t nRead;
- do {
- nRead = read(mWakeReadPipeFd, buffer, sizeof(buffer));
- } while ((nRead == -1 && errno == EINTR) || nRead == sizeof(buffer));
- } else {
- LOGW("Ignoring unexpected epoll events 0x%x on wake read pipe.", epollEvents);
- }
+ char buffer[16];
+ ssize_t nRead;
+ do {
+ nRead = read(mWakeReadPipeFd, buffer, sizeof(buffer));
+ } while ((nRead == -1 && errno == EINTR) || nRead == sizeof(buffer));
+ } else {
+ LOGW("Ignoring unexpected epoll events 0x%x on wake read pipe.", epollEvents);
+ }
+ } else {
+ if (! acquiredLock) {
+ mLock.lock();
+ acquiredLock = true;
+ }
+
+ ssize_t requestIndex = mRequests.indexOfKey(fd);
+ if (requestIndex >= 0) {
+ int events = 0;
+ if (epollEvents & EPOLLIN) events |= ALOOPER_EVENT_INPUT;
+ if (epollEvents & EPOLLOUT) events |= ALOOPER_EVENT_OUTPUT;
+ if (epollEvents & EPOLLERR) events |= ALOOPER_EVENT_ERROR;
+ if (epollEvents & EPOLLHUP) events |= ALOOPER_EVENT_HANGUP;
+
+ Response response;
+ response.events = events;
+ response.request = mRequests.valueAt(requestIndex);
+ mResponses.push(response);
} else {
- ssize_t requestIndex = mRequests.indexOfKey(fd);
- if (requestIndex >= 0) {
- int events = 0;
- if (epollEvents & EPOLLIN) events |= ALOOPER_EVENT_INPUT;
- if (epollEvents & EPOLLOUT) events |= ALOOPER_EVENT_OUTPUT;
- if (epollEvents & EPOLLERR) events |= ALOOPER_EVENT_ERROR;
- if (epollEvents & EPOLLHUP) events |= ALOOPER_EVENT_HANGUP;
-
- Response response;
- response.events = events;
- response.request = mRequests.valueAt(requestIndex);
- mResponses.push(response);
- } else {
- LOGW("Ignoring unexpected epoll events 0x%x on fd %d that is "
- "no longer registered.", epollEvents, fd);
- }
+ LOGW("Ignoring unexpected epoll events 0x%x on fd %d that is "
+ "no longer registered.", epollEvents, fd);
}
}
}
+ if (acquiredLock) {
+ mLock.unlock();
+ }
for (size_t i = 0; i < mResponses.size(); i++) {
const Response& response = mResponses.itemAt(i);