]> git.sesse.net Git - casparcg/commitdiff
Fixed potential race condition
authorhellgore <hellgore@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 1 Nov 2012 15:09:50 +0000 (15:09 +0000)
committerhellgore <hellgore@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 1 Nov 2012 15:09:50 +0000 (15:09 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/trunk@3471 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

common/concurrency/future_util.h

index fec9608a7c20a341945aebab6e6e34f66526be6e..fab0011db236d507f98c87c08632a22a538e9ef6 100644 (file)
@@ -81,6 +81,38 @@ public:
        {
                boost::mutex::scoped_lock lock(mutex_);
 
+               return try_completion_internal();
+       }
+
+       /**
+        * Call this when it is certain that the result should be ready, and if not
+        * it should be regarded as an unrecoverable error (retrying again would
+        * be useless), so the future will be marked as failed.
+        *
+        * @param exception The exception to mark the future with *if* the task
+        *                  completion fails.
+        */
+       void try_or_fail(const std::exception& exception)
+       {
+               boost::mutex::scoped_lock lock(mutex_);
+
+               if (!try_completion_internal())
+               {
+                       try
+                       {
+                               throw exception;
+                       }
+                       catch (...)
+                       {
+                               CASPAR_LOG_CURRENT_EXCEPTION();
+                               promise_.set_exception(boost::current_exception());
+                               done_ = true;
+                       }
+               }
+       }
+private:
+       bool try_completion_internal()
+       {
                if (!func_)
                        return false;
 
@@ -110,31 +142,6 @@ public:
 
                return done_;
        }
-
-       /**
-        * Call this when it is certain that the result should be ready, and if not
-        * it should be regarded as an unrecoverable error (retrying again would
-        * be useless), so the future will be marked as failed.
-        *
-        * @param exception The exception to mark the future with *if* the task
-        *                  completion fails.
-        */
-       void try_or_fail(const std::exception& exception)
-       {
-               if (!try_completion())
-               {
-                       try
-                       {
-                               throw exception;
-                       }
-                       catch (...)
-                       {
-                               CASPAR_LOG_CURRENT_EXCEPTION();
-                               promise_.set_exception(boost::current_exception());
-                               done_ = true;
-                       }
-               }
-       }
 private:
        boost::mutex mutex_;
        func_type func_;