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

Commit c2de6336 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Codec2 utils: wake up waiters when the client process died" into main am: a69f9500

parents 7297ae7d a69f9500
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -117,6 +117,11 @@ struct C2SyncVariables {
     */
    void notifyAll();

    /**
     * Invalide current sync variables on the death of the other process.
     */
    void invalidate();

    C2SyncVariables() {}

private:
+52 −4
Original line number Diff line number Diff line
@@ -396,6 +396,12 @@ private:
                    if (c2Fence) {
                        *c2Fence = _C2FenceFactory::CreateSurfaceFence(mSyncMem, waitId);
                    }
                    if (mInvalidated) {
                        if (c2Fence) {
                            *c2Fence = C2Fence();
                        }
                        return C2_BAD_STATE;
                    }
                    return C2_BLOCKING;
                }
                if (syncVar->getSyncStatusLocked() != C2SyncVariables::STATUS_ACTIVE) {
@@ -404,6 +410,12 @@ private:
                    if (c2Fence) {
                        *c2Fence = _C2FenceFactory::CreateSurfaceFence(mSyncMem, waitId);
                    }
                    if (mInvalidated) {
                        if (c2Fence) {
                            *c2Fence = C2Fence();
                        }
                        return C2_BAD_STATE;
                    }
                    return C2_BLOCKING;
                }
                syncVar->notifyDequeuedLocked();
@@ -690,7 +702,6 @@ public:
            }
        }
        int migrated = 0;
        std::shared_ptr<C2SurfaceSyncMemory> oldMem;
        // poolDatas dtor should not be called during lock is held.
        std::shared_ptr<C2BufferQueueBlockPoolData>
                poolDatas[NUM_BUFFER_SLOTS];
@@ -708,8 +719,22 @@ public:
                mGeneration = 0;
                ALOGD("configuring null producer: igbp_information(%d)", bqInformation);
            }
            oldMem = mSyncMem; // preven destruction while locked.
            if (mInvalidated) {
                return;
            }
            {
                std::unique_lock<std::mutex> memLock(mSyncMemMutex);
                mOldMem = mSyncMem; // prevent destruction while locked.
                                    // The waiters from the old memory will be
                                    // woken up by the client after this
                                    // configuration from HAL being finished.
                                    // But we will keep this in case of the
                                    // client being dead in between.
                                    // In the case the death listener will wake
                                    // up the wiators for the old memory using
                                    // mOldMem here.
                mSyncMem = c2SyncMem;
            }
            C2SyncVariables *syncVar = mSyncMem ? mSyncMem->mem() : nullptr;
            if (syncVar) {
                syncVar->lock();
@@ -736,6 +761,9 @@ public:
                // is no longer valid.
                mIgbpValidityToken = std::make_shared<int>(0);
            }
            if (mInvalidated) {
                mIgbpValidityToken = std::make_shared<int>(0);
            }
            for (int i = 0; i < NUM_BUFFER_SLOTS; ++i) {
                mBuffers[i] = buffers[i];
                mPoolDatas[i] = poolDatas[i];
@@ -754,8 +782,26 @@ public:
    }

    void invalidate() {
        mInvalidated = true;
        std::shared_ptr<C2SurfaceSyncMemory> syncMem;
        std::shared_ptr<C2SurfaceSyncMemory> oldMem;
        {
            std::unique_lock<std::mutex> l(mSyncMemMutex);
            bool old = mInvalidated.exchange(true);
            if (old) {
                return;
            }
            syncMem = mSyncMem;
            oldMem = mOldMem;
        }
        mIgbpValidityToken.reset();
        C2SyncVariables *syncVar = syncMem ? syncMem->mem(): nullptr;
        if (syncVar) {
            syncVar->invalidate();
        }
        C2SyncVariables *oldVar = oldMem ? oldMem->mem(): nullptr;
        if (oldVar) {
            oldVar->invalidate();
        }
    }

private:
@@ -780,7 +826,9 @@ private:
    sp<GraphicBuffer> mBuffers[NUM_BUFFER_SLOTS];
    std::weak_ptr<C2BufferQueueBlockPoolData> mPoolDatas[NUM_BUFFER_SLOTS];

    std::mutex mSyncMemMutex;
    std::shared_ptr<C2SurfaceSyncMemory> mSyncMem;
    std::shared_ptr<C2SurfaceSyncMemory> mOldMem;

    // IGBP invalidation notification token.
    // The buffers(C2BufferQueueBlockPoolData) has the reference to the IGBP where
+5 −0
Original line number Diff line number Diff line
@@ -284,6 +284,11 @@ void C2SyncVariables::notifyAll() {
    this->unlock();
}

void C2SyncVariables::invalidate() {
    mCond++;
    (void) syscall(__NR_futex, &mCond, FUTEX_REQUEUE, INT_MAX, (void *)INT_MAX, &mLock, 0);
}

int C2SyncVariables::signal() {
    mCond++;