diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2015-10-13 18:29:04 +0200 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2015-10-13 19:08:42 +0200 |
commit | 147b12162da60da1ebfe38f626e9f82b2102f26b (patch) | |
tree | 2f392a6d95821230d0a8383070d122d70432565e /libavutil/fifo.c | |
parent | 5bd62a1b3c3356b84818efca3fcaf52da27a32af (diff) | |
download | ffmpeg-147b12162da60da1ebfe38f626e9f82b2102f26b.tar.gz |
avutil/fifo: Fix thread saftey of av_fifo_generic_peek()
changing the context state and restoring it is not safe if another
thread writes data into the fifo
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavutil/fifo.c')
-rw-r--r-- | libavutil/fifo.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/libavutil/fifo.c b/libavutil/fifo.c index 07fb4ec811..1a227087be 100644 --- a/libavutil/fifo.c +++ b/libavutil/fifo.c @@ -153,24 +153,22 @@ int av_fifo_generic_peek(AVFifoBuffer *f, void *dest, int buf_size, { // Read memory barrier needed for SMP here in theory uint8_t *rptr = f->rptr; - uint32_t rndx = f->rndx; do { - int len = FFMIN(f->end - f->rptr, buf_size); + int len = FFMIN(f->end - rptr, buf_size); if (func) - func(dest, f->rptr, len); + func(dest, rptr, len); else { - memcpy(dest, f->rptr, len); + memcpy(dest, rptr, len); dest = (uint8_t *)dest + len; } // memory barrier needed for SMP here in theory - av_fifo_drain(f, len); + rptr += len; + if (rptr >= f->end) + rptr -= f->end - f->buffer; buf_size -= len; } while (buf_size > 0); - f->rptr = rptr; - f->rndx = rndx; - return 0; } |