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

Commit 7ea287a0 authored by Santos Cordon's avatar Santos Cordon
Browse files

Switch away from std::async for proximity-active callback.

By default, std::async() returns a future with the expectation that the
caller monitors it. By ignoring the future we forced the future's
destructor to run which waits on the thread by default (causing a
deadlock). Since we don't really want to monitor the future for our
purposes here anyway, we're switching to a detached thread with
this change.

Test: Verify that when sensor is enabled, there is an additional
      refresh rate vote for the rate specified in config file.
Bug: 175793106
Change-Id: Icfc2fc7e8dc84c614a9a19d7f23c9ce6d55cc6f0
parent a4f6c1c0
Loading
Loading
Loading
Loading
+11 −13
Original line number Diff line number Diff line
@@ -1626,19 +1626,17 @@ void SensorService::onProximityActiveLocked(bool isActive) {
}

void SensorService::notifyProximityStateLocked(
        const std::vector<sp<ProximityActiveListener>>& listnrs) {
    std::async(
        std::launch::async,
        [](uint64_t mySeq, bool isActive, std::vector<sp<ProximityActiveListener>> listeners) {
        const std::vector<sp<ProximityActiveListener>>& listeners) {
    const bool isActive = mProximityActiveCount > 0;
    const uint64_t mySeq = ++curProxCallbackSeq;
    std::thread t([isActive, mySeq, listenersCopy = listeners]() {
        while (completedCallbackSeq.load() != mySeq - 1)
            std::this_thread::sleep_for(1ms);
            for (auto& listener : listeners)
        for (auto& listener : listenersCopy)
            listener->onProximityActive(isActive);
        completedCallbackSeq++;
        },
        ++curProxCallbackSeq, mProximityActiveCount > 0,
        listnrs /* (this is meant to be a copy) */
    );
    });
    t.detach();
}

status_t SensorService::addProximityActiveListener(const sp<ProximityActiveListener>& callback) {