yading@11
|
1 /*
|
yading@11
|
2 * Copyright (c) 2012 Ronald S. Bultje <rsbultje@gmail.com>
|
yading@11
|
3 *
|
yading@11
|
4 * This file is part of FFmpeg.
|
yading@11
|
5 *
|
yading@11
|
6 * FFmpeg is free software; you can redistribute it and/or
|
yading@11
|
7 * modify it under the terms of the GNU Lesser General Public
|
yading@11
|
8 * License as published by the Free Software Foundation; either
|
yading@11
|
9 * version 2.1 of the License, or (at your option) any later version.
|
yading@11
|
10 *
|
yading@11
|
11 * FFmpeg is distributed in the hope that it will be useful,
|
yading@11
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@11
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@11
|
14 * Lesser General Public License for more details.
|
yading@11
|
15 *
|
yading@11
|
16 * You should have received a copy of the GNU Lesser General Public
|
yading@11
|
17 * License along with FFmpeg; if not, write to the Free Software
|
yading@11
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@11
|
19 */
|
yading@11
|
20
|
yading@11
|
21 #ifndef AVUTIL_ATOMIC_H
|
yading@11
|
22 #define AVUTIL_ATOMIC_H
|
yading@11
|
23
|
yading@11
|
24 #include "config.h"
|
yading@11
|
25
|
yading@11
|
26 #if HAVE_ATOMICS_GCC
|
yading@11
|
27 #include "atomic_gcc.h"
|
yading@11
|
28 #elif HAVE_ATOMICS_WIN32
|
yading@11
|
29 #include "atomic_win32.h"
|
yading@11
|
30 #elif HAVE_ATOMICS_SUNCC
|
yading@11
|
31 #include "atomic_suncc.h"
|
yading@11
|
32 #else
|
yading@11
|
33
|
yading@11
|
34 /**
|
yading@11
|
35 * Load the current value stored in an atomic integer.
|
yading@11
|
36 *
|
yading@11
|
37 * @param ptr atomic integer
|
yading@11
|
38 * @return the current value of the atomic integer
|
yading@11
|
39 * @note This acts as a memory barrier.
|
yading@11
|
40 */
|
yading@11
|
41 int avpriv_atomic_int_get(volatile int *ptr);
|
yading@11
|
42
|
yading@11
|
43 /**
|
yading@11
|
44 * Store a new value in an atomic integer.
|
yading@11
|
45 *
|
yading@11
|
46 * @param ptr atomic integer
|
yading@11
|
47 * @param val the value to store in the atomic integer
|
yading@11
|
48 * @note This acts as a memory barrier.
|
yading@11
|
49 */
|
yading@11
|
50 void avpriv_atomic_int_set(volatile int *ptr, int val);
|
yading@11
|
51
|
yading@11
|
52 /**
|
yading@11
|
53 * Add a value to an atomic integer.
|
yading@11
|
54 *
|
yading@11
|
55 * @param ptr atomic integer
|
yading@11
|
56 * @param inc the value to add to the atomic integer (may be negative)
|
yading@11
|
57 * @return the new value of the atomic integer.
|
yading@11
|
58 * @note This does NOT act as a memory barrier. This is primarily
|
yading@11
|
59 * intended for reference counting.
|
yading@11
|
60 */
|
yading@11
|
61 int avpriv_atomic_int_add_and_fetch(volatile int *ptr, int inc);
|
yading@11
|
62
|
yading@11
|
63 /**
|
yading@11
|
64 * Atomic pointer compare and swap.
|
yading@11
|
65 *
|
yading@11
|
66 * @param ptr pointer to the pointer to operate on
|
yading@11
|
67 * @param oldval do the swap if the current value of *ptr equals to oldval
|
yading@11
|
68 * @param newval value to replace *ptr with
|
yading@11
|
69 * @return the value of *ptr before comparison
|
yading@11
|
70 */
|
yading@11
|
71 void *avpriv_atomic_ptr_cas(void * volatile *ptr, void *oldval, void *newval);
|
yading@11
|
72
|
yading@11
|
73 #endif /* HAVE_MEMORYBARRIER */
|
yading@11
|
74 #endif /* AVUTIL_ATOMIC_H */
|