Loading media/codec2/vndk/include/C2SurfaceSyncObj.h +5 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,11 @@ struct C2SyncVariables { */ void notifyAll(); /** * Invalide current sync variables on the death of the other process. */ void invalidate(); C2SyncVariables() {} private: Loading media/codec2/vndk/platform/C2BqBuffer.cpp +52 −4 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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(); Loading Loading @@ -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]; Loading @@ -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(); Loading @@ -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]; Loading @@ -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: Loading @@ -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 Loading media/codec2/vndk/platform/C2SurfaceSyncObj.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -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++; Loading Loading
media/codec2/vndk/include/C2SurfaceSyncObj.h +5 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,11 @@ struct C2SyncVariables { */ void notifyAll(); /** * Invalide current sync variables on the death of the other process. */ void invalidate(); C2SyncVariables() {} private: Loading
media/codec2/vndk/platform/C2BqBuffer.cpp +52 −4 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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(); Loading Loading @@ -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]; Loading @@ -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(); Loading @@ -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]; Loading @@ -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: Loading @@ -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 Loading
media/codec2/vndk/platform/C2SurfaceSyncObj.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -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++; Loading