[FFmpeg-cvslog] pthread_frame: make accesses to debug field be protected by owner lock.
Ronald S. Bultje
git at videolan.org
Thu Apr 13 03:32:11 EEST 2017
ffmpeg | branch: release/3.3 | Ronald S. Bultje <rsbultje at gmail.com> | Thu Apr 6 13:58:59 2017 -0400| [1968a1eef1cae22e162259d7082c2eea98d81e32] | committer: Michael Niedermayer
pthread_frame: make accesses to debug field be protected by owner lock.
The av_log() is done outside the lock, but this way the accesses to the
field (reads and writes) are always protected by a mutex. The av_log()
is not run inside the lock context because it may involve user callbacks
and doing that in performance-sensitive code is probably not a good idea.
This should fix occasional tsan warnings when running fate-h264, like:
WARNING: ThreadSanitizer: data race (pid=10916)
Write of size 4 at 0x7d64000174fc by main thread (mutexes: write M2313):
#0 update_context_from_user src/libavcodec/pthread_frame.c:335 (ffmpeg+0x000000df7b06)
[..]
Previous read of size 4 at 0x7d64000174fc by thread T1 (mutexes: write M2311):
#0 ff_thread_await_progress src/libavcodec/pthread_frame.c:592 (ffmpeg+0x000000df8b3e)
(cherry picked from commit 2e664b9c1e73c80aab91070c1eb7676f04bdd12d)
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1968a1eef1cae22e162259d7082c2eea98d81e32
---
libavcodec/pthread_frame.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index c246c2fded..0ba87b5929 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -566,12 +566,11 @@ void ff_thread_report_progress(ThreadFrame *f, int n, int field)
p = f->owner[field]->internal->thread_ctx;
+ pthread_mutex_lock(&p->progress_mutex);
if (f->owner[field]->debug&FF_DEBUG_THREADS)
av_log(f->owner[field], AV_LOG_DEBUG,
"%p finished %d field %d\n", progress, n, field);
- pthread_mutex_lock(&p->progress_mutex);
-
atomic_store_explicit(&progress[field], n, memory_order_release);
pthread_cond_broadcast(&p->progress_cond);
@@ -589,11 +588,10 @@ void ff_thread_await_progress(ThreadFrame *f, int n, int field)
p = f->owner[field]->internal->thread_ctx;
+ pthread_mutex_lock(&p->progress_mutex);
if (f->owner[field]->debug&FF_DEBUG_THREADS)
av_log(f->owner[field], AV_LOG_DEBUG,
"thread awaiting %d field %d from %p\n", n, field, progress);
-
- pthread_mutex_lock(&p->progress_mutex);
while (atomic_load_explicit(&progress[field], memory_order_relaxed) < n)
pthread_cond_wait(&p->progress_cond, &p->progress_mutex);
pthread_mutex_unlock(&p->progress_mutex);
More information about the ffmpeg-cvslog
mailing list