Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d91c74f9 authored by Chia-I Wu's avatar Chia-I Wu
Browse files

vulkan: refactor LayerRef::~LayerRef

Add and call LayerLibrary::Close from LayerRef::~LayerRef.  There is no
functional change.

Change-Id: I514a1631204f104293a2b75f0a6d34d8625e68b1
parent fd0389fb
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ struct LayerLibrary {
        : path(path_), dlhandle(nullptr), refcount(0) {}

    bool Open();
    void Close();

    std::string path;
    void* dlhandle;
@@ -84,6 +85,15 @@ bool LayerLibrary::Open() {
    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 @@ LayerRef::~LayerRef() {
    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();
    }
}