From d6cd6ba6d387d1d6e1c8cd8077ff6ae596fb7065 Mon Sep 17 00:00:00 2001 From: Fan Xu Date: Thu, 15 Nov 2018 16:46:55 -0800 Subject: Add garbage collecion function to BufferHubService Now BufferHubService will cleanup unused BufferClient automatically. If the mClientList storing weak pointer, when user side's strong pointer dies, the refcount will become 0 and the allocated memory in the service will get freed. Test: BufferHubBuffer_test (passed) Bug: 119623209 Change-Id: I1390f878bf44afd7c1a5cccaeb34a9d13dab3db0 --- services/bufferhub/BufferHubService.cpp | 2 +- services/bufferhub/include/bufferhub/BufferHubService.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/bufferhub/BufferHubService.cpp b/services/bufferhub/BufferHubService.cpp index fc5ad1dbbf..1a38dd80b7 100644 --- a/services/bufferhub/BufferHubService.cpp +++ b/services/bufferhub/BufferHubService.cpp @@ -58,7 +58,7 @@ Return BufferHubService::importBuffer(const hidl_handle& /*nativeHandle*/, return Void(); } -hidl_handle BufferHubService::registerToken(const BufferClient* client) { +hidl_handle BufferHubService::registerToken(const wp& client) { uint32_t token; std::lock_guard lock(mTokenMapMutex); do { diff --git a/services/bufferhub/include/bufferhub/BufferHubService.h b/services/bufferhub/include/bufferhub/BufferHubService.h index 5441750e9a..e3f657fdd7 100644 --- a/services/bufferhub/include/bufferhub/BufferHubService.h +++ b/services/bufferhub/include/bufferhub/BufferHubService.h @@ -46,18 +46,18 @@ public: // Non-binder functions // Internal help function for IBufferClient::duplicate. - hidl_handle registerToken(const BufferClient* client); + hidl_handle registerToken(const wp& client); private: // List of active BufferClient for bookkeeping. std::mutex mClientListMutex; - std::vector> mClientList GUARDED_BY(mClientListMutex); + std::vector> mClientList GUARDED_BY(mClientListMutex); // TODO(b/118180214): use a more secure implementation std::mt19937 mTokenEngine; // The mapping from token to the client creates it. std::mutex mTokenMapMutex; - std::map mTokenMap GUARDED_BY(mTokenMapMutex); + std::map> mTokenMap GUARDED_BY(mTokenMapMutex); }; } // namespace implementation -- cgit v1.2.3-59-g8ed1b