Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed242de3 authored by Jeff Brown's avatar Jeff Brown
Browse files

Reduce lock thrashing in native Looper.

In the common case, there is nothing interesting happening on the native
Looper besides occasional wake ups.  There is no point grabbing the
semaphore then.

Change-Id: Ib5c426d0e158dfa37891b7ff5537b6f833592fad
parent e0e09d47
Loading
Loading
Loading
Loading
+38 −32
Original line number Diff line number Diff line
@@ -184,8 +184,7 @@ 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);
    bool acquiredLock = false;
    for (int i = 0; i < eventCount; i++) {
        int fd = eventItems[i].data.fd;
        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);
            }
        } else {
            if (! acquiredLock) {
                mLock.lock();
                acquiredLock = true;
            }

            ssize_t requestIndex = mRequests.indexOfKey(fd);
            if (requestIndex >= 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++) {