Loading media/bufferpool/aidl/default/Accessor.cpp +23 −7 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #define LOG_TAG "AidlBufferPoolAcc" //#define LOG_NDEBUG 0 #include <android-base/no_destructor.h> #include <sys/types.h> #include <stdint.h> #include <time.h> Loading @@ -41,7 +43,25 @@ static constexpr uint32_t kSeqIdVndkBit = 0; #endif static constexpr uint32_t kSeqIdMax = 0x7fffffff; uint32_t Accessor::sSeqId = time(nullptr) & kSeqIdMax; Accessor::ConnectionIdGenerator::ConnectionIdGenerator() { mSeqId = static_cast<uint32_t>(time(nullptr) & kSeqIdMax); mPid = static_cast<int32_t>(getpid()); } ConnectionId Accessor::ConnectionIdGenerator::getConnectionId() { uint32_t seq; { std::lock_guard<std::mutex> l(mLock); seq = mSeqId; if (mSeqId == kSeqIdMax) { mSeqId = 0; } else { ++mSeqId; } } return (int64_t)mPid << 32 | seq | kSeqIdVndkBit; } namespace { // anonymous namespace Loading Loading @@ -239,13 +259,14 @@ BufferPoolStatus Accessor::connect( uint32_t *pMsgId, StatusDescriptor* statusDescPtr, InvalidationDescriptor* invDescPtr) { static ::android::base::NoDestructor<ConnectionIdGenerator> sConIdGenerator; std::shared_ptr<Connection> newConnection = ::ndk::SharedRefBase::make<Connection>(); BufferPoolStatus status = ResultStatus::CRITICAL_ERROR; { std::lock_guard<std::mutex> lock(mBufferPool.mMutex); if (newConnection) { int32_t pid = getpid(); ConnectionId id = (int64_t)pid << 32 | sSeqId | kSeqIdVndkBit; ConnectionId id = sConIdGenerator->getConnectionId(); status = mBufferPool.mObserver.open(id, statusDescPtr); if (status == ResultStatus::OK) { newConnection->initialize(ref<Accessor>(), id); Loading @@ -255,11 +276,6 @@ BufferPoolStatus Accessor::connect( mBufferPool.mConnectionIds.insert(id); mBufferPool.mInvalidationChannel.getDesc(invDescPtr); mBufferPool.mInvalidation.onConnect(id, observer); if (sSeqId == kSeqIdMax) { sSeqId = 0; } else { ++sSeqId; } } } Loading media/bufferpool/aidl/default/Accessor.h +8 −1 Original line number Diff line number Diff line Loading @@ -189,7 +189,14 @@ struct Accessor : public BnAccessor { private: // ConnectionId = pid : (timestamp_created + seqId) // in order to guarantee uniqueness for each connection static uint32_t sSeqId; struct ConnectionIdGenerator { int32_t mPid; uint32_t mSeqId; std::mutex mLock; ConnectionIdGenerator(); ConnectionId getConnectionId(); }; const std::shared_ptr<BufferPoolAllocator> mAllocator; nsecs_t mScheduleEvictTs; Loading media/bufferpool/aidl/default/Android.bp +3 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,9 @@ cc_library { export_include_dirs: [ "include", ], header_libs: [ "libbase_headers", ], shared_libs: [ "libbinder_ndk", "libcutils", Loading Loading
media/bufferpool/aidl/default/Accessor.cpp +23 −7 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #define LOG_TAG "AidlBufferPoolAcc" //#define LOG_NDEBUG 0 #include <android-base/no_destructor.h> #include <sys/types.h> #include <stdint.h> #include <time.h> Loading @@ -41,7 +43,25 @@ static constexpr uint32_t kSeqIdVndkBit = 0; #endif static constexpr uint32_t kSeqIdMax = 0x7fffffff; uint32_t Accessor::sSeqId = time(nullptr) & kSeqIdMax; Accessor::ConnectionIdGenerator::ConnectionIdGenerator() { mSeqId = static_cast<uint32_t>(time(nullptr) & kSeqIdMax); mPid = static_cast<int32_t>(getpid()); } ConnectionId Accessor::ConnectionIdGenerator::getConnectionId() { uint32_t seq; { std::lock_guard<std::mutex> l(mLock); seq = mSeqId; if (mSeqId == kSeqIdMax) { mSeqId = 0; } else { ++mSeqId; } } return (int64_t)mPid << 32 | seq | kSeqIdVndkBit; } namespace { // anonymous namespace Loading Loading @@ -239,13 +259,14 @@ BufferPoolStatus Accessor::connect( uint32_t *pMsgId, StatusDescriptor* statusDescPtr, InvalidationDescriptor* invDescPtr) { static ::android::base::NoDestructor<ConnectionIdGenerator> sConIdGenerator; std::shared_ptr<Connection> newConnection = ::ndk::SharedRefBase::make<Connection>(); BufferPoolStatus status = ResultStatus::CRITICAL_ERROR; { std::lock_guard<std::mutex> lock(mBufferPool.mMutex); if (newConnection) { int32_t pid = getpid(); ConnectionId id = (int64_t)pid << 32 | sSeqId | kSeqIdVndkBit; ConnectionId id = sConIdGenerator->getConnectionId(); status = mBufferPool.mObserver.open(id, statusDescPtr); if (status == ResultStatus::OK) { newConnection->initialize(ref<Accessor>(), id); Loading @@ -255,11 +276,6 @@ BufferPoolStatus Accessor::connect( mBufferPool.mConnectionIds.insert(id); mBufferPool.mInvalidationChannel.getDesc(invDescPtr); mBufferPool.mInvalidation.onConnect(id, observer); if (sSeqId == kSeqIdMax) { sSeqId = 0; } else { ++sSeqId; } } } Loading
media/bufferpool/aidl/default/Accessor.h +8 −1 Original line number Diff line number Diff line Loading @@ -189,7 +189,14 @@ struct Accessor : public BnAccessor { private: // ConnectionId = pid : (timestamp_created + seqId) // in order to guarantee uniqueness for each connection static uint32_t sSeqId; struct ConnectionIdGenerator { int32_t mPid; uint32_t mSeqId; std::mutex mLock; ConnectionIdGenerator(); ConnectionId getConnectionId(); }; const std::shared_ptr<BufferPoolAllocator> mAllocator; nsecs_t mScheduleEvictTs; Loading
media/bufferpool/aidl/default/Android.bp +3 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,9 @@ cc_library { export_include_dirs: [ "include", ], header_libs: [ "libbase_headers", ], shared_libs: [ "libbinder_ndk", "libcutils", Loading