Merge "Reduce lock thrashing in native Looper." into gingerbread

This commit is contained in:
Jeff Brown
2010-09-17 17:26:02 -07:00
committed by Android (Google) Code Review

View File

@@ -184,8 +184,7 @@ int Looper::pollInner(int timeoutMillis) {
#if DEBUG_POLL_AND_WAKE #if DEBUG_POLL_AND_WAKE
LOGD("%p ~ pollOnce - handling events from %d fds", this, eventCount); LOGD("%p ~ pollOnce - handling events from %d fds", this, eventCount);
#endif #endif
{ // acquire lock bool acquiredLock = false;
AutoMutex _l(mLock);
for (int i = 0; i < eventCount; i++) { for (int i = 0; i < eventCount; i++) {
int fd = eventItems[i].data.fd; int fd = eventItems[i].data.fd;
uint32_t epollEvents = eventItems[i].events; uint32_t epollEvents = eventItems[i].events;
@@ -203,6 +202,11 @@ int Looper::pollInner(int timeoutMillis) {
LOGW("Ignoring unexpected epoll events 0x%x on wake read pipe.", epollEvents); LOGW("Ignoring unexpected epoll events 0x%x on wake read pipe.", epollEvents);
} }
} else { } else {
if (! acquiredLock) {
mLock.lock();
acquiredLock = true;
}
ssize_t requestIndex = mRequests.indexOfKey(fd); ssize_t requestIndex = mRequests.indexOfKey(fd);
if (requestIndex >= 0) { if (requestIndex >= 0) {
int events = 0; int events = 0;
@@ -221,6 +225,8 @@ int Looper::pollInner(int timeoutMillis) {
} }
} }
} }
if (acquiredLock) {
mLock.unlock();
} }
for (size_t i = 0; i < mResponses.size(); i++) { for (size_t i = 0; i < mResponses.size(); i++) {