From: Loren Merritt Date: Tue, 19 Dec 2006 21:24:47 +0000 (+0000) Subject: enable thread synchronization primitives on linux too X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=01e1db245d0c1c6119a8316994f2083c6096811a;p=x264.git enable thread synchronization primitives on linux too git-svn-id: svn://svn.videolan.org/x264/trunk@613 df754926-b1dd-0310-bc7b-ec298dee348c --- diff --git a/common/common.h b/common/common.h index d69d894b..7c21a8c4 100644 --- a/common/common.h +++ b/common/common.h @@ -64,6 +64,7 @@ #elif defined(HAVE_PTHREAD) #include +#define USE_CONDITION_VAR #else #define pthread_t int #define pthread_create(t,u,f,d) diff --git a/common/frame.c b/common/frame.c index 80346667..57dfbd78 100644 --- a/common/frame.c +++ b/common/frame.c @@ -761,26 +761,24 @@ void x264_deblock_init( int cpu, x264_deblock_function_t *pf ) /* threading */ #ifdef HAVE_PTHREAD -void x264_frame_cond_broadcast( x264_frame_t *frame ) +void x264_frame_cond_broadcast( x264_frame_t *frame, int i_lines_completed ) { pthread_mutex_lock( &frame->mutex ); + frame->i_lines_completed = i_lines_completed; pthread_cond_broadcast( &frame->cv ); pthread_mutex_unlock( &frame->mutex ); } void x264_frame_cond_wait( x264_frame_t *frame, int i_lines_completed ) { - if( frame->i_lines_completed < i_lines_completed ) - { - pthread_mutex_lock( &frame->mutex ); - while( frame->i_lines_completed < i_lines_completed ) - pthread_cond_wait( &frame->cv, &frame->mutex ); - pthread_mutex_unlock( &frame->mutex ); - } + pthread_mutex_lock( &frame->mutex ); + while( frame->i_lines_completed < i_lines_completed ) + pthread_cond_wait( &frame->cv, &frame->mutex ); + pthread_mutex_unlock( &frame->mutex ); } #else -void x264_frame_cond_broadcast( x264_frame_t *frame ) +void x264_frame_cond_broadcast( x264_frame_t *frame, int i_lines_completed ) {} void x264_frame_cond_wait( x264_frame_t *frame, int i_lines_completed ) {} diff --git a/common/frame.h b/common/frame.h index 099a1f57..7e138620 100644 --- a/common/frame.h +++ b/common/frame.h @@ -110,7 +110,7 @@ void x264_frame_init_lowres( int cpu, x264_frame_t *frame ); void x264_deblock_init( int cpu, x264_deblock_function_t *pf ); -void x264_frame_cond_broadcast( x264_frame_t *frame ); +void x264_frame_cond_broadcast( x264_frame_t *frame, int i_lines_completed ); void x264_frame_cond_wait( x264_frame_t *frame, int i_lines_completed ); void x264_frame_push( x264_frame_t **list, x264_frame_t *frame ); diff --git a/encoder/encoder.c b/encoder/encoder.c index b278f6bb..fb9a2bd7 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -920,10 +920,9 @@ static void x264_fdec_filter_row( x264_t *h, int mb_y ) x264_frame_expand_border_filtered( h, h->fdec, min_y, b_end ); } - if( h->param.i_threads > 1 ) + if( h->param.i_threads > 1 && h->fdec->b_kept_as_ref ) { - h->fdec->i_lines_completed = mb_y*16 + (b_end ? 10000 : -(X264_THREAD_HEIGHT << h->sh.b_mbaff)); - x264_frame_cond_broadcast( h->fdec ); + x264_frame_cond_broadcast( h->fdec, mb_y*16 + (b_end ? 10000 : -(X264_THREAD_HEIGHT << h->sh.b_mbaff)) ); } }