[FFmpeg-cvslog] avutil/fifo: Fix thread saftey of av_fifo_generic_peek()
Michael Niedermayer
git at videolan.org
Tue Oct 13 19:27:26 CEST 2015
ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Tue Oct 13 18:29:04 2015 +0200| [147b12162da60da1ebfe38f626e9f82b2102f26b] | committer: Michael Niedermayer
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 at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=147b12162da60da1ebfe38f626e9f82b2102f26b
---
libavutil/fifo.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 07fb4ec..1a22708 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;
}
More information about the ffmpeg-cvslog
mailing list