diff mbox

[FFmpeg-devel] avutil/buffer: use appropriate atomic operations

Message ID 20191205090207.53666-1-quinkblack@foxmail.com
State Accepted
Commit 71fd72070c867b4f442e5c71baab9775c51273dc
Headers show

Commit Message

Zhao Zhili Dec. 5, 2019, 9:02 a.m. UTC
From: Zhao Zhili <zhilizhao@tencent.com>

No functional changes. ref/unref vs add/sub is symmetrical.
---
 libavutil/buffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

James Almer Dec. 5, 2019, 11:55 p.m. UTC | #1
On 12/5/2019 6:02 AM, quinkblack@foxmail.com wrote:
> From: Zhao Zhili <zhilizhao@tencent.com>
> 
> No functional changes. ref/unref vs add/sub is symmetrical.
> ---
>  libavutil/buffer.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
> index 8d1aa5fa84..f0034b026a 100644
> --- a/libavutil/buffer.c
> +++ b/libavutil/buffer.c
> @@ -116,7 +116,7 @@ static void buffer_replace(AVBufferRef **dst, AVBufferRef **src)
>      } else
>          av_freep(dst);
>  
> -    if (atomic_fetch_add_explicit(&b->refcount, -1, memory_order_acq_rel) == 1) {
> +    if (atomic_fetch_sub_explicit(&b->refcount, 1, memory_order_acq_rel) == 1) {
>          b->free(b->opaque, b->data);
>          av_freep(&b);
>      }
> @@ -281,7 +281,7 @@ void av_buffer_pool_uninit(AVBufferPool **ppool)
>      pool   = *ppool;
>      *ppool = NULL;
>  
> -    if (atomic_fetch_add_explicit(&pool->refcount, -1, memory_order_acq_rel) == 1)
> +    if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1)
>          buffer_pool_free(pool);
>  }
>  
> @@ -298,7 +298,7 @@ static void pool_release_buffer(void *opaque, uint8_t *data)
>      pool->pool = buf;
>      ff_mutex_unlock(&pool->mutex);
>  
> -    if (atomic_fetch_add_explicit(&pool->refcount, -1, memory_order_acq_rel) == 1)
> +    if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1)
>          buffer_pool_free(pool);
>  }

Applied, thanks.
diff mbox

Patch

diff --git a/libavutil/buffer.c b/libavutil/buffer.c
index 8d1aa5fa84..f0034b026a 100644
--- a/libavutil/buffer.c
+++ b/libavutil/buffer.c
@@ -116,7 +116,7 @@  static void buffer_replace(AVBufferRef **dst, AVBufferRef **src)
     } else
         av_freep(dst);
 
-    if (atomic_fetch_add_explicit(&b->refcount, -1, memory_order_acq_rel) == 1) {
+    if (atomic_fetch_sub_explicit(&b->refcount, 1, memory_order_acq_rel) == 1) {
         b->free(b->opaque, b->data);
         av_freep(&b);
     }
@@ -281,7 +281,7 @@  void av_buffer_pool_uninit(AVBufferPool **ppool)
     pool   = *ppool;
     *ppool = NULL;
 
-    if (atomic_fetch_add_explicit(&pool->refcount, -1, memory_order_acq_rel) == 1)
+    if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1)
         buffer_pool_free(pool);
 }
 
@@ -298,7 +298,7 @@  static void pool_release_buffer(void *opaque, uint8_t *data)
     pool->pool = buf;
     ff_mutex_unlock(&pool->mutex);
 
-    if (atomic_fetch_add_explicit(&pool->refcount, -1, memory_order_acq_rel) == 1)
+    if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1)
         buffer_pool_free(pool);
 }