[FFmpeg-devel] [PATCH] Always read frame progress values under progress_mutex.

Wan-Teh Chang wtc at google.com
Fri Feb 26 01:06:12 CET 2016


This fixes data race warnings by ThreadSanitizer.
ff_thread_report_progress and ff_thread_await_progress should read
progress[field] only when holding progress_mutex because progress_mutex
guards frame progress values.
---
 libavcodec/pthread_frame.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index b77dd1e..b7f603d 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -474,7 +474,7 @@ void ff_thread_report_progress(ThreadFrame *f, int n, int field)
     PerThreadContext *p;
     volatile int *progress = f->progress ? (int*)f->progress->data : NULL;
 
-    if (!progress || progress[field] >= n) return;
+    if (!progress) return;
 
     p = f->owner->internal->thread_ctx;
 
@@ -482,8 +482,10 @@ void ff_thread_report_progress(ThreadFrame *f, int n, int field)
         av_log(f->owner, AV_LOG_DEBUG, "%p finished %d field %d\n", progress, n, field);
 
     pthread_mutex_lock(&p->progress_mutex);
-    progress[field] = n;
-    pthread_cond_broadcast(&p->progress_cond);
+    if (progress[field] < n) {
+        progress[field] = n;
+        pthread_cond_broadcast(&p->progress_cond);
+    }
     pthread_mutex_unlock(&p->progress_mutex);
 }
 
@@ -492,7 +494,7 @@ void ff_thread_await_progress(ThreadFrame *f, int n, int field)
     PerThreadContext *p;
     volatile int *progress = f->progress ? (int*)f->progress->data : NULL;
 
-    if (!progress || progress[field] >= n) return;
+    if (!progress) return;
 
     p = f->owner->internal->thread_ctx;
 
-- 
2.7.0.rc3.207.g0ac5344



More information about the ffmpeg-devel mailing list