This is similar to 5152196b2b47d446d9a509b9bfb318daa26a1f2b.
Showing the changes to libavfilter/pthread.c (1 of 1 file). Show all
Unified · Split
| @@ -56,6 +56,7 @@ typedef struct ThreadContext { · 55 unmodified lines | ||
| 56 | 56 | pthread_cond_t current_job_cond; |
| 57 | 57 | pthread_mutex_t current_job_lock; |
| 58 | 58 | int current_job; |
| 59 | + unsigned int current_execute; | |
| 59 | 60 | int done; |
| 60 | 61 | } ThreadContext; |
| 61 | 62 | |
| @@ -64,6 +65,7 @@ static void* attribute_align_arg worker(void *v) · 2 unmodified lines | ||
| 64 | 65 | ThreadContext *c = v; |
| 65 | 66 | int our_job = c->nb_jobs; |
| 66 | 67 | int nb_threads = c->nb_threads; |
| 68 | + unsigned int last_execute = 0; | |
| 67 | 69 | int self_id; |
| 68 | 70 | |
| 69 | 71 | pthread_mutex_lock(&c->current_job_lock); |
| @@ -73,8 +75,9 @@ static void* attribute_align_arg worker(void *v) · 3 unmodified lines | ||
| 73 | 75 | if (c->current_job == nb_threads + c->nb_jobs) |
| 74 | 76 | pthread_cond_signal(&c->last_job_cond); |
| 75 | 77 | |
| 76 | − if (!c->done) | |
| 78 | + while (last_execute == c->current_execute && !c->done) | |
| 77 | 79 | pthread_cond_wait(&c->current_job_cond, &c->current_job_lock); |
| 80 | + last_execute = c->current_execute; | |
| 78 | 81 | our_job = self_id; |
| 79 | 82 | |
| 80 | 83 | if (c->done) { |
| @@ -111,7 +114,8 @@ static void slice_thread_uninit(ThreadContext *c) · 30 unmodified lines | ||
| 111 | 114 | |
| 112 | 115 | static void slice_thread_park_workers(ThreadContext *c) |
| 113 | 116 | { |
| 114 | − pthread_cond_wait(&c->last_job_cond, &c->current_job_lock); | |
| 117 | + while (c->current_job != c->nb_threads + c->nb_jobs) | |
| 118 | + pthread_cond_wait(&c->last_job_cond, &c->current_job_lock); | |
| 115 | 119 | pthread_mutex_unlock(&c->current_job_lock); |
| 116 | 120 | } |
| 117 | 121 | |
| @@ -138,6 +142,8 @@ static int thread_execute(AVFilterContext *ctx, avfilter_action_func *func, · 20 unmodified lines | ||
| 138 | 142 | c->rets = &dummy_ret; |
| 139 | 143 | c->nb_rets = 1; |
| 140 | 144 | } |
| 145 | + c->current_execute++; | |
| 146 | + | |
| 141 | 147 | pthread_cond_broadcast(&c->current_job_cond); |
| 142 | 148 | |
| 143 | 149 | slice_thread_park_workers(c); |