From: Henrik Gramner Date: Sun, 25 Oct 2015 16:15:10 +0000 (+0100) Subject: Simplify threadpool_wait X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=24f7705f15cf6d59028a76a894d866b9fad85f39;p=x264 Simplify threadpool_wait --- diff --git a/common/threadpool.c b/common/threadpool.c index de1ae5f5..c65452ca 100644 --- a/common/threadpool.c +++ b/common/threadpool.c @@ -118,28 +118,23 @@ void x264_threadpool_run( x264_threadpool_t *pool, void *(*func)(void *), void * void *x264_threadpool_wait( x264_threadpool_t *pool, void *arg ) { - x264_threadpool_job_t *job = NULL; - x264_pthread_mutex_lock( &pool->done.mutex ); - while( !job ) + while( 1 ) { for( int i = 0; i < pool->done.i_size; i++ ) - { - x264_threadpool_job_t *t = (void*)pool->done.list[i]; - if( t->arg == arg ) + if( ((x264_threadpool_job_t*)pool->done.list[i])->arg == arg ) { - job = (void*)x264_frame_shift( pool->done.list+i ); + x264_threadpool_job_t *job = (void*)x264_frame_shift( pool->done.list+i ); pool->done.i_size--; + x264_pthread_mutex_unlock( &pool->done.mutex ); + + void *ret = job->ret; + x264_sync_frame_list_push( &pool->uninit, (void*)job ); + return ret; } - } - if( !job ) - x264_pthread_cond_wait( &pool->done.cv_fill, &pool->done.mutex ); - } - x264_pthread_mutex_unlock( &pool->done.mutex ); - void *ret = job->ret; - x264_sync_frame_list_push( &pool->uninit, (void*)job ); - return ret; + x264_pthread_cond_wait( &pool->done.cv_fill, &pool->done.mutex ); + } } static void x264_threadpool_list_delete( x264_sync_frame_list_t *slist )