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

Commit c6045544 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revert "Don't call epoll_wait with zero timeout unless watching FDs"" into main

parents 558b9543 ca68e181
Loading
Loading
Loading
Loading
+6 −13
Original line number Diff line number Diff line
@@ -216,18 +216,14 @@ int Looper::pollInner(int timeoutMillis) {
    mResponses.clear();
    mResponseIndex = 0;

    struct epoll_event eventItems[EPOLL_MAX_EVENTS];
    int eventCount = 0;
    // Poll if we need to wait or have requests that may have FD events.
    if (timeoutMillis != 0 || mHasRequests) {
    // We are about to idle.
    std::atomic_store_explicit(&mPolling, true, std::memory_order_relaxed);

        eventCount = epoll_wait(mEpollFd.get(), eventItems, EPOLL_MAX_EVENTS, timeoutMillis);
    struct epoll_event eventItems[EPOLL_MAX_EVENTS];
    int eventCount = epoll_wait(mEpollFd.get(), eventItems, EPOLL_MAX_EVENTS, timeoutMillis);

    // No longer idling.
    std::atomic_store_explicit(&mPolling, false, std::memory_order_relaxed);
    }

    // Acquire lock.
    mLock.lock();
@@ -497,8 +493,6 @@ int Looper::addFd(int fd, int ident, int events, const sp<LooperCallback>& callb
            mRequests.emplace(seq, request);
            seq_it->second = seq;
        }

        mHasRequests = !mRequests.empty();
    } // release lock
    return 1;
}
@@ -566,7 +560,6 @@ int Looper::removeSequenceNumberLocked(SequenceNumber seq) {
    // updating the epoll set so that we avoid accidentally leaking callbacks.
    mRequests.erase(request_it);
    mSequenceNumberByFd.erase(fd);
    mHasRequests = !mRequests.empty();

    int epollResult = epoll_ctl(mEpollFd.get(), EPOLL_CTL_DEL, fd, nullptr);
    if (epollResult < 0) {
+6 −3
Original line number Diff line number Diff line
@@ -708,15 +708,18 @@ TEST_F(LooperTest, RemoveMessage_WhenRemovingAllMessagesForHandler_ShouldRemoveT
    mLooper->sendMessage(handler, Message(MSG_TEST3));
    mLooper->removeMessages(handler);

    constexpr int MIN_POLL_TIMEOUT_MS = 1;
    int result = mLooper->pollOnce(MIN_POLL_TIMEOUT_MS);
    StopWatch stopWatch("pollOnce");
    int result = mLooper->pollOnce(0);
    int32_t elapsedMillis = ns2ms(stopWatch.elapsedTime());

    EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
            << "elapsed time should approx. zero because message was sent so looper was awoken";
    EXPECT_EQ(Looper::POLL_WAKE, result)
            << "pollOnce result should be Looper::POLL_WAKE because looper was awoken";
    EXPECT_EQ(size_t(0), handler->messages.size())
            << "no messages to handle";

    result = mLooper->pollOnce(MIN_POLL_TIMEOUT_MS);
    result = mLooper->pollOnce(0);

    EXPECT_EQ(Looper::POLL_TIMEOUT, result)
            << "pollOnce result should be Looper::POLL_TIMEOUT because there was nothing to do";