]> granicus.if.org Git - libvpx/commitdiff
make vp9 encoder static initializers thread safe
authorJim Bankoski <jimbankoski@google.com>
Thu, 18 Dec 2014 23:50:46 +0000 (15:50 -0800)
committerJim Bankoski <jimbankoski@google.com>
Thu, 18 Dec 2014 23:50:46 +0000 (15:50 -0800)
Change-Id: If2d0888d13ebe52bc7c3b16f16319408a86ab6de

vp9/common/vp9_rtcd.c
vp9/decoder/vp9_decoder.c
vp9/encoder/vp9_encoder.c
vp9/vp9_cx_iface.c

index dc15a84ff172ec27e3e0857eeea12c045bde9836..c777bc81f2621b0116511b6b5528bac292d4cf1f 100644 (file)
@@ -16,5 +16,7 @@ void vpx_scale_rtcd(void);
 
 void vp9_rtcd() {
     vpx_scale_rtcd();
+    // TODO(JBB): Remove this once, by insuring that both the encoder and
+    // decoder setup functions are protected by once();
     once(setup_rtcd_internal);
 }
index 2daf86200a5f836a6c307e4116696f091a1c0da1..185b268b3ffe719a2bd480f09bcf232a9482dc94 100644 (file)
@@ -15,6 +15,7 @@
 #include "./vpx_scale_rtcd.h"
 
 #include "vpx_mem/vpx_mem.h"
+#include "vpx_ports/vpx_once.h"
 #include "vpx_ports/vpx_timer.h"
 #include "vpx_scale/vpx_scale.h"
 
@@ -34,7 +35,7 @@
 #include "vp9/decoder/vp9_dthread.h"
 
 static void initialize_dec() {
-  static int init_done = 0;
+  static volatile int init_done = 0;
 
   if (!init_done) {
     vp9_rtcd();
@@ -85,7 +86,7 @@ VP9Decoder *vp9_decoder_create() {
                   sizeof(*cm->frame_contexts)));
 
   pbi->need_resync = 1;
-  initialize_dec();
+  once(initialize_dec);
 
   // Initialize the references to not point to any frame buffers.
   vpx_memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map));
index aaa6b238dc6082a4e10bcec0d41ef60e49d908f8..e821e3b49e7ca283be6468f4acd1090c49f1c720 100644 (file)
@@ -182,7 +182,7 @@ static void vp9_swap_mi_and_prev_mi(VP9_COMMON *cm) {
 }
 
 void vp9_initialize_enc() {
-  static int init_done = 0;
+  static volatile int init_done = 0;
 
   if (!init_done) {
     vp9_rtcd();
index b9fb8140ce777c25cd22c28242438e7537fa09a0..0d663deb98cd673f946a8f27f509161941ce33ba 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "./vpx_config.h"
 #include "vpx/vpx_codec.h"
+#include "vpx_ports/vpx_once.h"
 #include "vpx/internal/vpx_codec_internal.h"
 #include "./vpx_version.h"
 #include "vp9/encoder/vp9_encoder.h"
@@ -729,7 +730,7 @@ static vpx_codec_err_t encoder_init(vpx_codec_ctx_t *ctx,
     }
 
     priv->extra_cfg = default_extra_cfg;
-    vp9_initialize_enc();
+    once(vp9_initialize_enc);
 
     res = validate_config(priv, &priv->cfg, &priv->extra_cfg);