]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/pthread.c
Mark some arrays that never change as const.
[ffmpeg] / libavfilter / pthread.c
index a4f45c82cd50b6921e425d76b456676b45e53f15..2ebcc9753a516fab46ee4a8195cd264b61fcd786 100644 (file)
@@ -1,5 +1,4 @@
 /*
- *
  * This file is part of Libav.
  *
  * Libav is free software; you can redistribute it and/or
@@ -45,7 +44,7 @@ typedef struct ThreadContext {
     pthread_t *workers;
     avfilter_action_func *func;
 
-    /* per-execute perameters */
+    /* per-execute parameters */
     AVFilterContext *ctx;
     void *arg;
     int   *rets;
@@ -56,6 +55,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 +64,7 @@ static void* attribute_align_arg worker(void *v)
     ThreadContext *c = v;
     int our_job      = c->nb_jobs;
     int nb_threads   = c->nb_threads;
+    unsigned int last_execute = 0;
     int self_id;
 
     pthread_mutex_lock(&c->current_job_lock);
@@ -73,7 +74,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);
 
-            pthread_cond_wait(&c->current_job_cond, &c->current_job_lock);
+            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) {
@@ -110,7 +113,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 != c->nb_threads + c->nb_jobs)
+        pthread_cond_wait(&c->last_job_cond, &c->current_job_lock);
     pthread_mutex_unlock(&c->current_job_lock);
 }
 
@@ -137,6 +141,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);