[x264-devel] Fix clobbering of mutex/cvs

Anton Mitrofanov git at videolan.org
Mon Mar 12 21:00:00 CET 2012


x264 | branch: master | Anton Mitrofanov <Bugmaster at narod.ru> | Sun Mar 11 23:08:18 2012 -0700| [5c85e0a2b7992fcaab09418e3fcefc613cffc743] | committer: Jason Garrett-Glaser

Fix clobbering of mutex/cvs
Regression in r2183.
Bizarrely seemed to work on many platforms, but crashed on win64 and may have been slower.
Only affected sliced threads during encoding, but could cause crashes on x264 encoder close even without sliced threads.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=5c85e0a2b7992fcaab09418e3fcefc613cffc743
---

 encoder/encoder.c |   19 +++++++------------
 1 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/encoder/encoder.c b/encoder/encoder.c
index 910dec0..2539b3f 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -1271,18 +1271,8 @@ x264_t *x264_encoder_open( x264_param_t *param )
         goto fail;
 
     h->thread[0] = h;
-    for( int i = 0; i < h->param.i_threads + !!h->param.i_sync_lookahead; i++ )
-    {
-        if( i )
-            CHECKED_MALLOC( h->thread[i], sizeof(x264_t) );
-        if( i < h->param.i_threads )
-        {
-            if( x264_pthread_mutex_init( &h->thread[i]->mutex, NULL ) )
-                goto fail;
-            if( x264_pthread_cond_init( &h->thread[i]->cv, NULL ) )
-                goto fail;
-        }
-    }
+    for( int i = 1; i < h->param.i_threads + !!h->param.i_sync_lookahead; i++ )
+        CHECKED_MALLOC( h->thread[i], sizeof(x264_t) );
 
     for( int i = 0; i < h->param.i_threads; i++ )
     {
@@ -1291,6 +1281,11 @@ x264_t *x264_encoder_open( x264_param_t *param )
         if( i > 0 )
             *h->thread[i] = *h;
 
+        if( x264_pthread_mutex_init( &h->thread[i]->mutex, NULL ) )
+            goto fail;
+        if( x264_pthread_cond_init( &h->thread[i]->cv, NULL ) )
+            goto fail;
+
         if( allocate_threadlocal_data )
         {
             h->thread[i]->fdec = x264_frame_pop_unused( h, 1 );



More information about the x264-devel mailing list