diff options
author | Michael Welter <michael@welter-4d.de> | 2022-09-11 20:56:18 +0200 |
---|---|---|
committer | Michael Welter <michael@welter-4d.de> | 2022-12-20 15:36:13 +0100 |
commit | f43e674bc0e47b7360c2a1ee335f7536e1638ae1 (patch) | |
tree | a9e418d2ffbdb0b791aa36c6f0ed1407771e99ab /video/camera.cpp | |
parent | 00299649bf84c9f81764d36d49c01c254953f362 (diff) |
Fix initialization order issues
Diffstat (limited to 'video/camera.cpp')
-rw-r--r-- | video/camera.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
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 <utility> #include <QMutex> -static std::vector<std::unique_ptr<video::impl::camera_>> metadata; -static QMutex mtx; +std::pair<std::vector<std::unique_ptr<video::impl::camera_>>&, QMutex&> get_metadata() +{ + static std::vector<std::unique_ptr<video::impl::camera_>> metadata; + static QMutex mtx; + return { metadata, mtx }; +} namespace video::impl { @@ -17,6 +21,7 @@ camera::~camera() = default; void register_camera(std::unique_ptr<impl::camera_> 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<camera_impl> make_camera_(const QString& name) { + auto [metadata, mtx] = get_metadata(); QMutexLocker l(&mtx); for (auto& camera : metadata) @@ -54,6 +61,7 @@ std::unique_ptr<camera_impl> 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<camera_impl> make_camera(const QString& name) std::vector<QString> camera_names() { + auto [metadata, mtx] = get_metadata(); + QMutexLocker l(&mtx); std::vector<QString> names; names.reserve(32); |