Debian Codegraph @

interfaces/cc/gcc/i386/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 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 typedef int atomic_int;
39 typedef struct atomic32_t atomic_t;
40
41 typedef struct atomic_ptr_t atomic_ptr_t;
42 struct atomic_ptr_t
43 {
44 void * volatile ptr;
45 };
46
47 /* ( * v ) */
48 #define atomic_read( v ) \
49 atomic32_read ( v )
50
51 /* ( * v ) = i */
52 #define atomic_set( v, i ) \
53 atomic32_set ( v, i )
54
55 /* prior = ( * v ), ( * v ) += i, prior */
56 #define atomic_read_and_add( v, i ) \
57 atomic32_read_and_add ( v, i )
58
59 /* ( * v ) += i */
60 #define atomic_add( v, i ) \
61 atomic32_add ( v, i )
62
63 /* ( * v ) += i */
64 #define atomic_add_and_read( v, i ) \
65 atomic32_add_and_read ( v, i )
66
67 /* ( void ) ++ ( * v ) */
68 #define atomic_inc( v ) \
69 atomic32_inc ( v )
70
71 /* ( void ) -- ( * v ) */
72 #define atomic_dec( v ) \
73 atomic32_dec ( v )
74
75 /* -- ( * v ) == 0 */
76 #define atomic_dec_and_test( v ) \
77 atomic32_dec_and_test ( v )
78
79 /* ++ ( * v ) == 0
80 when atomic_dec_and_test uses predecrement, you want
81 postincrement to this function. so it isn't very useful */
82 #define atomic_inc_and_test( v ) \
83 atomic32_inc_and_test ( v )
84
85 /* ( * v ) -- == 0
86 HERE's useful */
87 #define atomic_test_and_inc( v ) \
88 atomic32_test_and_inc ( v )
89
90 /* prior = ( * v ), ( * v ) = ( prior == t ? s : prior ), prior */
91 #define atomic_test_and_set( v, s, t ) \
92 atomic32_test_and_set ( v, s, t )
93
94 /* N.B. - THESE FUNCTIONS ARE FOR 32 BIT PTRS ONLY */
95
96 /* int atomic_read_ptr ( const atomic_ptr_t *v ); */
97 #define atomic_read_ptr( v ) \
98 ( ( v ) -> ptr )
99
100 static __inline__
101 void *atomic_test_and_set_ptr ( atomic_ptr_t *v, void *s, void *t )
102 {
103 void *rtn;
104 __asm__ __volatile__
105 (
106 "lock;"
107 "cmpxchg %%edx,(%%ecx)"
108 : "=a" ( rtn ), "=c" ( v )
109 : "c" ( v ), "d" ( s ), "a" ( t )
110 );
111 return rtn;
112 }
113
114 /* val = ( * v ), ( ( * v ) = ( val < t ) ? val + i : val ), val */
115 #define atomic_read_and_add_lt( v, i, t ) \
116 atomic32_read_and_add_lt ( v, i, t )
117
118 /* val = ( * v ), ( ( * v ) = ( val <= t ) ? val + i : val ), val */
119 #define atomic_read_and_add_le( v, i, t ) \
120 atomic32_read_and_add_le ( v, i, t )
121
122 /* val = ( * v ), ( ( * v ) = ( val == t ) ? val + i : val ), val */
123 #define atomic_read_and_add_eq( v, i, t ) \
124 atomic32_read_and_add_eq ( v, i, t )
125
126 /* val = ( * v ), ( ( * v ) = ( val != t ) ? val + i : val ), val */
127 #define atomic_read_and_add_ne( v, i, t ) \
128 atomic32_read_and_add_ne ( v, i, t )
129
130 /* val = ( * v ), ( ( * v ) = ( val >= t ) ? val + i : val ), val */
131 #define atomic_read_and_add_ge( v, i, t ) \
132 atomic32_read_and_add_ge ( v, i, t )
133
134 /* val = ( * v ), ( ( * v ) = ( val > t ) ? val + i : val ), val */
135 #define atomic_read_and_add_gt( v, i, t ) \
136 atomic32_read_and_add_gt ( v, i, t )
137
138 /* val = ( * v ), ( ( * v ) = ( ( val & 1 ) == 1 ) ? val + i : val ), val */
139 #define atomic_read_and_add_odd( v, i ) \
140 atomic32_read_and_add_odd ( v, i )
141
142 /* val = ( * v ), ( ( * v ) = ( ( val & 1 ) == 0 ) ? val + i : val ), val */
143 #define atomic_read_and_add_even( v, i ) \
144 atomic32_read_and_add_even ( v, i )
145
146 /* DEPRECATED */
147
148 /* val = ( * v ), ( * v ) = ( val < t ? val + i : val ), ( val < t ? 1 : 0 ) */
149 #define atomic_add_if_lt( v, i, t ) \
150 atomic32_add_if_lt ( v, i, t )
151
152 /* val = ( * v ), ( * v ) = ( val <= t ? val + i : val ), ( val <= t ? 1 : 0 ) */
153 #define atomic_add_if_le( v, i, t ) \
154 atomic32_add_if_le ( v, i, t )
155
156 /* val = ( * v ), ( * v ) = ( val == t ? val + i : val ), ( val == t ? 1 : 0 ) */
157 #define atomic_add_if_eq( v, i, t ) \
158 atomic32_add_if_eq ( v, i, t )
159
160 /* val = ( * v ), ( * v ) = ( val >= t ? val + i : val ), ( val >= t ? 1 : 0 ) */
161 #define atomic_add_if_ge( v, i, t ) \
162 atomic32_add_if_ge ( v, i, t )
163
164 /* val = ( * v ), ( * v ) = ( val > t ? val + i : val ), ( val > t ? 1 : 0 ) */
165 #define atomic_add_if_gt( v, i, t ) \
166 atomic32_add_if_gt ( v, i, t )
167
168 #undef LOCK
169
170 #ifdef __cplusplus
171 }
172 #endif
173
174 #endif /* _h_atomic_ */