Commit Graph

5 Commits

Author SHA1 Message Date
Anton Khirnov 27079a426c buffer: convert to stdatomic 2016-10-02 18:58:04 +02:00
Anton Khirnov 721a4efc05 buffer: add support for pools using caller data in allocation
This should allow using more complex allocators than simple malloc
wrappers.
2016-02-14 21:24:39 +01:00
wm4 fbd6c97f9c lavu: fix memory leaks by using a mutex instead of atomics
The buffer pool has to atomically add and remove entries from the linked
list of available buffers. This was done by removing the entire list
with a CAS operation, working on it, and then setting it back again
(using a retry-loop in case another thread was doing the same thing).

This could effectively cause memory leaks: while a thread was working on
the buffer list, other threads would allocate new buffers, increasing
the pool's total size. There was no real leak, but since these extra
buffers were not needed, but not free'd either (except when the buffer
pool was destroyed), this had the same effects as a real leak. For some
reason, growth was exponential, and could easily kill the process due
to OOM in real-world uses.

Fix this by using a mutex to protect the list operations. The fancy
way atomics remove the whole list to work on it is not needed anymore,
which also avoids the situation which was causing the leak.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2014-11-27 13:36:00 +01:00
Anton Khirnov 1cec0624d0 AVBuffer: add a new API for buffer pools 2013-03-08 07:33:28 +01:00
Anton Khirnov 8e401dbe90 lavu: add a new API for reference-counted data buffers. 2013-03-08 07:33:03 +01:00