diff mbox series

[FFmpeg-devel,03/13] avcodec/vp9: Check initializing conditions/mutexes

Message ID AM7PR03MB6660051CF6F7694C0C57D2D88FCE9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 0e0906726133519c59a2234162df66f53d755de0
Headers show
Series [FFmpeg-devel,01/13] avcodec/vp9: Do not destroy uninitialized mutexes/conditions | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 fail Make fate failed
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 2, 2021, 3:41 p.m. UTC
Also don't destroy uninitialized conditions/mutexes.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/vp9.c    | 17 +++++++++++------
 libavcodec/vp9dec.h |  1 +
 2 files changed, 12 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 5c20a7ec5d..239475cdbe 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -27,6 +27,8 @@ 
 #include "internal.h"
 #include "profiles.h"
 #include "thread.h"
+#include "pthread_internal.h"
+
 #include "videodsp.h"
 #include "vp56.h"
 #include "vp9.h"
@@ -39,6 +41,10 @@ 
 #define VP9_SYNCCODE 0x498342
 
 #if HAVE_THREADS
+DEFINE_OFFSET_ARRAY(VP9Context, vp9_context, pthread_init_cnt,
+                    (offsetof(VP9Context, progress_mutex)),
+                    (offsetof(VP9Context, progress_cond)));
+
 static void vp9_free_entries(AVCodecContext *avctx) {
     VP9Context *s = avctx->priv_data;
 
@@ -1248,10 +1254,7 @@  static av_cold int vp9_decode_free(AVCodecContext *avctx)
     free_buffers(s);
     vp9_free_entries(avctx);
 #if HAVE_THREADS
-    if (avctx->active_thread_type & FF_THREAD_SLICE) {
-        pthread_mutex_destroy(&s->progress_mutex);
-        pthread_cond_destroy(&s->progress_cond);
-    }
+    ff_pthread_free(s, vp9_context_offsets);
 #endif
     av_freep(&s->td);
     return 0;
@@ -1794,14 +1797,16 @@  static void vp9_decode_flush(AVCodecContext *avctx)
 static av_cold int vp9_decode_init(AVCodecContext *avctx)
 {
     VP9Context *s = avctx->priv_data;
+    int ret;
 
     s->last_bpp = 0;
     s->s.h.filter.sharpness = -1;
 
 #if HAVE_THREADS
     if (avctx->active_thread_type & FF_THREAD_SLICE) {
-        pthread_mutex_init(&s->progress_mutex, NULL);
-        pthread_cond_init(&s->progress_cond, NULL);
+        ret = ff_pthread_init(s, vp9_context_offsets);
+        if (ret < 0)
+            return ret;
     }
 #endif
 
diff --git a/libavcodec/vp9dec.h b/libavcodec/vp9dec.h
index d82b258a3d..9cbd5839a8 100644
--- a/libavcodec/vp9dec.h
+++ b/libavcodec/vp9dec.h
@@ -105,6 +105,7 @@  typedef struct VP9Context {
     pthread_mutex_t progress_mutex;
     pthread_cond_t progress_cond;
     atomic_int *entries;
+    unsigned pthread_init_cnt;
 #endif
 
     uint8_t ss_h, ss_v;