1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2010 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
26 * Atomic operations do not require locking, but they are not very powerful.
29 /** Static initializer for \ref vlc_atomic_t */
30 # define VLC_ATOMIC_INIT(val) { (val) }
32 /* All functions return the atom value _after_ the operation. */
34 VLC_API
uintptr_t vlc_atomic_get(const vlc_atomic_t
*);
35 VLC_API
uintptr_t vlc_atomic_set(vlc_atomic_t
*, uintptr_t);
36 VLC_API
uintptr_t vlc_atomic_add(vlc_atomic_t
*, uintptr_t);
38 static inline uintptr_t vlc_atomic_sub (vlc_atomic_t
*atom
, uintptr_t v
)
40 return vlc_atomic_add (atom
, -v
);
43 static inline uintptr_t vlc_atomic_inc (vlc_atomic_t
*atom
)
45 return vlc_atomic_add (atom
, 1);
48 static inline uintptr_t vlc_atomic_dec (vlc_atomic_t
*atom
)
50 return vlc_atomic_sub (atom
, 1);
53 VLC_API
uintptr_t vlc_atomic_swap(vlc_atomic_t
*, uintptr_t);
54 VLC_API
uintptr_t vlc_atomic_compare_swap(vlc_atomic_t
*, uintptr_t, uintptr_t);
56 /** Helper to retrieve a single precision from an atom. */
57 static inline float vlc_atomic_getf(const vlc_atomic_t
*atom
)
59 union { float f
; uintptr_t i
; } u
;
60 u
.i
= vlc_atomic_get(atom
);
64 /** Helper to store a single precision into an atom. */
65 static inline float vlc_atomic_setf(vlc_atomic_t
*atom
, float f
)
67 union { float f
; uintptr_t i
; } u
;
69 vlc_atomic_set(atom
, u
.i
);