forked from videolan/vlc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvlc_atomic.h
60 lines (51 loc) · 1.86 KB
/
vlc_atomic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*****************************************************************************
* vlc_atomic.h:
*****************************************************************************
* Copyright (C) 2010 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef __cplusplus
# error Not implemented in C++.
#endif
#ifndef VLC_ATOMIC_H
# define VLC_ATOMIC_H
/**
* \file
* Atomic operations do not require locking, but they are not very powerful.
*/
# include <stdatomic.h>
typedef atomic_uint_least32_t vlc_atomic_float;
static inline void vlc_atomic_init_float(vlc_atomic_float *var, float f)
{
union { float f; uint32_t i; } u;
u.f = f;
atomic_init(var, u.i);
}
/** Helper to retrieve a single precision from an atom. */
static inline float vlc_atomic_load_float(vlc_atomic_float *atom)
{
union { float f; uint32_t i; } u;
u.i = atomic_load(atom);
return u.f;
}
/** Helper to store a single precision into an atom. */
static inline void vlc_atomic_store_float(vlc_atomic_float *atom, float f)
{
union { float f; uint32_t i; } u;
u.f = f;
atomic_store(atom, u.i);
}
#endif