[FFmpeg-cvslog] Move the |die| member of FrameThreadContext to PerThreadContext.
Wan-Teh Chang
git at videolan.org
Tue Mar 1 19:54:30 CET 2016
ffmpeg | branch: master | Wan-Teh Chang <wtc-at-google.com at ffmpeg.org> | Tue Mar 1 10:11:53 2016 -0800| [4845f0720e38c5baab7baad52bfce1451f1c1639] | committer: Ronald S. Bultje
Move the |die| member of FrameThreadContext to PerThreadContext.
This fixes a data race warning by ThreadSanitizer.
FrameThreadContext.die is read by all the worker threads but is not
protected by any mutex. Move it to PerThreadContext so that each worker
thread reads its own copy of |die|, which can then be protected with
PerThreadContext.mutex.
Signed-off-by: Wan-Teh Chang <wtc at google.com>
Signed-off-by: Ronald S. Bultje <rsbultje at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4845f0720e38c5baab7baad52bfce1451f1c1639
---
libavcodec/pthread_frame.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index b77dd1e..c5ac44f 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -93,6 +93,8 @@ typedef struct PerThreadContext {
const enum AVPixelFormat *available_formats; ///< Format array for get_format()
enum AVPixelFormat result_format; ///< get_format() result
+
+ int die; ///< Set when the thread should exit.
} PerThreadContext;
/**
@@ -111,8 +113,6 @@ typedef struct FrameThreadContext {
* Set for the first N packets, where N is the number of threads.
* While it is set, ff_thread_en/decode_frame won't return any results.
*/
-
- int die; ///< Set when threads should exit.
} FrameThreadContext;
#define THREAD_SAFE_CALLBACKS(avctx) \
@@ -134,10 +134,10 @@ static attribute_align_arg void *frame_worker_thread(void *arg)
pthread_mutex_lock(&p->mutex);
while (1) {
- while (p->state == STATE_INPUT_READY && !fctx->die)
+ while (p->state == STATE_INPUT_READY && !p->die)
pthread_cond_wait(&p->input_cond, &p->mutex);
- if (fctx->die) break;
+ if (p->die) break;
if (!codec->update_thread_context && THREAD_SAFE_CALLBACKS(avctx))
ff_thread_finish_setup(avctx);
@@ -553,12 +553,11 @@ void ff_frame_thread_free(AVCodecContext *avctx, int thread_count)
fctx->threads->avctx->internal->is_copy = 1;
}
- fctx->die = 1;
-
for (i = 0; i < thread_count; i++) {
PerThreadContext *p = &fctx->threads[i];
pthread_mutex_lock(&p->mutex);
+ p->die = 1;
pthread_cond_signal(&p->input_cond);
pthread_mutex_unlock(&p->mutex);
More information about the ffmpeg-cvslog
mailing list