vulkan: refactor LayerRef::~LayerRef
Add and call LayerLibrary::Close from LayerRef::~LayerRef. There is no
functional change.
Change-Id: I514a1631204f104293a2b75f0a6d34d8625e68b1
diff --git a/vulkan/libvulkan/layers_extensions.cpp b/vulkan/libvulkan/layers_extensions.cpp
index 51a26a1..522d771 100644
--- a/vulkan/libvulkan/layers_extensions.cpp
+++ b/vulkan/libvulkan/layers_extensions.cpp
@@ -63,6 +63,7 @@
: path(path_), dlhandle(nullptr), refcount(0) {}
bool Open();
+ void Close();
std::string path;
void* dlhandle;
@@ -84,6 +85,15 @@
return true;
}
+void LayerLibrary::Close() {
+ if (--refcount == 0) {
+ ALOGV("Closing library %s", path.c_str());
+ dlclose(dlhandle);
+ dlhandle = nullptr;
+ }
+ ALOGV("Refcount on destruction is %zu", refcount);
+}
+
std::mutex g_library_mutex;
std::vector<LayerLibrary> g_layer_libraries;
std::vector<Layer> g_instance_layers;
@@ -391,12 +401,7 @@
if (layer_) {
LayerLibrary& library = g_layer_libraries[layer_->library_idx];
std::lock_guard<std::mutex> lock(g_library_mutex);
- if (--library.refcount == 0) {
- ALOGV("Closing library %s", library.path.c_str());
- dlclose(library.dlhandle);
- library.dlhandle = nullptr;
- }
- ALOGV("Refcount on destruction is %zu", library.refcount);
+ library.Close();
}
}