[FFmpeg-devel] [PATCH 181/191] avcodec/h261: Make ff_h261_common_init() thread-safe

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Mon Nov 23 21:37:29 EET 2020


Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavcodec/h261.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/libavcodec/h261.c b/libavcodec/h261.c
index 47bad4e57f..9c848eb7e8 100644
--- a/libavcodec/h261.c
+++ b/libavcodec/h261.c
@@ -25,6 +25,8 @@
  * H.261 codec
  */
 
+#include "libavutil/thread.h"
+
 #include "avcodec.h"
 #include "h261.h"
 
@@ -80,13 +82,13 @@ void ff_h261_loop_filter(MpegEncContext *s)
     h261_loop_filter(dest_cr, uvlinesize);
 }
 
-av_cold void ff_h261_common_init(void)
+static av_cold void h261_common_init(void)
 {
-    static int done = 0;
-
-    if (done)
-        return;
-
     ff_rl_init(&ff_h261_rl_tcoeff, ff_h261_rl_table_store);
-    done = 1;
+}
+
+av_cold void ff_h261_common_init(void)
+{
+    static AVOnce init_static_once = AV_ONCE_INIT;
+    ff_thread_once(&init_static_once, h261_common_init);
 }
-- 
2.25.1



More information about the ffmpeg-devel mailing list