Debian Codegraph @

interfaces/cc/gcc/arm64/atomic.h

raw
1 /*===========================================================================
2 *
3 * PUBLIC DOMAIN NOTICE
4 * National Center for Biotechnology Information
5 *
6 * This software/database is a "United States Government Work" under the
7 * terms of the United States Copyright Act. It was written as part of
8 * the author's official duties as a United States Government employee and
9 * thus cannot be copyrighted. This software/database is freely available
10 * to the public for use. The National Library of Medicine and the U.S.
11 * Government have not placed any restriction on its use or reproduction.
12 *
13 * Although all reasonable efforts have been taken to ensure the accuracy
14 * and reliability of the software and data, the NLM and the U.S.
15 * Government do not and cannot warrant the performance or results that
16 * may be obtained by using this software or data. The NLM and the U.S.
17 * Government disclaim all warranties, express or implied, including
18 * warranties of performance, merchantability or fitness for any particular
19 * purpose.
20 *
21 * Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26
27 #ifndef _h_atomic_
28 #define _h_atomic_
29
30 #ifndef _h_atomic32_
31 #include "atomic32.h"
32 #endif
33
34 #ifndef _h_atomic64_
35 #include "atomic64.h"
36 #endif
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 #if DFLT_ATOMIC_BITS == 32
43 #define ATOMIC_NAME( suffix ) \
44 atomic32_ ## suffix
45 typedef int atomic_int;
46 #else
47 #define ATOMIC_NAME( suffix ) \
48 atomic64_ ## suffix
49 typedef long int atomic_int;
50 #endif
51
52 typedef struct ATOMIC_NAME ( t ) atomic_t;
53
54 typedef struct atomic_ptr_t atomic_ptr_t;
55 struct atomic_ptr_t
56 {
57 void * volatile ptr;
58 };
59
60 /* ( * v ) */
61 #define atomic_read( v ) \
62 ATOMIC_NAME ( read ) ( v )
63
64 /* ( * v ) = i */
65 #define atomic_set( v, i ) \
66 ATOMIC_NAME ( set ) ( v, i )
67
68 /* prior = ( * v ), ( * v ) += i, prior */
69 #define atomic_read_and_add( v, i ) \
70 ATOMIC_NAME ( read_and_add ) ( v, i )
71
72 /* ( * v ) += i */
73 #define atomic_add( v, i ) \
74 ATOMIC_NAME ( add ) ( v, i )
75
76 /* ( * v ) += i */
77 #define atomic_add_and_read( v, i ) \
78 ATOMIC_NAME ( add_and_read ) ( v, i )
79
80 /* ( void ) ++ ( * v ) */
81 #define atomic_inc( v ) \
82 ATOMIC_NAME ( inc ) ( v )
83
84 /* ( void ) -- ( * v ) */
85 #define atomic_dec( v ) \
86 ATOMIC_NAME ( dec ) ( v )
87
88 /* -- ( * v ) == 0 */
89 #define atomic_dec_and_test( v ) \
90 ATOMIC_NAME ( dec_and_test ) ( v )
91
92 /* ++ ( * v ) == 0
93 when atomic_dec_and_test uses predecrement, you want
94 postincrement to this function. so it isn't very useful */
95 #define atomic_inc_and_test( v ) \
96 ATOMIC_NAME ( inc_and_test ) ( v )
97
98 /* ( * v ) -- == 0
99 HERE's useful */
100 #define atomic_test_and_inc( v ) \
101 ATOMIC_NAME ( test_and_inc ) ( v )
102
103 /* prior = ( * v ), ( * v ) = ( prior == t ? s : prior ), prior */
104 #define atomic_test_and_set( v, s, t ) \
105 ATOMIC_NAME ( test_and_set ) ( v, s, t )
106
107 /* N.B. - THESE FUNCTIONS ARE FOR 64 BIT PTRS ONLY */
108
109 /* int atomic_read_ptr ( const atomic_ptr_t *v ); */
110 #define atomic_read_ptr( v ) \
111 ( ( v ) -> ptr )
112
113 static __inline__
114 void *atomic_test_and_set_ptr ( atomic_ptr_t *v, void *s, void *t )
115 {
116 void *rtn = v -> ptr;
117 if ( rtn == t )
118 v -> ptr = s;
119 return rtn;
120 }
121
122 /* val = ( * v ), ( ( * v ) = ( val < t ) ? val + i : val ), val */
123 #define atomic_read_and_add_lt( v, i, t ) \
124 ATOMIC_NAME ( read_and_add_lt ) ( v, i, t )
125
126 /* val = ( * v ), ( ( * v ) = ( val <= t ) ? val + i : val ), val */
127 #define atomic_read_and_add_le( v, i, t ) \
128 ATOMIC_NAME ( read_and_add_le ) ( v, i, t )
129
130 /* val = ( * v ), ( ( * v ) = ( val == t ) ? val + i : val ), val */
131 #define atomic_read_and_add_eq( v, i, t ) \
132 ATOMIC_NAME ( read_and_add_eq ) ( v, i, t )
133
134 /* val = ( * v ), ( ( * v ) = ( val != t ) ? val + i : val ), val */
135 #define atomic_read_and_add_ne( v, i, t ) \
136 ATOMIC_NAME ( read_and_add_ne ) ( v, i, t )
137
138 /* val = ( * v ), ( ( * v ) = ( val >= t ) ? val + i : val ), val */
139 #define atomic_read_and_add_ge( v, i, t ) \
140 ATOMIC_NAME ( read_and_add_ge ) ( v, i, t )
141
142 /* val = ( * v ), ( ( * v ) = ( val > t ) ? val + i : val ), val */
143 #define atomic_read_and_add_gt( v, i, t ) \
144 ATOMIC_NAME ( read_and_add_gt ) ( v, i, t )
145
146 /* val = ( * v ), ( ( * v ) = ( ( val & 1 ) == 1 ) ? val + i : val ), val */
147 #define atomic_read_and_add_odd( v, i ) \
148 ATOMIC_NAME ( read_and_add_odd ) ( v, i )
149
150 /* val = ( * v ), ( ( * v ) = ( ( val & 1 ) == 0 ) ? val + i : val ), val */
151 #define atomic_read_and_add_even( v, i ) \
152 ATOMIC_NAME ( read_and_add_even ) ( v, i )
153
154 /* DEPRECATED */
155
156 /* val = ( * v ), ( * v ) = ( val < t ? val + i : val ), ( val < t ? 1 : 0 ) */
157 #define atomic_add_if_lt( v, i, t ) \
158 ATOMIC_NAME ( add_if_lt ) ( v, i, t )
159
160 /* val = ( * v ), ( * v ) = ( val <= t ? val + i : val ), ( val <= t ? 1 : 0 ) */
161 #define atomic_add_if_le( v, i, t ) \
162 ATOMIC_NAME ( add_if_le ) ( v, i, t )
163
164 /* val = ( * v ), ( * v ) = ( val == t ? val + i : val ), ( val == t ? 1 : 0 ) */
165 #define atomic_add_if_eq( v, i, t ) \
166 ATOMIC_NAME ( add_if_eq ) ( v, i, t )
167
168 /* val = ( * v ), ( * v ) = ( val >= t ? val + i : val ), ( val >= t ? 1 : 0 ) */
169 #define atomic_add_if_ge( v, i, t ) \
170 ATOMIC_NAME ( add_if_ge ) ( v, i, t )
171
172 /* val = ( * v ), ( * v ) = ( val > t ? val + i : val ), ( val > t ? 1 : 0 ) */
173 #define atomic_add_if_gt( v, i, t ) \
174 ATOMIC_NAME ( add_if_gt ) ( v, i, t )
175
176 #undef LOCK
177
178
179 #ifdef __cplusplus
180 }
181 #endif
182
183 #endif /* _h_atomic_ */