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

Commit 30873bfd authored by Andreas Huber's avatar Andreas Huber
Browse files

Unregister any handlers still registered on now "dead" ALoopers

upon the death of an ALooper.

Change-Id: I64c0835b8db04486204f3d0fa7173ee53708a116
related-to-bug: 10106648
parent 9610adc3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ struct ALooperRoster {
            const sp<ALooper> looper, const sp<AHandler> &handler);

    void unregisterHandler(ALooper::handler_id handlerID);
    void unregisterStaleHandlers();

    status_t postMessage(const sp<AMessage> &msg, int64_t delayUs = 0);
    void deliverMessage(const sp<AMessage> &msg);
+4 −0
Original line number Diff line number Diff line
@@ -72,6 +72,10 @@ ALooper::ALooper()

ALooper::~ALooper() {
    stop();

    // Since this looper is "dead" (or as good as dead by now),
    // have ALooperRoster unregister any handlers still registered for it.
    gLooperRoster.unregisterStaleHandlers();
}

void ALooper::setName(const char *name) {
+14 −0
Original line number Diff line number Diff line
@@ -71,6 +71,20 @@ void ALooperRoster::unregisterHandler(ALooper::handler_id handlerID) {
    mHandlers.removeItemsAt(index);
}

void ALooperRoster::unregisterStaleHandlers() {
    Mutex::Autolock autoLock(mLock);

    for (size_t i = mHandlers.size(); i-- > 0;) {
        const HandlerInfo &info = mHandlers.valueAt(i);

        sp<ALooper> looper = info.mLooper.promote();
        if (looper == NULL) {
            ALOGV("Unregistering stale handler %d", mHandlers.keyAt(i));
            mHandlers.removeItemsAt(i);
        }
    }
}

status_t ALooperRoster::postMessage(
        const sp<AMessage> &msg, int64_t delayUs) {
    Mutex::Autolock autoLock(mLock);