From f43e674bc0e47b7360c2a1ee335f7536e1638ae1 Mon Sep 17 00:00:00 2001 From: Michael Welter Date: Sun, 11 Sep 2022 20:56:18 +0200 Subject: Fix initialization order issues --- video/camera.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'video/camera.cpp') diff --git a/video/camera.cpp b/video/camera.cpp index 42320402..a66d8a59 100644 --- a/video/camera.cpp +++ b/video/camera.cpp @@ -4,8 +4,12 @@ #include #include -static std::vector> metadata; -static QMutex mtx; +std::pair>&, QMutex&> get_metadata() +{ + static std::vector> metadata; + static QMutex mtx; + return { metadata, mtx }; +} namespace video::impl { @@ -17,6 +21,7 @@ camera::~camera() = default; void register_camera(std::unique_ptr camera) { + auto [metadata, mtx] = get_metadata(); QMutexLocker l(&mtx); metadata.push_back(std::move(camera)); } @@ -27,6 +32,7 @@ namespace video { bool show_dialog(const QString& camera_name) { + auto [metadata, mtx] = get_metadata(); QMutexLocker l(&mtx); for (auto& camera : metadata) @@ -39,6 +45,7 @@ bool show_dialog(const QString& camera_name) std::unique_ptr make_camera_(const QString& name) { + auto [metadata, mtx] = get_metadata(); QMutexLocker l(&mtx); for (auto& camera : metadata) @@ -54,6 +61,7 @@ std::unique_ptr make_camera(const QString& name) if (auto ret = make_camera_(name)) return ret; + auto [metadata, mtx] = get_metadata(); for (auto& camera : metadata) for (const QString& name_ : camera->camera_names()) if (auto ret = camera->make_camera(name_)) @@ -64,6 +72,8 @@ std::unique_ptr make_camera(const QString& name) std::vector camera_names() { + auto [metadata, mtx] = get_metadata(); + QMutexLocker l(&mtx); std::vector names; names.reserve(32); -- cgit v1.2.3