]> git.sesse.net Git - casparcg/commitdiff
Created consumer_index counter in channel_consumer instead of using uninitialized...
authorHelge Norberg <helge.norberg@gmail.com>
Mon, 31 Mar 2014 15:23:51 +0000 (17:23 +0200)
committerHelge Norberg <helge.norberg@gmail.com>
Mon, 31 Mar 2014 15:23:51 +0000 (17:23 +0200)
core/producer/channel/channel_producer.cpp

index 6b4d1f6f24a39567f93aa7b579c8ce5b3a33263c..9ab3e0a8840e594b1b7dffb38676d58bfc8b1dc3 100644 (file)
@@ -33,6 +33,8 @@
 #include "../../mixer/write_frame.h"\r
 #include "../../mixer/read_frame.h"\r
 \r
+#include <boost/thread/once.hpp>\r
+\r
 #include <common/exception/exceptions.h>\r
 #include <common/memory/memcpy.h>\r
 #include <common/concurrency/future_util.h>\r
@@ -46,6 +48,7 @@ class channel_consumer : public frame_consumer
        tbb::concurrent_bounded_queue<std::shared_ptr<read_frame>>      frame_buffer_;\r
        core::video_format_desc                                                                         format_desc_;\r
        int                                                                                                                     channel_index_;\r
+       int                                                                                                                     consumer_index_;\r
        tbb::atomic<bool>                                                                                       is_running_;\r
        tbb::atomic<int64_t>                                                                            current_age_;\r
 \r
@@ -54,9 +57,23 @@ public:
        {\r
                is_running_ = true;\r
                current_age_ = 0;\r
+               consumer_index_ = next_consumer_index();\r
                frame_buffer_.set_capacity(3);\r
        }\r
 \r
+       static int next_consumer_index()\r
+       {\r
+               static tbb::atomic<int> consumer_index_counter;\r
+               static boost::once_flag consumer_index_counter_initialized;\r
+\r
+               boost::call_once(consumer_index_counter_initialized, [&]()\r
+               {\r
+                       consumer_index_counter = 0;\r
+               });\r
+\r
+               return ++consumer_index_counter;\r
+       }\r
+\r
        ~channel_consumer()\r
        {\r
                stop();\r
@@ -106,7 +123,7 @@ public:
 \r
        virtual int index() const override\r
        {\r
-               return 78500 + channel_index_;\r
+               return 78500 + consumer_index_;\r
        }\r
 \r
        // channel_consumer\r