Simplify threadpool_wait
authorHenrik Gramner <henrik@gramner.com>
Sun, 25 Oct 2015 16:15:10 +0000 (17:15 +0100)
committerHenrik Gramner <henrik@gramner.com>
Sat, 16 Jan 2016 23:30:13 +0000 (00:30 +0100)
common/threadpool.c

index de1ae5f..c65452c 100644 (file)
@@ -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 )