]> granicus.if.org Git - libx264/commitdiff
lookahead: Keep b_exit_thread under ifbuf.mutex
authorJean-Baptiste Kempf <jb@videolan.org>
Tue, 28 Sep 2021 19:47:40 +0000 (21:47 +0200)
committerAnton Mitrofanov <bugmaster@narod.ru>
Wed, 29 Sep 2021 21:34:37 +0000 (21:34 +0000)
The lookahead_thread main loop checks b_exit_thread and exits if it is set.
That flag is set by x264_lookahead_delete, which uses ifbuf.mutex to guard accessing it.
However, the read in the while-loop condition of lookahead_thread is not guarded,
and so TSAN sometimes reports a data race.

encoder/lookahead.c

index 18958bd0a06b9d7b7fdea5de4cdf5612bbe7e783..93f59b1906a78d96d38be55916b1c0a061c29d82 100644 (file)
@@ -89,9 +89,14 @@ static void lookahead_slicetype_decide( x264_t *h )
 
 REALIGN_STACK static void *lookahead_thread( x264_t *h )
 {
-    while( !h->lookahead->b_exit_thread )
+    while( 1 )
     {
         x264_pthread_mutex_lock( &h->lookahead->ifbuf.mutex );
+        if( h->lookahead->b_exit_thread )
+        {
+            x264_pthread_mutex_unlock( &h->lookahead->ifbuf.mutex );
+            break;
+        }
         x264_pthread_mutex_lock( &h->lookahead->next.mutex );
         int shift = X264_MIN( h->lookahead->next.i_max_size - h->lookahead->next.i_size, h->lookahead->ifbuf.i_size );
         lookahead_shift( &h->lookahead->next, &h->lookahead->ifbuf, shift );