From: Anton Mitrofanov Date: Mon, 12 Mar 2012 06:08:18 +0000 (-0700) Subject: Fix clobbering of mutex/cvs X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=5c85e0a2b7992fcaab09418e3fcefc613cffc743;p=x264.git 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. --- diff --git a/encoder/encoder.c b/encoder/encoder.c index 910dec07..2539b3fc 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 );