Add the debug_threads boolean field to FrameThreadContext. The debug_threads field records whether the FF_DEBUG_THREADS bit is set in the debug field of the avctx passed to ff_frame_thread_init(). The debug_threads field is set when avcodec_open2() is called, never changes thereafter, and applies to all the decoding threads owned by a FrameThreadContext. The current code allows different decoding threads to have different FF_DEBUG_THREADS options, but that does not seem useful.
This fixes the tsan warning that 2e664b9c1e73c80aab91070c1eb7676f04bdd12d attempted to fix: WARNING: ThreadSanitizer: data race (pid=452658) Write of size 4 at 0x7b640003f4fc by main thread (mutexes: write M248499): #0 update_context_from_user [..]/libavcodec/pthread_frame.c:335:19 (5ab42bb1a6f4b068d7863dabe9b2bacc+0xe73859) [..] Previous read of size 4 at 0x7b640003f4fc by thread T130 (mutexes: write M248502, write M248500): #0 ff_thread_await_progress [..]/libavcodec/pthread_frame.c:591:26 (5ab42bb1a6f4b068d7863dabe9b2bacc+0xe749a1) Signed-off-by: Wan-Teh Chang <w...@google.com> --- libavcodec/pthread_frame.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 363b139f71..eb4d2d9458 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -133,6 +133,7 @@ typedef struct FrameThreadContext { * Set for the first N packets, where N is the number of threads. * While it is set, ff_thread_en/decode_frame won't return any results. */ + int debug_threads; ///< Set if the FF_DEBUG_THREADS option is set. } FrameThreadContext; #define THREAD_SAFE_CALLBACKS(avctx) \ @@ -566,7 +567,7 @@ 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) + if (p->parent->debug_threads) av_log(f->owner[field], AV_LOG_DEBUG, "%p finished %d field %d\n", progress, n, field); @@ -588,7 +589,7 @@ 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) + if (p->parent->debug_threads) av_log(f->owner[field], AV_LOG_DEBUG, "thread awaiting %d field %d from %p\n", n, field, progress); while (atomic_load_explicit(&progress[field], memory_order_relaxed) < n) @@ -763,6 +764,7 @@ int ff_frame_thread_init(AVCodecContext *avctx) fctx->async_lock = 1; fctx->delaying = 1; + fctx->debug_threads = (avctx->debug & FF_DEBUG_THREADS) != 0; for (i = 0; i < thread_count; i++) { AVCodecContext *copy = av_malloc(sizeof(AVCodecContext)); -- 2.13.2.725.g09c95d1e9-goog _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel