]> git.sesse.net Git - vlc/blob - src/win32/atomic.c
LGPL
[vlc] / src / win32 / atomic.c
1 /*****************************************************************************
2  * atomic.c:
3  *****************************************************************************
4  * Copyright (C) 2010 RĂ©mi Denis-Courmont
5  *
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.
10  *
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.
15  *
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  *****************************************************************************/
20
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include <vlc_common.h>
26 #include <vlc_atomic.h>
27
28 #include <windows.h>
29
30 uintptr_t vlc_atomic_get (const vlc_atomic_t *atom)
31 {
32     return atom->u;
33 }
34
35 uintptr_t vlc_atomic_set (vlc_atomic_t *atom, uintptr_t v)
36 {
37 #if defined (WIN64)
38     InterlockedExchange64 (&atom->u, v);
39 #else
40     InterlockedExchange (&atom->u, v);
41 #endif
42     return v;
43 }
44
45 uintptr_t vlc_atomic_add (vlc_atomic_t *atom, uintptr_t v)
46 {
47 #if defined (WIN64)
48     return InterlockedExchangeAdd64 (&atom->s, v) + v;
49 #else
50     return InterlockedExchangeAdd (&atom->s, v) + v;
51 #endif
52 }
53
54 uintptr_t vlc_atomic_swap (vlc_atomic_t *atom, uintptr_t v)
55 {
56 #if defined (WIN64)
57     return InterlockedExchange64 (&atom->s, v);
58 #else
59     return InterlockedExchange (&atom->s, v);
60 #endif
61 }
62
63 uintptr_t vlc_atomic_compare_swap (vlc_atomic_t *atom,
64                                    uintptr_t oldval, uintptr_t newval)
65 {
66 #if defined (WIN64)
67     return InterlockedCompareExchange64 (&atom->s, newval, oldval);
68 #else
69     return InterlockedCompareExchange (&atom->s, newval, oldval);
70 #endif
71 }