X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=core%2Fproducer%2Fframe_producer.cpp;h=de25a488e792be9a12a95192375557188a4634e4;hb=06bdd05d8ec7da072de717d5e1fcb462a1d8ee56;hp=e26432f97fe92637484a9037164a56d1af73c5cc;hpb=6ee3c95273bceac0ebb9831fd8f9176d614531e6;p=casparcg diff --git a/core/producer/frame_producer.cpp b/core/producer/frame_producer.cpp index e26432f97..de25a488e 100644 --- a/core/producer/frame_producer.cpp +++ b/core/producer/frame_producer.cpp @@ -209,6 +209,18 @@ const spl::shared_ptr& frame_producer::empty() return producer; } +std::shared_ptr& producer_destroyer() +{ + static auto destroyer = [] + { + auto result = std::make_shared(L"Producer destroyer"); + result->set_capacity(std::numeric_limits::max()); + return result; + }();; + + return destroyer; +} + tbb::atomic& destroy_producers_in_separate_thread() { static tbb::atomic state; @@ -219,6 +231,8 @@ tbb::atomic& destroy_producers_in_separate_thread() void destroy_producers_synchronously() { destroy_producers_in_separate_thread() = false; + // Join destroyer, executing rest of producers in queue synchronously. + producer_destroyer().reset(); } class destroy_producer_proxy : public frame_producer @@ -233,25 +247,24 @@ public: virtual ~destroy_producer_proxy() { - static tbb::atomic counter; - static std::once_flag counter_init_once; - std::call_once(counter_init_once, []{ counter = 0; }); - if(producer_ == core::frame_producer::empty() || !destroy_producers_in_separate_thread()) return; - ++counter; - CASPAR_VERIFY(counter < 8); + auto destroyer = producer_destroyer(); + + if (!destroyer) + return; + + CASPAR_VERIFY(destroyer->size() < 8); auto producer = new spl::shared_ptr(std::move(producer_)); - boost::thread([=] + + destroyer->begin_invoke([=] { std::unique_ptr> pointer_guard(producer); auto str = (*producer)->print(); try { - ensure_gpf_handler_installed_for_thread(u8(L"Destroyer: " + str).c_str()); - if (!producer->unique()) CASPAR_LOG(debug) << str << L" Not destroyed on asynchronous destruction thread: " << producer->use_count(); else @@ -268,9 +281,7 @@ public: { CASPAR_LOG_CURRENT_EXCEPTION(); } - - --counter; - }).detach(); + }); } draw_frame receive() override {return producer_->receive();}