Double gBn/sConstructorMap
The new getBn/sConstructorMap() functions ensure that the
map is initialized before usage. For ABI compatibility (to prebuilt
HAL definition libs), the old global map is kept and checked as well.
Test: boots
Bug: 69122224
Change-Id: I32b1a612f8e841d1e7dca5335230a3dc7d589da5
diff --git a/transport/Static.cpp b/transport/Static.cpp
index 784b835..cbe6add 100644
--- a/transport/Static.cpp
+++ b/transport/Static.cpp
@@ -29,16 +29,28 @@
Mutex gDefaultServiceManagerLock;
sp<android::hidl::manager::V1_0::IServiceManager> gDefaultServiceManager;
-ConcurrentMap<std::string, std::function<sp<IBinder>(void *)>>
- gBnConstructorMap{};
+// Deprecated; kept for ABI compatibility. Use getBnConstructorMap.
+BnConstructorMap gBnConstructorMap{};
ConcurrentMap<const ::android::hidl::base::V1_0::IBase*, wp<::android::hardware::BHwBinder>>
gBnMap{};
ConcurrentMap<wp<::android::hidl::base::V1_0::IBase>, SchedPrio> gServicePrioMap{};
-ConcurrentMap<std::string, std::function<sp<::android::hidl::base::V1_0::IBase>(void *)>>
- gBsConstructorMap;
+// Deprecated; kept for ABI compatibility. Use getBsConstructorMap.
+BsConstructorMap gBsConstructorMap{};
+
+// For static executables, it is not guaranteed that gBnConstructorMap are initialized before
+// used in HAL definition libraries.
+BnConstructorMap& getBnConstructorMap() {
+ static BnConstructorMap map{};
+ return map;
+}
+
+BsConstructorMap& getBsConstructorMap() {
+ static BsConstructorMap map{};
+ return map;
+}
} // namespace details
} // namespace hardware