Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
27079a42
Commit
27079a42
authored
Jul 17, 2016
by
Anton Khirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
buffer: convert to stdatomic
parent
eb34d403
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
12 deletions
+14
-12
buffer.c
libavutil/buffer.c
+11
-10
buffer_internal.h
libavutil/buffer_internal.h
+3
-2
No files found.
libavutil/buffer.c
View file @
27079a42
...
@@ -16,10 +16,10 @@
...
@@ -16,10 +16,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
#include <stdatomic.h>
#include <stdint.h>
#include <stdint.h>
#include <string.h>
#include <string.h>
#include "atomic.h"
#include "buffer_internal.h"
#include "buffer_internal.h"
#include "common.h"
#include "common.h"
#include "mem.h"
#include "mem.h"
...
@@ -40,7 +40,8 @@ AVBufferRef *av_buffer_create(uint8_t *data, int size,
...
@@ -40,7 +40,8 @@ AVBufferRef *av_buffer_create(uint8_t *data, int size,
buf
->
size
=
size
;
buf
->
size
=
size
;
buf
->
free
=
free
?
free
:
av_buffer_default_free
;
buf
->
free
=
free
?
free
:
av_buffer_default_free
;
buf
->
opaque
=
opaque
;
buf
->
opaque
=
opaque
;
buf
->
refcount
=
1
;
atomic_init
(
&
buf
->
refcount
,
1
);
if
(
flags
&
AV_BUFFER_FLAG_READONLY
)
if
(
flags
&
AV_BUFFER_FLAG_READONLY
)
buf
->
flags
|=
BUFFER_FLAG_READONLY
;
buf
->
flags
|=
BUFFER_FLAG_READONLY
;
...
@@ -98,7 +99,7 @@ AVBufferRef *av_buffer_ref(AVBufferRef *buf)
...
@@ -98,7 +99,7 @@ AVBufferRef *av_buffer_ref(AVBufferRef *buf)
*
ret
=
*
buf
;
*
ret
=
*
buf
;
a
vpriv_atomic_int_add_and_fetch
(
&
buf
->
buffer
->
refcount
,
1
);
a
tomic_fetch_add_explicit
(
&
buf
->
buffer
->
refcount
,
1
,
memory_order_relaxed
);
return
ret
;
return
ret
;
}
}
...
@@ -112,7 +113,7 @@ void av_buffer_unref(AVBufferRef **buf)
...
@@ -112,7 +113,7 @@ void av_buffer_unref(AVBufferRef **buf)
b
=
(
*
buf
)
->
buffer
;
b
=
(
*
buf
)
->
buffer
;
av_freep
(
buf
);
av_freep
(
buf
);
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
);
b
->
free
(
b
->
opaque
,
b
->
data
);
av_freep
(
&
b
);
av_freep
(
&
b
);
}
}
...
@@ -123,7 +124,7 @@ int av_buffer_is_writable(const AVBufferRef *buf)
...
@@ -123,7 +124,7 @@ int av_buffer_is_writable(const AVBufferRef *buf)
if
(
buf
->
buffer
->
flags
&
AV_BUFFER_FLAG_READONLY
)
if
(
buf
->
buffer
->
flags
&
AV_BUFFER_FLAG_READONLY
)
return
0
;
return
0
;
return
a
vpriv_atomic_int_add_and_fetch
(
&
buf
->
buffer
->
refcount
,
0
)
==
1
;
return
a
tomic_load
(
&
buf
->
buffer
->
refcount
)
==
1
;
}
}
int
av_buffer_make_writable
(
AVBufferRef
**
pbuf
)
int
av_buffer_make_writable
(
AVBufferRef
**
pbuf
)
...
@@ -209,7 +210,7 @@ AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
...
@@ -209,7 +210,7 @@ AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
pool
->
alloc2
=
alloc
;
pool
->
alloc2
=
alloc
;
pool
->
pool_free
=
pool_free
;
pool
->
pool_free
=
pool_free
;
a
vpriv_atomic_int_se
t
(
&
pool
->
refcount
,
1
);
a
tomic_ini
t
(
&
pool
->
refcount
,
1
);
return
pool
;
return
pool
;
}
}
...
@@ -225,7 +226,7 @@ AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size))
...
@@ -225,7 +226,7 @@ AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size))
pool
->
size
=
size
;
pool
->
size
=
size
;
pool
->
alloc
=
alloc
?
alloc
:
av_buffer_alloc
;
pool
->
alloc
=
alloc
?
alloc
:
av_buffer_alloc
;
a
vpriv_atomic_int_se
t
(
&
pool
->
refcount
,
1
);
a
tomic_ini
t
(
&
pool
->
refcount
,
1
);
return
pool
;
return
pool
;
}
}
...
@@ -260,7 +261,7 @@ void av_buffer_pool_uninit(AVBufferPool **ppool)
...
@@ -260,7 +261,7 @@ void av_buffer_pool_uninit(AVBufferPool **ppool)
pool
=
*
ppool
;
pool
=
*
ppool
;
*
ppool
=
NULL
;
*
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
);
buffer_pool_free
(
pool
);
}
}
...
@@ -274,7 +275,7 @@ static void pool_release_buffer(void *opaque, uint8_t *data)
...
@@ -274,7 +275,7 @@ static void pool_release_buffer(void *opaque, uint8_t *data)
pool
->
pool
=
buf
;
pool
->
pool
=
buf
;
ff_mutex_unlock
(
&
pool
->
mutex
);
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
);
buffer_pool_free
(
pool
);
}
}
...
@@ -327,7 +328,7 @@ AVBufferRef *av_buffer_pool_get(AVBufferPool *pool)
...
@@ -327,7 +328,7 @@ AVBufferRef *av_buffer_pool_get(AVBufferPool *pool)
ff_mutex_unlock
(
&
pool
->
mutex
);
ff_mutex_unlock
(
&
pool
->
mutex
);
if
(
ret
)
if
(
ret
)
a
vpriv_atomic_int_add_and_fetch
(
&
pool
->
refcount
,
1
);
a
tomic_fetch_add_explicit
(
&
pool
->
refcount
,
1
,
memory_order_relaxed
);
return
ret
;
return
ret
;
}
}
libavutil/buffer_internal.h
View file @
27079a42
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#ifndef AVUTIL_BUFFER_INTERNAL_H
#ifndef AVUTIL_BUFFER_INTERNAL_H
#define AVUTIL_BUFFER_INTERNAL_H
#define AVUTIL_BUFFER_INTERNAL_H
#include <stdatomic.h>
#include <stdint.h>
#include <stdint.h>
#include "buffer.h"
#include "buffer.h"
...
@@ -40,7 +41,7 @@ struct AVBuffer {
...
@@ -40,7 +41,7 @@ struct AVBuffer {
/**
/**
* number of existing AVBufferRef instances referring to this buffer
* number of existing AVBufferRef instances referring to this buffer
*/
*/
volatile
int
refcount
;
atomic_u
int
refcount
;
/**
/**
* a callback for freeing the data
* a callback for freeing the data
...
@@ -85,7 +86,7 @@ struct AVBufferPool {
...
@@ -85,7 +86,7 @@ struct AVBufferPool {
* buffers have been released, then it's safe to free the pool and all
* buffers have been released, then it's safe to free the pool and all
* the buffers in it.
* the buffers in it.
*/
*/
volatile
int
refcount
;
atomic_u
int
refcount
;
int
size
;
int
size
;
void
*
opaque
;
void
*
opaque
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment