]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pthread_frame.c
Merge commit 'c95169f0ec68bdeeabc5fde8aa4076f406242524'
[ffmpeg] / libavcodec / pthread_frame.c
index 363b139f71803b6f114da5bca98c82df5f536263..2c702c737218924c4ef6eda7fa13be6383c6e918 100644 (file)
@@ -107,6 +107,8 @@ typedef struct PerThreadContext {
 
     int hwaccel_serializing;
     int async_serializing;
+
+    atomic_int debug_threads;       ///< Set if the FF_DEBUG_THREADS option is set.
 } PerThreadContext;
 
 /**
@@ -398,6 +400,9 @@ static int submit_packet(PerThreadContext *p, AVCodecContext *user_avctx,
         pthread_mutex_unlock(&p->mutex);
         return ret;
     }
+    atomic_store_explicit(&p->debug_threads,
+                          (p->avctx->debug & FF_DEBUG_THREADS) != 0,
+                          memory_order_relaxed);
 
     release_delayed_buffers(p);
 
@@ -565,11 +570,12 @@ 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 (atomic_load_explicit(&p->debug_threads, memory_order_relaxed))
         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);
@@ -587,10 +593,11 @@ 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 (atomic_load_explicit(&p->debug_threads, memory_order_relaxed))
         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);
@@ -732,8 +739,10 @@ int ff_frame_thread_init(AVCodecContext *avctx)
 
     if (!thread_count) {
         int nb_cpus = av_cpu_count();
+#if FF_API_DEBUG_MV
         if ((avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) || avctx->debug_mv)
             nb_cpus = 1;
+#endif
         // use number of cores + 1 as thread count if there is more than one
         if (nb_cpus > 1)
             thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);
@@ -823,6 +832,8 @@ int ff_frame_thread_init(AVCodecContext *avctx)
 
         if (err) goto error;
 
+        atomic_init(&p->debug_threads, (copy->debug & FF_DEBUG_THREADS) != 0);
+
         err = AVERROR(pthread_create(&p->thread, NULL, frame_worker_thread, p));
         p->thread_init= !err;
         if(!p->thread_init)