Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
175 lines (144 loc) · 3.5 KB

SDL_atomic.c

File metadata and controls

175 lines (144 loc) · 3.5 KB
 
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
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library 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 library 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 library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#ifdef SDL_ATOMIC_LINUX
#include "SDL.h"
#include "SDL_config.h"
#include "SDL_atomic.h"
Uint32
SDL_AtomicExchange32(Uint32 * ptr, Uint32 value)
{
Jun 24, 2009
Jun 24, 2009
32
return __sync_lock_test_and_set(ptr, value);
33
34
35
36
37
}
SDL_bool
SDL_AtomicCompareThenSet32(Uint32 * ptr, Uint32 oldvalue, Uint32 newvalue)
{
Jun 24, 2009
Jun 24, 2009
38
return (SDL_bool)__sync_bool_compare_and_swap(ptr, oldvalue, newvalue);
39
40
41
42
43
}
SDL_bool
SDL_AtomicTestThenSet32(Uint32 * ptr)
{
Jun 24, 2009
Jun 24, 2009
44
return (SDL_bool)(0 == __sync_lock_test_and_set(ptr, 1));
45
46
47
48
49
}
void
SDL_AtomicClear32(Uint32 * ptr)
{
Jun 24, 2009
Jun 24, 2009
50
__sync_lock_release(ptr);
51
52
53
54
55
}
Uint32
SDL_AtomicFetchThenIncrement32(Uint32 * ptr)
{
Jun 24, 2009
Jun 24, 2009
56
return __sync_fetch_and_add(ptr, 1);
57
58
59
60
61
}
Uint32
SDL_AtomicFetchThenDecrement32(Uint32 * ptr)
{
Jun 24, 2009
Jun 24, 2009
62
return __sync_fetch_and_sub(ptr, 1);
63
64
65
66
67
}
Uint32
SDL_AtomicFetchThenAdd32(Uint32 * ptr, Uint32 value)
{
Jun 24, 2009
Jun 24, 2009
68
return __sync_fetch_and_add(ptr, value);
69
70
71
72
73
}
Uint32
SDL_AtomicFetchThenSubtract32(Uint32 * ptr, Uint32 value)
{
Jun 24, 2009
Jun 24, 2009
74
return __sync_fetch_and_sub(ptr, value);
75
76
77
78
79
}
Uint32
SDL_AtomicIncrementThenFetch32(Uint32 * ptr)
{
Jun 24, 2009
Jun 24, 2009
80
return __sync_add_and_fetch(ptr, 1);
81
82
83
84
85
}
Uint32
SDL_AtomicDecrementThenFetch32(Uint32 * ptr)
{
Jun 24, 2009
Jun 24, 2009
86
return __sync_sub_and_fetch(ptr, 1);
87
88
89
90
91
}
Uint32
SDL_AtomicAddThenFetch32(Uint32 * ptr, Uint32 value)
{
Jun 24, 2009
Jun 24, 2009
92
return __sync_add_and_fetch(ptr, value);
93
94
95
96
97
}
Uint32
SDL_AtomicSubtractThenFetch32(Uint32 * ptr, Uint32 value)
{
Jun 24, 2009
Jun 24, 2009
98
return __sync_sub_and_fetch(ptr, value);
99
100
101
102
103
104
105
}
#ifdef SDL_HAS_64BIT_TYPE
Uint64
SDL_AtomicExchange64(Uint64 * ptr, Uint64 value)
{
Jun 24, 2009
Jun 24, 2009
106
return __sync_lock_test_and_set(ptr, value);
Jun 24, 2009
Jun 24, 2009
110
SDL_AtomicCompareThenSet64(Uint64 * ptr, Uint64 oldvalue, Uint64 newvalue)
Jun 24, 2009
Jun 24, 2009
112
return (SDL_bool)__sync_bool_compare_and_swap(ptr, oldvalue, newvalue);
113
114
115
116
117
}
SDL_bool
SDL_AtomicTestThenSet64(Uint64 * ptr)
{
Jun 24, 2009
Jun 24, 2009
118
return (SDL_bool)(0 == __sync_lock_test_and_set(ptr, 1));
119
120
121
122
123
}
void
SDL_AtomicClear64(Uint64 * ptr)
{
Jun 24, 2009
Jun 24, 2009
124
__sync_lock_release(ptr);
125
126
127
128
129
}
Uint64
SDL_AtomicFetchThenIncrement64(Uint64 * ptr)
{
Jun 24, 2009
Jun 24, 2009
130
return __sync_fetch_and_add(ptr, 1);
131
132
133
134
135
}
Uint64
SDL_AtomicFetchThenDecrement64(Uint64 * ptr)
{
Jun 24, 2009
Jun 24, 2009
136
return __sync_fetch_and_sub(ptr, 1);
137
138
139
140
141
}
Uint64
SDL_AtomicFetchThenAdd64(Uint64 * ptr, Uint64 value)
{
Jun 24, 2009
Jun 24, 2009
142
return __sync_fetch_and_add(ptr, value);
143
144
145
146
147
}
Uint64
SDL_AtomicFetchThenSubtract64(Uint64 * ptr, Uint64 value)
{
Jun 24, 2009
Jun 24, 2009
148
return __sync_fetch_and_sub(ptr, value);
149
150
151
152
153
}
Uint64
SDL_AtomicIncrementThenFetch64(Uint64 * ptr)
{
Jun 24, 2009
Jun 24, 2009
154
return __sync_add_and_fetch(ptr, 1);
155
156
157
158
159
}
Uint64
SDL_AtomicDecrementThenFetch64(Uint64 * ptr)
{
Jun 24, 2009
Jun 24, 2009
160
return __sync_sub_and_fetch(ptr, 1);
161
162
163
164
165
}
Uint64
SDL_AtomicAddThenFetch64(Uint64 * ptr, Uint64 value)
{
Jun 24, 2009
Jun 24, 2009
166
return __sync_add_and_fetch(ptr, value);
167
168
169
170
171
}
Uint64
SDL_AtomicSubtractThenFetch64(Uint64 * ptr, Uint64 value)
{
Jun 24, 2009
Jun 24, 2009
172
return __sync_sub_and_fetch(ptr, value);