]> git.sesse.net Git - casparcg/commitdiff
2.0.0.2: Reverted executor lazy autostart. Caused a deadlock during shutdown.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Fri, 29 Apr 2011 08:06:03 +0000 (08:06 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Fri, 29 Apr 2011 08:06:03 +0000 (08:06 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@670 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

12 files changed:
common/concurrency/executor.h
common/diagnostics/graph.cpp
core/consumer/frame_consumer_device.cpp
core/mixer/frame_mixer_device.cpp
core/mixer/gpu/ogl_device.cpp
core/mixer/image/image_mixer.cpp
core/producer/frame_producer_device.cpp
modules/decklink/consumer/decklink_consumer.cpp
modules/decklink/producer/decklink_producer.cpp
modules/ffmpeg/consumer/ffmpeg_consumer.cpp
modules/ffmpeg/producer/ffmpeg_producer.cpp
modules/ffmpeg/producer/input.cpp

index 45e4b1b9325f8cd35c677b0578b0e98ef1cee4a1..8b3d087a74dfa21042925f2679122daf0edc9b37 100644 (file)
@@ -69,9 +69,11 @@ class executor : boost::noncopyable
        tbb::concurrent_bounded_queue<std::function<void()>> execution_queue_;\r
 public:\r
                \r
-       explicit executor(const std::wstring& name) : name_(narrow(name)) // noexcept\r
+       explicit executor(const std::wstring& name, bool auto_start = false) : name_(narrow(name)) // noexcept\r
        {\r
                is_running_ = false;\r
+               if(auto_start)\r
+                       start();\r
        }\r
        \r
        virtual ~executor() // noexcept\r
@@ -86,6 +88,14 @@ public:
        {\r
                execution_queue_.set_capacity(capacity);\r
        }\r
+\r
+       void start() // noexcept\r
+       {\r
+               if(is_running_.fetch_and_store(true))\r
+                       return;\r
+               clear();\r
+               thread_ = boost::thread([this]{run();});\r
+       }\r
                        \r
        void stop() // noexcept\r
        {\r
@@ -111,9 +121,6 @@ public:
        template<typename Func>\r
        auto begin_invoke(Func&& func) -> boost::unique_future<decltype(func())> // noexcept\r
        {       \r
-               if(!is_running_)\r
-                       start();\r
-\r
                typedef boost::packaged_task<decltype(func())> task_type;\r
                                \r
                auto task = task_type(std::forward<Func>(func));\r
@@ -151,6 +158,9 @@ public:
        template<typename Func>\r
        auto invoke(Func&& func) -> decltype(func())\r
        {\r
+               if(!is_running_)\r
+                       start();\r
+\r
                if(boost::this_thread::get_id() == thread_.get_id())  // Avoids potential deadlock.\r
                        return func();\r
                \r
@@ -163,14 +173,6 @@ public:
        bool is_running() const { return is_running_;                           }       \r
                \r
 private:\r
-\r
-       void start() // noexcept\r
-       {\r
-               if(is_running_.fetch_and_store(true))\r
-                       return;\r
-               clear();\r
-               thread_ = boost::thread([this]{run();});\r
-       }\r
        \r
        void execute() // noexcept\r
        {\r
index 0cd1941f65988680346d0ca1cf0febe2f1f96ab8..18fc10a13b0c0f177b95e38258288213db60eed9 100644 (file)
@@ -75,6 +75,7 @@ public:
 private:\r
        context() : executor_(L"diagnostics")\r
        {\r
+               executor_.start();\r
                executor_.begin_invoke([this]\r
                {\r
                        window_.Create(sf::VideoMode(600, 1000), "CasparCG Diagnostics");\r
index dd2b99587f1fa2160afa8f50c1af3503f4b4d28e..c69ba3fa4b3e11bda1b6e4ad1830cacb272a9e5e 100644 (file)
@@ -52,6 +52,7 @@ public:
                , executor_(L"frame_consumer_device")\r
        {               \r
                executor_.set_capacity(2);\r
+               executor_.start();\r
        }\r
 \r
        void add(int index, safe_ptr<frame_consumer>&& consumer)\r
index 0f731f3bb776376c05639c78575b98b8c96563c4..af789e3d616af0d9616b5c7725723c48e74df0f5 100644 (file)
@@ -114,6 +114,7 @@ public:
                diag_->set_color("tick-time", diagnostics::color(0.1f, 0.7f, 0.8f));\r
                diag_->set_color("input-buffer", diagnostics::color(1.0f, 1.0f, 0.0f)); \r
                executor_.set_capacity(2);      \r
+               executor_.start();\r
                CASPAR_LOG(info) << print() << L" Successfully initialized.";   \r
        }\r
 \r
@@ -130,7 +131,6 @@ public:
                auto image = image_mixer_.begin_pass();\r
                BOOST_FOREACH(auto& frame, frames)\r
                {\r
-                       // Apply root transform and render.\r
                        if(format_desc_.mode != core::video_mode::progressive)\r
                        {\r
                                auto frame1 = make_safe<core::basic_frame>(frame.second);\r
index fcf8f14828dc50b72dfeed3df081cbba4b3ca798..692bb3a53424c64c90050b57a7bbf8f6414cfeec 100644 (file)
@@ -32,6 +32,7 @@ namespace caspar { namespace mixer {
 \r
 ogl_device::ogl_device() : executor_(L"ogl_device")\r
 {\r
+       executor_.start();\r
        invoke([=]\r
        {\r
                context_.reset(new sf::Context());\r
index aa714f26ed8deca91f7a6d89218a1ef7b1ea8ede..aa9741db76445bd0763ebc63d0db97c4a00329f4 100644 (file)
@@ -157,10 +157,10 @@ public:
        {\r
                return context_->begin_invoke([=]() -> safe_ptr<const host_buffer>\r
                {\r
-                       reading_->map(); // Open host buffer for reading.\r
-                       render_targets_[0]->attach(0); // Render to the next target\r
-                       GL(glClear(GL_COLOR_BUFFER_BIT)); // Clear the new target\r
-                       return make_safe(reading_);\r
+                       reading_->map();\r
+                       render_targets_[0]->attach(0);\r
+                       GL(glClear(GL_COLOR_BUFFER_BIT));\r
+                       return safe_ptr<const host_buffer>(reading_);\r
                });\r
        }\r
 \r
@@ -168,9 +168,9 @@ public:
        {\r
                context_->begin_invoke([=]\r
                {\r
-                       reading_ = context_->create_host_buffer(format_desc_.size, host_buffer::read_only); // Create a new host buffer.\r
-                       render_targets_[0]->write(*reading_); // Move data to host buffer.\r
-                       std::rotate(render_targets_.begin(), render_targets_.begin() + 1, render_targets_.end()); // Set new render target.\r
+                       reading_ = context_->create_host_buffer(format_desc_.size, host_buffer::read_only);\r
+                       render_targets_[0]->write(*reading_);\r
+                       std::rotate(render_targets_.begin(), render_targets_.begin() + 1, render_targets_.end());\r
                });\r
        }\r
                \r
index 9372c40e64335dac9d4e15d80a8e5fa15df87d8f..23db41cd9a97ca080432943104ada0ec27e6ee4f 100644 (file)
@@ -54,7 +54,10 @@ struct frame_producer_device::implementation : boost::noncopyable
 public:\r
        implementation(const video_format_desc& format_desc)  \r
                : format_desc_(format_desc)\r
-               , executor_(L"frame_producer_device"){}\r
+               , executor_(L"frame_producer_device")\r
+       {\r
+               executor_.start();\r
+       }\r
 \r
        boost::signals2::connection connect(const output_t::slot_type& subscriber)\r
        {\r
index 13be196ac2a277f1a8a19a0fd7188612f9f9f2f6..5a56633736832e2834bd69ca58b2948dc9522e25 100644 (file)
@@ -288,7 +288,7 @@ public:
 \r
 struct decklink_consumer::implementation\r
 {\r
-       std::unique_ptr<decklink_output> output_;\r
+       std::unique_ptr<decklink_output> input_;\r
        size_t device_index_;\r
        bool embed_audio_;\r
        bool internal_key_;\r
@@ -300,13 +300,16 @@ public:
                : device_index_(device_index)\r
                , embed_audio_(embed_audio)\r
                , internal_key_(internal_key)\r
-               , executor_(L"DECKLINK[" + boost::lexical_cast<std::wstring>(device_index) + L"]"){}\r
+               , executor_(L"DECKLINK[" + boost::lexical_cast<std::wstring>(device_index) + L"]")\r
+       {\r
+               executor_.start();\r
+       }\r
 \r
        ~implementation()\r
        {\r
                executor_.invoke([&]\r
                {\r
-                       output_ = nullptr;\r
+                       input_ = nullptr;\r
                });\r
        }\r
 \r
@@ -314,13 +317,13 @@ public:
        {\r
                executor_.invoke([&]\r
                {\r
-                       output_.reset(new decklink_output(format_desc, device_index_, embed_audio_, internal_key_));\r
+                       input_.reset(new decklink_output(format_desc, device_index_, embed_audio_, internal_key_));\r
                });\r
        }\r
        \r
        void send(const safe_ptr<const core::read_frame>& frame)\r
        {\r
-               output_->send(frame);\r
+               input_->send(frame);\r
        }\r
 \r
        size_t buffer_depth() const\r
@@ -330,7 +333,7 @@ public:
 \r
        std::wstring print() const\r
        {\r
-               return output_->print();\r
+               return input_->print();\r
        }\r
 };\r
 \r
index fcc0f5680ef61340b286482141cfc0bdc7f6d1eb..79f486a4c61f8ee91294977f23d9696d9c2beb76 100644 (file)
@@ -256,7 +256,7 @@ public:
        explicit decklink_producer(const safe_ptr<core::frame_factory>& frame_factory, const core::video_format_desc& format_desc, size_t device_index)\r
                : format_desc_(format_desc) \r
                , device_index_(device_index)\r
-               , executor_(L"decklink_producer")\r
+               , executor_(L"decklink_producer", true)\r
        {\r
                executor_.invoke([=]\r
                {\r
index bc5f7632773426da7c654ee944b42b95b0d616f1..bdbda90edce275e113cb7af8750cc03af8b1b97f 100644 (file)
@@ -116,6 +116,7 @@ public:
        void initialize(const core::video_format_desc& format_desc)\r
        {\r
                format_desc_ = format_desc;\r
+               executor_.start();\r
                active_ = executor_.begin_invoke([]{});\r
 \r
                fmt_ = av_guess_format(nullptr, filename_.c_str(), nullptr);\r
index 3e61711228706364cbf99c49997daab912d2133e..019c53e91d5fc667a01811a567e9cc50df72a49d 100644 (file)
 #include <common/utility/timer.h>\r
 #include <common/utility/assert.h>\r
 \r
-#include <boost/timer.hpp>\r
-\r
 #include <tbb/parallel_invoke.h>\r
 \r
+#include <boost/timer.hpp>\r
+\r
 #include <deque>\r
 #include <functional>\r
 \r
index 07c46a02ed1486c39a39d3a0a0b51559d7cf5088..08283991b5f9ea03de4e000cb8bdfae4f8452b40 100644 (file)
@@ -124,6 +124,7 @@ public:
                                source_info(narrow(print())) << \r
                                msg_info("No video or audio codec context found."));            \r
                        \r
+               executor_.start();\r
                executor_.begin_invoke([this]{read_file();});\r
                CASPAR_LOG(info) << print() << " Started.";\r
        }\r