From 056d77d5238f54bb372950587b3554f9b391b99b Mon Sep 17 00:00:00 2001 From: Jaesoo Lee Date: Mon, 22 May 2017 15:53:25 +0900 Subject: [PATCH] configstore-utils: add feature to cache service handles Previously, the service handle for the configstore needs to be retrieved for every calls. This change reduces the time for retrieving multiple configstore items from a same client by caching the service handle per a configstore interface class. Bug: 38411900 Test: built and tested on sailfish. Change-Id: Iaff81e9f2b026aee0bd3865f5d5ed3fb7b6056e0 --- configstore/utils/include/configstore/Utils.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/configstore/utils/include/configstore/Utils.h b/configstore/utils/include/configstore/Utils.h index 862e81212e..ee8554928d 100644 --- a/configstore/utils/include/configstore/Utils.h +++ b/configstore/utils/include/configstore/Utils.h @@ -42,6 +42,15 @@ using ::android::hardware::configstore::V1_0::OptionalInt64; using ::android::hardware::configstore::V1_0::OptionalUInt64; using ::android::hardware::configstore::V1_0::OptionalString; +// a function to retrieve and cache the service handle +// for a particular interface +template +sp getService() { + // static initializer used for synchronizations + static sp configs = I::getService(); + return configs; +} + // arguments V: type for the value (i.e., OptionalXXX) // I: interface class name // func: member function pointer @@ -49,9 +58,10 @@ template (I::* func) (std::function)> decltype(V::value) get(const decltype(V::value) &defValue) { using namespace android::hardware::details; + // static initializer used for synchronizations auto getHelper = []()->V { V ret; - sp configs = I::getService(); + sp configs = getService(); if (!configs.get()) { // fallback to the default value