]> git.sesse.net Git - casparcg/blobdiff - common/executor.h
[image_scroll_producer] Completed documentation with DURATION and END_TIME.
[casparcg] / common / executor.h
index 1e69ff1c07658d9a31819bf67a9d5afb52f6a0f2..805c1bc9dbe6d080fbd7a418d0cd29dd34fb65a6 100644 (file)
@@ -60,7 +60,8 @@ class executor final
        tbb::atomic<bool>                                                                                       is_running_;
        boost::thread                                                                                           thread_;        
        function_queue_t                                                                                        execution_queue_;
-               
+       tbb::atomic<bool>                                                                                       currently_in_task_;
+
 public:                
        executor(const std::wstring& name)
                : name_(name)
@@ -74,12 +75,13 @@ public:
                })
        {
                is_running_ = true;
+               currently_in_task_ = false;
                thread_ = boost::thread([this]{run();});
        }
        
        ~executor()
        {
-               CASPAR_LOG(trace) << L"Shutting down " << name_;
+               CASPAR_LOG(debug) << L"Shutting down " << name_;
 
                try
                {
@@ -169,7 +171,7 @@ public:
        {
                return execution_queue_.size(); 
        }
-               
+
        bool is_running() const
        {
                return is_running_; 
@@ -180,6 +182,11 @@ public:
                return boost::this_thread::get_id() == thread_.get_id();
        }
 
+       bool is_currently_in_task() const
+       {
+               return currently_in_task_;
+       }
+
        std::wstring name() const
        {
                return name_;
@@ -232,7 +239,7 @@ private:
 
                if (!execution_queue_.try_push(priority, function))
                {
-                       CASPAR_LOG(debug) << print() << L" Overflow. Blocking caller.";
+                       CASPAR_LOG(warning) << print() << L" Overflow. Blocking caller.";
                        execution_queue_.push(priority, function);
                }
 
@@ -243,7 +250,17 @@ private:
                                function();
                        }
 
-                       return future.get();
+                       try
+                       {
+                               return future.get();
+                       }
+                       catch (const caspar_exception& e)
+                       {
+                               if (!is_current()) // Add context information from this thread before rethrowing.
+                                       e << context_info(get_context() + *boost::get_error_info<context_info_t>(e));
+
+                               throw;
+                       }
                });
        }
 
@@ -256,12 +273,15 @@ private:
                        {
                                std::function<void ()> func;
                                execution_queue_.pop(func);
+                               currently_in_task_ = true;
                                func();
                        }
                        catch(...)
                        {
                                CASPAR_LOG_CURRENT_EXCEPTION();
                        }
+
+                       currently_in_task_ = false;
                }
        }       
 };