This is similar to b1b3478d661761b97efceb30852e51e62ac4a229.

Signed-off-by: Derek Buitenhuis <[email protected]>
---
Hash will be changed to the correct one before push.
---
 libavfilter/pthread.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavfilter/pthread.c b/libavfilter/pthread.c
index 17e8e7b..4aa50d6 100644
--- a/libavfilter/pthread.c
+++ b/libavfilter/pthread.c
@@ -56,6 +56,7 @@ typedef struct ThreadContext {
     pthread_cond_t current_job_cond;
     pthread_mutex_t current_job_lock;
     int current_job;
+    unsigned int current_execute;
     int done;
 } ThreadContext;
 
@@ -64,6 +65,7 @@ static void* attribute_align_arg worker(void *v)
     ThreadContext *c = v;
     int our_job      = c->nb_jobs;
     int nb_threads   = c->nb_threads;
+    int last_execute = 0;
     int self_id;
 
     pthread_mutex_lock(&c->current_job_lock);
@@ -73,8 +75,9 @@ static void* attribute_align_arg worker(void *v)
             if (c->current_job == nb_threads + c->nb_jobs)
                 pthread_cond_signal(&c->last_job_cond);
 
-            if (!c->done)
+            while (last_execute == c->current_execute && !c->done)
                 pthread_cond_wait(&c->current_job_cond, &c->current_job_lock);
+            last_execute = c->current_execute;
             our_job = self_id;
 
             if (c->done) {
@@ -111,7 +114,8 @@ static void slice_thread_uninit(ThreadContext *c)
 
 static void slice_thread_park_workers(ThreadContext *c)
 {
-    pthread_cond_wait(&c->last_job_cond, &c->current_job_lock);
+    while (c->current_job != thread_count + c->job_count)
+        pthread_cond_wait(&c->last_job_cond, &c->current_job_lock);
     pthread_mutex_unlock(&c->current_job_lock);
 }
 
@@ -138,6 +142,8 @@ static int thread_execute(AVFilterContext *ctx, 
avfilter_action_func *func,
         c->rets    = &dummy_ret;
         c->nb_rets = 1;
     }
+    c->current_execute++;
+
     pthread_cond_broadcast(&c->current_job_cond);
 
     slice_thread_park_workers(c);
-- 
1.8.4.rc3

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to