From 5c85e0a2b7992fcaab09418e3fcefc613cffc743 Mon Sep 17 00:00:00 2001 From: Anton Mitrofanov Date: Sun, 11 Mar 2012 23:08:18 -0700 Subject: [PATCH] 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. --- encoder/encoder.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) 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 ); -- 2.47.3