• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2019, The Linux Foundation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *    * Redistributions of source code must retain the above copyright
8  *      notice, this list of conditions and the following disclaimer.
9  *    * Redistributions in binary form must reproduce the above
10  *      copyright notice, this list of conditions and the following
11  *      disclaimer in the documentation and/or other materials provided
12  *      with the distribution.
13  *    * Neither the name of The Linux Foundation nor the names of its
14  *      contributors may be used to endorse or promote products derived
15  *      from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef AEEATOMIC_H
31 #define AEEATOMIC_H
32 /*
33 =======================================================================
34 
35 FILE:         AEEatomic.h
36 
37 SERVICES:     atomic
38 
39 DESCRIPTION:  Fast Atomic ops
40 
41 =======================================================================
42 */
43 
44 #include "AEEStdDef.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif /* #ifdef __cplusplus */
49 
50 uint32 atomic_Add(uint32 * volatile puDest, int nAdd);
51 uint32 atomic_Exchange(uint32 * volatile puDest, uint32 uVal);
52 uint32 atomic_CompareAndExchange(uint32 * volatile puDest, uint32 uExchange, uint32 uCompare);
53 uint32 atomic_CompareOrAdd(uint32 * volatile puDest, uint32 uCompare, int nAdd);
54 
55 uint64 atomic_CompareAndExchange64(uint64 * volatile puDest, uint64 uExchange, uint64 uCompare);
56 uintptr_t atomic_CompareAndExchangeUP(uintptr_t * volatile puDest, uintptr_t uExchange, uintptr_t uCompare);
57 #ifdef __cplusplus
58 }
59 #endif /* #ifdef __cplusplus */
60 
61 /*=====================================================================
62 INTERFACE DOCUMENTATION
63 =======================================================================
64 atomic Interface
65 
66   The atomic interface provides fast "atomic" operations.  The
67    operations are defined to be atomic with respect to each other.
68 
69 =======================================================================
70 
71 =======================================================================
72 
73 atomic_Add()
74 
75 Description:
76 
77    Performs an atomic sum operation.
78 
79 Prototype:
80 
81    uint32 atomic_Add(uint32* puDest, int nInc);
82 
83 Parameters:
84    puDest [in|out] : Points to unsigned number to add nInc and save
85    nInc : increment
86 
87 Return Value:
88    result.
89 
90 Comments:
91    None
92 
93 Side Effects:
94    None
95 
96 See Also:
97    None
98 
99 =======================================================================
100 
101 atomic_Exchange()
102 
103 Description:
104 
105    Atomic exchange of 32bit value. Performs an atomic operation of :
106       write uVal to *puDest
107       return the previous value in *puDest
108 
109 Prototype:
110 
111    uint32 atomic_Exchange(uint32* puDest, uint32 uVal);
112 
113 Parameters:
114    puDest [in|out] : Points to unsigned number to be exchanged
115    uVal : new value to write.
116 
117 Return Value:
118    previous value at *puDest.
119 
120 Comments:
121    None
122 
123 Side Effects:
124    May cause exception if puDest is not a 32 bit aligned address.
125 
126 See Also:
127    None
128 =======================================================================
129 
130 atomic_CompareAndExchange()
131 
132 Description:
133 
134    Performs an atomic operation of :
135       if (*puDest == uCompare) {
136          *puDest = uExchange;
137       }
138 
139    returns the previous value in *puDest
140 
141 Prototype:
142 
143    uint32 atomic_CompareAndExchange(uint32 *puDest, uint32 uExchange,
144                                     uint32 uCompare);
145 
146 Parameters:
147    puDest [in|out] : Points to unsigned number.
148    uExchange : A new value to write to *puDest
149    uCompare : Comparand
150 
151 Return Value:
152    previous value at *puDest.
153 
154 Comments:
155    None
156 
157 Side Effects:
158    May cause exception if puDest is not a 32 bit aligned address.
159 
160 See Also:
161    None
162 
163 =======================================================================
164 atomic_CompareOrAdd()
165 
166 Description:
167 
168    Performs an atomic operation of :
169       if (*puDest != uCompare) {
170          *puDest += nAdd;
171       }
172 
173    returns the new value in *puDest
174 
175 Prototype:
176 
177    uint32 atomic_CompareOrAdd(uint32 *puDest, uint32 uCompare, int nAdd);
178 
179 Parameters:
180    puDest [in|out] : Points to unsigned number.
181    uCompare : Comparand
182    nAdd : Add to *puDest
183 
184 Return Value:
185    new value at *puDest.
186 
187 Comments:
188    None
189 
190 Side Effects:
191    May cause exception if puDest is not a 32 bit aligned address.
192 
193 See Also:
194    None
195 =======================================================================*/
196 
197 #endif /* #ifndef AEEATOMIC_H */
198 
199