Browse code

pthread : Remove lock/unlock pairs in worker loop to avoid unexpected state changes.

Reviewed-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Aaron Colwell authored on 2012/03/23 04:37:47
Showing 1 changed files
... ...
@@ -365,21 +365,17 @@ static attribute_align_arg void *frame_worker_thread(void *arg)
365 365
     AVCodecContext *avctx = p->avctx;
366 366
     AVCodec *codec = avctx->codec;
367 367
 
368
+    pthread_mutex_lock(&p->mutex);
368 369
     while (1) {
369 370
         int i;
370
-        if (p->state == STATE_INPUT_READY && !fctx->die) {
371
-            pthread_mutex_lock(&p->mutex);
372 371
             while (p->state == STATE_INPUT_READY && !fctx->die)
373 372
                 pthread_cond_wait(&p->input_cond, &p->mutex);
374
-            pthread_mutex_unlock(&p->mutex);
375
-        }
376 373
 
377 374
         if (fctx->die) break;
378 375
 
379 376
         if (!codec->update_thread_context && (avctx->thread_safe_callbacks || avctx->get_buffer == avcodec_default_get_buffer))
380 377
             ff_thread_finish_setup(avctx);
381 378
 
382
-        pthread_mutex_lock(&p->mutex);
383 379
         avcodec_get_frame_defaults(&p->frame);
384 380
         p->got_frame = 0;
385 381
         p->result = codec->decode(avctx, &p->frame, &p->got_frame, &p->avpkt);
... ...
@@ -397,9 +393,8 @@ static attribute_align_arg void *frame_worker_thread(void *arg)
397 397
         pthread_cond_broadcast(&p->progress_cond);
398 398
         pthread_cond_signal(&p->output_cond);
399 399
         pthread_mutex_unlock(&p->progress_mutex);
400
-
401
-        pthread_mutex_unlock(&p->mutex);
402 400
     }
401
+    pthread_mutex_unlock(&p->mutex);
403 402
 
404 403
     return NULL;
405 404
 }