ffmpeg | branch: release/3.3 | Ronald S. Bultje <rsbul...@gmail.com> | Fri Mar 
31 11:27:20 2017 -0400| [f5f0b2f44ce9df08f7a79b32d9209b23ba6b3447] | committer: 
Michael Niedermayer

ffmpeg: make transcode_init_done atomic.

Should fix tsan warnings in fate-fifo-muxer-h264/wav:

WARNING: ThreadSanitizer: data race (pid=26552)
  Write of size 4 at 0x000001e0d7c0 by main thread:
    #0 transcode_init src/ffmpeg.c:3761 (ffmpeg+0x00000050ca1c)
[..]
  Previous read of size 4 at 0x000001e0d7c0 by thread T1:
    #0 decode_interrupt_cb src/ffmpeg.c:460 (ffmpeg+0x0000004fde19)

(cherry picked from commit 76d8c77430e9e0110623705bfb54d922cc2ac3ea)
Signed-off-by: Michael Niedermayer <mich...@niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f5f0b2f44ce9df08f7a79b32d9209b23ba6b3447
---

 ffmpeg.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 11faf0d4a8..ea03179c21 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <limits.h>
+#include <stdatomic.h>
 #include <stdint.h>
 
 #if HAVE_IO_H
@@ -319,7 +320,7 @@ void term_exit(void)
 
 static volatile int received_sigterm = 0;
 static volatile int received_nb_signals = 0;
-static volatile int transcode_init_done = 0;
+static atomic_int transcode_init_done = ATOMIC_VAR_INIT(0);
 static volatile int ffmpeg_exited = 0;
 static int main_return_code = 0;
 
@@ -457,7 +458,7 @@ static int read_key(void)
 
 static int decode_interrupt_cb(void *ctx)
 {
-    return received_nb_signals > transcode_init_done;
+    return received_nb_signals > atomic_load(&transcode_init_done);
 }
 
 const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL };
@@ -612,7 +613,7 @@ static void ffmpeg_cleanup(int ret)
     if (received_sigterm) {
         av_log(NULL, AV_LOG_INFO, "Exiting normally, received signal %d.\n",
                (int) received_sigterm);
-    } else if (ret && transcode_init_done) {
+    } else if (ret && atomic_load(&transcode_init_done)) {
         av_log(NULL, AV_LOG_INFO, "Conversion failed!\n");
     }
     term_exit();
@@ -3758,7 +3759,7 @@ static int transcode_init(void)
         return ret;
     }
 
-    transcode_init_done = 1;
+    atomic_store(&transcode_init_done, 1);
 
     return 0;
 }

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

Reply via email to