changeset 9607:9eceacadf27b

me: split initialization to avoid harmless race hazard
author Steve Borho <steve@borho.org>
date Mon, 02 Mar 2015 18:52:34 -0600
parents 058cbd563b8f
children e1b402399735
files source/encoder/encoder.cpp source/encoder/motion.cpp source/encoder/motion.h
diffstat 3 files changed, 35 insertions(+-), 35 deletions(-) [+]
line wrap: on
line diff
--- a/source/encoder/encoder.cpp	Wed Mar 04 10:35:55 2015 -0600
+++ b/source/encoder/encoder.cpp	Mon Mar 02 18:52:34 2015 -0600
@@ -81,6 +81,8 @@ Encoder::Encoder()
     m_analysisFile = NULL;
     for (int i = 0; i < X265_MAX_FRAME_THREADS; i++)
         m_frameEncoder[i] = NULL;
+
+    MotionEstimate::initScales();
 }
 
 void Encoder::create()
--- a/source/encoder/motion.cpp	Wed Mar 04 10:35:55 2015 -0600
+++ b/source/encoder/motion.cpp	Mon Mar 02 18:52:34 2015 -0600
@@ -59,38 +59,6 @@ const SubpelWorkload workload[X265_MAX_S
 int sizeScale[NUM_PU_SIZES];
 #define SAD_THRESH(v) (bcost < (((v >> 4) * sizeScale[partEnum])))
 
-void initScales(void)
-{
-#define SETUP_SCALE(W, H) \
-    sizeScale[LUMA_ ## W ## x ## H] = (H * H) >> 4;
-    SETUP_SCALE(4, 4);
-    SETUP_SCALE(8, 8);
-    SETUP_SCALE(8, 4);
-    SETUP_SCALE(4, 8);
-    SETUP_SCALE(16, 16);
-    SETUP_SCALE(16, 8);
-    SETUP_SCALE(8, 16);
-    SETUP_SCALE(16, 12);
-    SETUP_SCALE(12, 16);
-    SETUP_SCALE(4, 16);
-    SETUP_SCALE(16, 4);
-    SETUP_SCALE(32, 32);
-    SETUP_SCALE(32, 16);
-    SETUP_SCALE(16, 32);
-    SETUP_SCALE(32, 24);
-    SETUP_SCALE(24, 32);
-    SETUP_SCALE(32, 8);
-    SETUP_SCALE(8, 32);
-    SETUP_SCALE(64, 64);
-    SETUP_SCALE(64, 32);
-    SETUP_SCALE(32, 64);
-    SETUP_SCALE(64, 48);
-    SETUP_SCALE(48, 64);
-    SETUP_SCALE(64, 16);
-    SETUP_SCALE(16, 64);
-#undef SETUP_SCALE
-}
-
 /* radius 2 hexagon. repeated entries are to avoid having to compute mod6 every time. */
 const MV hex2[8] = { MV(-1, -2), MV(-2, 0), MV(-1, 2), MV(1, 2), MV(2, 0), MV(1, -2), MV(-1, -2), MV(-2, 0) };
 const uint8_t mod6m1[8] = { 5, 0, 1, 2, 3, 4, 5, 0 };  /* (x-1)%6 */
@@ -142,14 +110,43 @@ MotionEstimate::MotionEstimate()
 
 void MotionEstimate::init(int method, int refine, int csp)
 {
-    if (!sizeScale[0])
-        initScales();
-
     searchMethod = method;
     subpelRefine = refine;
     fencPUYuv.create(FENC_STRIDE, csp);
 }
 
+void MotionEstimate::initScales(void)
+{
+#define SETUP_SCALE(W, H) \
+    sizeScale[LUMA_ ## W ## x ## H] = (H * H) >> 4;
+    SETUP_SCALE(4, 4);
+    SETUP_SCALE(8, 8);
+    SETUP_SCALE(8, 4);
+    SETUP_SCALE(4, 8);
+    SETUP_SCALE(16, 16);
+    SETUP_SCALE(16, 8);
+    SETUP_SCALE(8, 16);
+    SETUP_SCALE(16, 12);
+    SETUP_SCALE(12, 16);
+    SETUP_SCALE(4, 16);
+    SETUP_SCALE(16, 4);
+    SETUP_SCALE(32, 32);
+    SETUP_SCALE(32, 16);
+    SETUP_SCALE(16, 32);
+    SETUP_SCALE(32, 24);
+    SETUP_SCALE(24, 32);
+    SETUP_SCALE(32, 8);
+    SETUP_SCALE(8, 32);
+    SETUP_SCALE(64, 64);
+    SETUP_SCALE(64, 32);
+    SETUP_SCALE(32, 64);
+    SETUP_SCALE(64, 48);
+    SETUP_SCALE(48, 64);
+    SETUP_SCALE(64, 16);
+    SETUP_SCALE(16, 64);
+#undef SETUP_SCALE
+}
+
 MotionEstimate::~MotionEstimate()
 {
     fencPUYuv.destroy();
--- a/source/encoder/motion.h	Wed Mar 04 10:35:55 2015 -0600
+++ b/source/encoder/motion.h	Mon Mar 02 18:52:34 2015 -0600
@@ -67,6 +67,7 @@ public:
     MotionEstimate();
     ~MotionEstimate();
 
+    static void initScales();
     void init(int method, int refine, int csp);
 
     /* Methods called at slice setup */