[x264-devel] Simplify threadpool_wait

Henrik Gramner git at videolan.org
Sun Jan 17 22:17:55 CET 2016


x264 | branch: master | Henrik Gramner <henrik at gramner.com> | Sun Oct 25 17:15:10 2015 +0100| [24f7705f15cf6d59028a76a894d866b9fad85f39] | committer: Henrik Gramner

Simplify threadpool_wait

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

 common/threadpool.c |   25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/common/threadpool.c b/common/threadpool.c
index de1ae5f..c65452c 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 )



More information about the x264-devel mailing list