Merge "Add getInstance call to LazyServiceRegistrar"
diff --git a/transport/HidlLazyUtils.cpp b/transport/HidlLazyUtils.cpp
index 8e3fdf3..08ed676 100644
--- a/transport/HidlLazyUtils.cpp
+++ b/transport/HidlLazyUtils.cpp
@@ -181,6 +181,11 @@
mImpl = std::make_shared<details::LazyServiceRegistrarImpl>();
}
+LazyServiceRegistrar& LazyServiceRegistrar::getInstance() {
+ static auto registrarInstance = new LazyServiceRegistrar();
+ return *registrarInstance;
+}
+
status_t LazyServiceRegistrar::registerService(
const sp<::android::hidl::base::V1_0::IBase>& service, const std::string& name) {
return mImpl->registerService(service, name);
diff --git a/transport/include/hidl/HidlLazyUtils.h b/transport/include/hidl/HidlLazyUtils.h
index 2205daa..257de98 100644
--- a/transport/include/hidl/HidlLazyUtils.h
+++ b/transport/include/hidl/HidlLazyUtils.h
@@ -29,12 +29,13 @@
/** Exits when all HALs registered through this object have 0 clients */
class LazyServiceRegistrar {
public:
- LazyServiceRegistrar();
- status_t registerService(const sp<::android::hidl::base::V1_0::IBase>& service,
- const std::string& name = "default");
+ LazyServiceRegistrar();
+ static LazyServiceRegistrar& getInstance();
+ status_t registerService(const sp<::android::hidl::base::V1_0::IBase>& service,
+ const std::string& name = "default");
private:
- std::shared_ptr<details::LazyServiceRegistrarImpl> mImpl;
+ std::shared_ptr<details::LazyServiceRegistrarImpl> mImpl;
};
} // namespace hardware
diff --git a/transport/include/hidl/LegacySupport.h b/transport/include/hidl/LegacySupport.h
index 0a9feee..fdc5a48 100644
--- a/transport/include/hidl/LegacySupport.h
+++ b/transport/include/hidl/LegacySupport.h
@@ -91,15 +91,6 @@
return defaultPassthroughServiceImplementation<Interface>("default", maxThreads);
}
-// Make LazyServiceRegistrar static so that multiple calls to
-// registerLazyPassthroughServiceImplementation work as expected: each HAL is registered and the
-// process only exits once all HALs have 0 clients.
-static inline std::shared_ptr<LazyServiceRegistrar> getOrCreateLazyServiceRegistrar() {
- using android::hardware::LazyServiceRegistrar;
- static auto serviceCounter(std::make_shared<LazyServiceRegistrar>());
- return serviceCounter;
-}
-
/**
* Registers a passthrough service implementation that exits when there are 0 clients.
*
@@ -112,10 +103,11 @@
__attribute__((warn_unused_result)) status_t registerLazyPassthroughServiceImplementation(
const std::string& name = "default") {
return details::registerPassthroughServiceImplementation<Interface>(
- [](const sp<Interface>& service, const std::string& name) {
- return getOrCreateLazyServiceRegistrar()->registerService(service, name);
- },
- name);
+ [](const sp<Interface>& service, const std::string& name) {
+ using android::hardware::LazyServiceRegistrar;
+ return LazyServiceRegistrar::getInstance().registerService(service, name);
+ },
+ name);
}
/**