Commit 67d8eabd authored by Clément Bœsch's avatar Clément Bœsch

lavu/buffer: drop USE_ATOMICS

USE_ATOMICS is only set if there is no thread implementation enabled, in
which case you can't expect any lock mechanism from FFmpeg.

This is also conflicting with the incoming use of stdatomic.
parent f015711e
......@@ -284,44 +284,6 @@ void av_buffer_pool_uninit(AVBufferPool **ppool)
buffer_pool_free(pool);
}
#if USE_ATOMICS
/* remove the whole buffer list from the pool and return it */
static BufferPoolEntry *get_pool(AVBufferPool *pool)
{
BufferPoolEntry *cur = *(void * volatile *)&pool->pool, *last = NULL;
while (cur != last) {
last = cur;
cur = avpriv_atomic_ptr_cas((void * volatile *)&pool->pool, last, NULL);
if (!cur)
return NULL;
}
return cur;
}
static void add_to_pool(BufferPoolEntry *buf)
{
AVBufferPool *pool;
BufferPoolEntry *cur, *end = buf;
if (!buf)
return;
pool = buf->pool;
while (end->next)
end = end->next;
while (avpriv_atomic_ptr_cas((void * volatile *)&pool->pool, NULL, buf)) {
/* pool is not empty, retrieve it and append it to our list */
cur = get_pool(pool);
end->next = cur;
while (end->next)
end = end->next;
}
}
#endif
static void pool_release_buffer(void *opaque, uint8_t *data)
{
BufferPoolEntry *buf = opaque;
......@@ -330,14 +292,10 @@ static void pool_release_buffer(void *opaque, uint8_t *data)
if(CONFIG_MEMORY_POISONING)
memset(buf->data, FF_MEMORY_POISON, pool->size);
#if USE_ATOMICS
add_to_pool(buf);
#else
ff_mutex_lock(&pool->mutex);
buf->next = pool->pool;
pool->pool = buf;
ff_mutex_unlock(&pool->mutex);
#endif
if (!avpriv_atomic_int_add_and_fetch(&pool->refcount, -1))
buffer_pool_free(pool);
......@@ -369,11 +327,6 @@ static AVBufferRef *pool_alloc_buffer(AVBufferPool *pool)
ret->buffer->opaque = buf;
ret->buffer->free = pool_release_buffer;
#if USE_ATOMICS
avpriv_atomic_int_add_and_fetch(&pool->refcount, 1);
avpriv_atomic_int_add_and_fetch(&pool->nb_allocated, 1);
#endif
return ret;
}
......@@ -382,29 +335,6 @@ AVBufferRef *av_buffer_pool_get(AVBufferPool *pool)
AVBufferRef *ret;
BufferPoolEntry *buf;
#if USE_ATOMICS
/* check whether the pool is empty */
buf = get_pool(pool);
if (!buf && pool->refcount <= pool->nb_allocated) {
av_log(NULL, AV_LOG_DEBUG, "Pool race dectected, spining to avoid overallocation and eventual OOM\n");
while (!buf && avpriv_atomic_int_get(&pool->refcount) <= avpriv_atomic_int_get(&pool->nb_allocated))
buf = get_pool(pool);
}
if (!buf)
return pool_alloc_buffer(pool);
/* keep the first entry, return the rest of the list to the pool */
add_to_pool(buf->next);
buf->next = NULL;
ret = av_buffer_create(buf->data, pool->size, pool_release_buffer,
buf, 0);
if (!ret) {
add_to_pool(buf);
return NULL;
}
#else
ff_mutex_lock(&pool->mutex);
buf = pool->pool;
if (buf) {
......@@ -418,7 +348,6 @@ AVBufferRef *av_buffer_pool_get(AVBufferPool *pool)
ret = pool_alloc_buffer(pool);
}
ff_mutex_unlock(&pool->mutex);
#endif
if (ret)
avpriv_atomic_int_add_and_fetch(&pool->refcount, 1);
......
......@@ -87,8 +87,6 @@ struct AVBufferPool {
*/
volatile int refcount;
volatile int nb_allocated;
int size;
void *opaque;
AVBufferRef* (*alloc)(int size);
......
......@@ -26,8 +26,6 @@
#if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
#define USE_ATOMICS 0
#if HAVE_PTHREADS
#include <pthread.h>
......@@ -146,8 +144,6 @@ static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_
#else
#define USE_ATOMICS 1
#define AVMutex char
#define ff_mutex_init(mutex, attr) (0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment