]> git.sesse.net Git - nageru/commitdiff
Consistently use call_once to initialize static metrics.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 17 Jun 2017 12:00:45 +0000 (14:00 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 17 Jun 2017 12:00:45 +0000 (14:00 +0200)
decklink_output.cpp
quicksync_encoder.cpp
x264_encoder.cpp

index 17cc520d25964fca766d511fd653ef8c2e68b2d1..544e2edd333017d080b989a859004ba0f04bd6e4 100644 (file)
@@ -3,6 +3,8 @@
 #include <movit/resource_pool.h>  // Must be above the Xlib includes.
 #include <pthread.h>
 
+#include <mutex>
+
 #include <epoxy/egl.h>
 
 #include "chroma_subsampler.h"
@@ -20,7 +22,7 @@ using namespace std::chrono;
 namespace {
 
 // This class can be deleted during regular use, so make all the metrics static.
-bool metrics_inited = false;
+once_flag decklink_metrics_inited;
 LatencyHistogram latency_histogram;
 atomic<int64_t> metric_decklink_output_width_pixels{-1};
 atomic<int64_t> metric_decklink_output_height_pixels{-1};
@@ -49,7 +51,7 @@ DeckLinkOutput::DeckLinkOutput(ResourcePool *resource_pool, QSurface *surface, u
 {
        chroma_subsampler.reset(new ChromaSubsampler(resource_pool));
 
-       if (!metrics_inited) {
+       call_once(decklink_metrics_inited, [](){
                latency_histogram.init("decklink_output");
                global_metrics.add("decklink_output_width_pixels", &metric_decklink_output_width_pixels, Metrics::TYPE_GAUGE);
                global_metrics.add("decklink_output_height_pixels", &metric_decklink_output_height_pixels, Metrics::TYPE_GAUGE);
@@ -70,9 +72,7 @@ DeckLinkOutput::DeckLinkOutput(ResourcePool *resource_pool, QSurface *surface, u
                global_metrics.add("decklink_output_completed_frames", {{ "status", "unknown" }}, &metric_decklink_output_completed_frames_unknown);
 
                global_metrics.add("decklink_output_scheduled_samples", &metric_decklink_output_scheduled_samples);
-
-               metrics_inited = true;
-       }
+       });
 }
 
 void DeckLinkOutput::set_device(IDeckLink *decklink)
index 0c9cf0640446f39df3dcdfca27f0d16f584a50d2..1b36aa5246fbda3b19b5e65a5abc48365ab23840 100644 (file)
@@ -68,7 +68,7 @@ namespace {
 
 // These need to survive several QuickSyncEncoderImpl instances,
 // so they are outside.
-bool quick_sync_metrics_inited = false;
+once_flag quick_sync_metrics_inited;
 LatencyHistogram mixer_latency_histogram, qs_latency_histogram;
 MuxMetrics current_file_mux_metrics, total_mux_metrics;
 std::atomic<double> metric_current_file_start_time_seconds{0.0 / 0.0};
@@ -1573,15 +1573,14 @@ QuickSyncEncoderImpl::QuickSyncEncoderImpl(const std::string &filename, Resource
                memset(&slice_param, 0, sizeof(slice_param));
        }
 
-       if (!quick_sync_metrics_inited) {
+       call_once(quick_sync_metrics_inited, [](){
                mixer_latency_histogram.init("mixer");
                qs_latency_histogram.init("quick_sync");
                current_file_mux_metrics.init({{ "destination", "current_file" }});
                total_mux_metrics.init({{ "destination", "files_total" }});
                global_metrics.add("current_file_start_time_seconds", &metric_current_file_start_time_seconds, Metrics::TYPE_GAUGE);
                global_metrics.add("quick_sync_stalled_frames", &metric_quick_sync_stalled_frames);
-               quick_sync_metrics_inited = true;
-       }
+       });
 
        storage_thread = thread(&QuickSyncEncoderImpl::storage_task_thread, this);
 
index e32fcacf7bc12db1929613d191c4165208aed44e..90b61ed4769a172c2e0df61e5a616d7e1b167ad6 100644 (file)
@@ -66,7 +66,7 @@ X264Encoder::X264Encoder(AVOutputFormat *oformat)
        : wants_global_headers(oformat->flags & AVFMT_GLOBALHEADER),
          dyn(load_x264_for_bit_depth(global_flags.x264_bit_depth))
 {
-       call_once(x264_metrics_inited, [&](){
+       call_once(x264_metrics_inited, [](){
                global_metrics.add("x264_queued_frames", &metric_x264_queued_frames, Metrics::TYPE_GAUGE);
                global_metrics.add("x264_max_queued_frames", &metric_x264_max_queued_frames, Metrics::TYPE_GAUGE);
                global_metrics.add("x264_dropped_frames", &metric_x264_dropped_frames);