[FFmpeg-cvslog] Merge commit '27079a426c9d3db918b158976e44b9b143d78e1c'

Clément Bœsch git at videolan.org
Wed Mar 22 18:49:13 EET 2017


ffmpeg | branch: master | Clément Bœsch <u at pkh.me> | Wed Mar 22 17:46:01 2017 +0100| [443e9692935f1f6c9abefbc842e9f2f5ae6b065d] | committer: Clément Bœsch

Merge commit '27079a426c9d3db918b158976e44b9b143d78e1c'

* commit '27079a426c9d3db918b158976e44b9b143d78e1c':
  buffer: convert to stdatomic

Merged-by: Clément Bœsch <u at pkh.me>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=443e9692935f1f6c9abefbc842e9f2f5ae6b065d
---

 libavutil/buffer.c          | 23 ++++++++++++-----------
 libavutil/buffer_internal.h |  5 +++--
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/libavutil/buffer.c b/libavutil/buffer.c
index 33cb513..8d1aa5f 100644
--- a/libavutil/buffer.c
+++ b/libavutil/buffer.c
@@ -16,10 +16,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <stdatomic.h>
 #include <stdint.h>
 #include <string.h>
 
-#include "atomic.h"
 #include "buffer_internal.h"
 #include "common.h"
 #include "mem.h"
@@ -40,7 +40,8 @@ AVBufferRef *av_buffer_create(uint8_t *data, int size,
     buf->size     = size;
     buf->free     = free ? free : av_buffer_default_free;
     buf->opaque   = opaque;
-    buf->refcount = 1;
+
+    atomic_init(&buf->refcount, 1);
 
     if (flags & AV_BUFFER_FLAG_READONLY)
         buf->flags |= BUFFER_FLAG_READONLY;
@@ -98,7 +99,7 @@ AVBufferRef *av_buffer_ref(AVBufferRef *buf)
 
     *ret = *buf;
 
-    avpriv_atomic_int_add_and_fetch(&buf->buffer->refcount, 1);
+    atomic_fetch_add_explicit(&buf->buffer->refcount, 1, memory_order_relaxed);
 
     return ret;
 }
@@ -115,7 +116,7 @@ static void buffer_replace(AVBufferRef **dst, AVBufferRef **src)
     } else
         av_freep(dst);
 
-    if (!avpriv_atomic_int_add_and_fetch(&b->refcount, -1)) {
+    if (atomic_fetch_add_explicit(&b->refcount, -1, memory_order_acq_rel) == 1) {
         b->free(b->opaque, b->data);
         av_freep(&b);
     }
@@ -134,7 +135,7 @@ int av_buffer_is_writable(const AVBufferRef *buf)
     if (buf->buffer->flags & AV_BUFFER_FLAG_READONLY)
         return 0;
 
-    return avpriv_atomic_int_get(&buf->buffer->refcount) == 1;
+    return atomic_load(&buf->buffer->refcount) == 1;
 }
 
 void *av_buffer_get_opaque(const AVBufferRef *buf)
@@ -144,7 +145,7 @@ void *av_buffer_get_opaque(const AVBufferRef *buf)
 
 int av_buffer_get_ref_count(const AVBufferRef *buf)
 {
-    return buf->buffer->refcount;
+    return atomic_load(&buf->buffer->refcount);
 }
 
 int av_buffer_make_writable(AVBufferRef **pbuf)
@@ -229,7 +230,7 @@ AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
     pool->alloc2    = alloc;
     pool->pool_free = pool_free;
 
-    avpriv_atomic_int_set(&pool->refcount, 1);
+    atomic_init(&pool->refcount, 1);
 
     return pool;
 }
@@ -245,7 +246,7 @@ AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size))
     pool->size     = size;
     pool->alloc    = alloc ? alloc : av_buffer_alloc;
 
-    avpriv_atomic_int_set(&pool->refcount, 1);
+    atomic_init(&pool->refcount, 1);
 
     return pool;
 }
@@ -280,7 +281,7 @@ void av_buffer_pool_uninit(AVBufferPool **ppool)
     pool   = *ppool;
     *ppool = NULL;
 
-    if (!avpriv_atomic_int_add_and_fetch(&pool->refcount, -1))
+    if (atomic_fetch_add_explicit(&pool->refcount, -1, memory_order_acq_rel) == 1)
         buffer_pool_free(pool);
 }
 
@@ -297,7 +298,7 @@ static void pool_release_buffer(void *opaque, uint8_t *data)
     pool->pool = buf;
     ff_mutex_unlock(&pool->mutex);
 
-    if (!avpriv_atomic_int_add_and_fetch(&pool->refcount, -1))
+    if (atomic_fetch_add_explicit(&pool->refcount, -1, memory_order_acq_rel) == 1)
         buffer_pool_free(pool);
 }
 
@@ -350,7 +351,7 @@ AVBufferRef *av_buffer_pool_get(AVBufferPool *pool)
     ff_mutex_unlock(&pool->mutex);
 
     if (ret)
-        avpriv_atomic_int_add_and_fetch(&pool->refcount, 1);
+        atomic_fetch_add_explicit(&pool->refcount, 1, memory_order_relaxed);
 
     return ret;
 }
diff --git a/libavutil/buffer_internal.h b/libavutil/buffer_internal.h
index bbd40a0..54b6704 100644
--- a/libavutil/buffer_internal.h
+++ b/libavutil/buffer_internal.h
@@ -19,6 +19,7 @@
 #ifndef AVUTIL_BUFFER_INTERNAL_H
 #define AVUTIL_BUFFER_INTERNAL_H
 
+#include <stdatomic.h>
 #include <stdint.h>
 
 #include "buffer.h"
@@ -40,7 +41,7 @@ struct AVBuffer {
     /**
      *  number of existing AVBufferRef instances referring to this buffer
      */
-    volatile int refcount;
+    atomic_uint refcount;
 
     /**
      * a callback for freeing the data
@@ -85,7 +86,7 @@ struct AVBufferPool {
      * buffers have been released, then it's safe to free the pool and all
      * the buffers in it.
      */
-    volatile int refcount;
+    atomic_uint refcount;
 
     int size;
     void *opaque;


======================================================================

diff --cc libavutil/buffer.c
index 33cb513,0e2b4ef..8d1aa5f
--- a/libavutil/buffer.c
+++ b/libavutil/buffer.c
@@@ -107,15 -108,12 +108,15 @@@ static void buffer_replace(AVBufferRef 
  {
      AVBuffer *b;
  
 -    if (!buf || !*buf)
 -        return;
 -    b = (*buf)->buffer;
 -    av_freep(buf);
 +    b = (*dst)->buffer;
 +
 +    if (src) {
 +        **dst = **src;
 +        av_freep(src);
 +    } else
 +        av_freep(dst);
  
-     if (!avpriv_atomic_int_add_and_fetch(&b->refcount, -1)) {
+     if (atomic_fetch_add_explicit(&b->refcount, -1, memory_order_acq_rel) == 1) {
          b->free(b->opaque, b->data);
          av_freep(&b);
      }
@@@ -134,19 -124,9 +135,19 @@@ int av_buffer_is_writable(const AVBuffe
      if (buf->buffer->flags & AV_BUFFER_FLAG_READONLY)
          return 0;
  
-     return avpriv_atomic_int_get(&buf->buffer->refcount) == 1;
+     return atomic_load(&buf->buffer->refcount) == 1;
  }
  
 +void *av_buffer_get_opaque(const AVBufferRef *buf)
 +{
 +    return buf->buffer->opaque;
 +}
 +
 +int av_buffer_get_ref_count(const AVBufferRef *buf)
 +{
-     return buf->buffer->refcount;
++    return atomic_load(&buf->buffer->refcount);
 +}
 +
  int av_buffer_make_writable(AVBufferRef **pbuf)
  {
      AVBufferRef *newbuf, *buf = *pbuf;



More information about the ffmpeg-cvslog mailing list