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

Commit 8f8374d7 authored by Dan Stoza's avatar Dan Stoza
Browse files

DispSync: Actually wait forever

When computeNextEventTimeLocked returns INT64_MAX (because there are
currently no listeners), wait until the condition variable is
signaled instead of waiting for a long timeout. Since the condition
variable timeout is specified using CLOCK_REALTIME behind the scenes,
we can receive false wakeups in the presence of large system clock
changes.

Bug: 28152577
Change-Id: I88dbab5d5d0776cb25dea76a4574db055b308fd1
parent 6328134d
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -97,7 +97,6 @@ public:
    virtual bool threadLoop() {
        status_t err;
        nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
        nsecs_t nextEventTime = 0;

        while (true) {
            Vector<CallbackInvocation> callbackInvocations;
@@ -127,16 +126,21 @@ public:
                    continue;
                }

                nextEventTime = computeNextEventTimeLocked(now);
                targetTime = nextEventTime;
                targetTime = computeNextEventTimeLocked(now);

                bool isWakeup = false;

                if (now < targetTime) {
                    if (kTraceDetailedInfo) ATRACE_NAME("DispSync waiting");

                    if (targetTime == INT64_MAX) {
                        ALOGV("[%s] Waiting forever", mName);
                        err = mCond.wait(mMutex);
                    } else {
                        ALOGV("[%s] Waiting until %" PRId64, mName,
                                ns2us(targetTime));
                    if (kTraceDetailedInfo) ATRACE_NAME("DispSync waiting");
                        err = mCond.waitRelative(mMutex, targetTime - now);
                    }

                    if (err == TIMED_OUT) {
                        isWakeup = true;