- \r
-class destroy_producer_proxy : public frame_producer\r
-{ \r
- std::shared_ptr<frame_producer>* producer_;\r
-public:\r
- destroy_producer_proxy(safe_ptr<frame_producer>&& producer) \r
- : producer_(new std::shared_ptr<frame_producer>(std::move(producer)))\r
- {\r
- }\r
-\r
- ~destroy_producer_proxy()\r
- { \r
- static auto destroyers = std::make_shared<tbb::concurrent_bounded_queue<std::shared_ptr<executor>>>();\r
- static tbb::atomic<int> destroyer_count;\r
-\r
- try\r
- {\r
- std::shared_ptr<executor> destroyer;\r
- if(!destroyers->try_pop(destroyer))\r
- {\r
- destroyer.reset(new executor(L"destroyer"));\r
- destroyer->set_priority_class(below_normal_priority_class);\r
- if(++destroyer_count > 16)\r
- CASPAR_LOG(warning) << L"Potential destroyer dead-lock detected.";\r
- CASPAR_LOG(trace) << "Created destroyer: " << destroyer_count;\r
- }\r
- \r
- auto producer = producer_;\r
- auto pool = destroyers;\r
- destroyer->begin_invoke([=]\r
- {\r
- try\r
- {\r
- if(!producer->unique())\r
- CASPAR_LOG(trace) << (*producer)->print() << L" Not destroyed on safe asynchronous destruction thread: " << producer->use_count();\r
- else\r
- CASPAR_LOG(trace) << (*producer)->print() << L" Destroying on safe asynchronous destruction thread.";\r
- }\r
- catch(...){}\r
-\r
- delete producer;\r
- pool->push(destroyer);\r
- }); \r
- }\r
- catch(...)\r
- {\r
- CASPAR_LOG_CURRENT_EXCEPTION();\r
- try\r
- {\r
- delete producer_;\r
- }\r
- catch(...){}\r
- }\r
- }\r
-\r
- virtual safe_ptr<basic_frame> receive(int hints) override {return (*producer_)->receive(hints);}\r
- virtual safe_ptr<basic_frame> last_frame() const override {return (*producer_)->last_frame();}\r
- virtual std::wstring print() const override {return (*producer_)->print();}\r
- virtual boost::property_tree::wptree info() const override {return (*producer_)->info();}\r
- virtual boost::unique_future<std::wstring> call(const std::wstring& str) override {return (*producer_)->call(str);}\r
- virtual safe_ptr<frame_producer> get_following_producer() const override {return (*producer_)->get_following_producer();}\r
- virtual void set_leading_producer(const safe_ptr<frame_producer>& producer) override {(*producer_)->set_leading_producer(producer);}\r
- virtual int64_t nb_frames() const override {return (*producer_)->nb_frames();}\r
-};\r