Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXAtomic.h
1 /********************************************************************************
2 * *
3 * A t o m i c O p e r a t i o n s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2006,2017 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXATOMIC_H
22 #define FXATOMIC_H
23 
24 
25 namespace FX {
26 
27 
32 extern FXAPI FXbool atomicsAvailable();
33 
34 
36 
42 extern FXAPI void atomicThreadFence();
43 
44 
46 
48 extern FXAPI FXint atomicRead(volatile FXint* ptr);
49 
51 extern FXAPI void atomicWrite(volatile FXint* ptr,FXint v);
52 
54 extern FXAPI FXint atomicSet(volatile FXint* ptr,FXint v);
55 
57 extern FXAPI FXint atomicAdd(volatile FXint* ptr,FXint v);
58 
60 extern FXAPI FXint atomicCas(volatile FXint* ptr,FXint expect,FXint v);
61 
63 extern FXAPI FXbool atomicBoolCas(volatile FXint* ptr,FXint expect,FXint v);
64 
65 
67 
69 extern FXAPI FXuint atomicRead(volatile FXuint* ptr);
70 
72 extern FXAPI void atomicWrite(volatile FXuint* ptr,FXuint v);
73 
75 extern FXAPI FXuint atomicSet(volatile FXuint* ptr,FXuint v);
76 
78 extern FXAPI FXuint atomicAdd(volatile FXuint* ptr,FXuint v);
79 
81 extern FXAPI FXuint atomicCas(volatile FXuint* ptr,FXuint expect,FXuint v);
82 
84 extern FXAPI FXbool atomicBoolCas(volatile FXuint* ptr,FXuint expect,FXuint v);
85 
86 
88 
90 extern FXAPI FXlong atomicSet(volatile FXlong* ptr,FXlong v);
91 
93 extern FXAPI FXlong atomicAdd(volatile FXlong* ptr,FXlong v);
94 
96 extern FXAPI FXlong atomicCas(volatile FXlong* ptr,FXlong expect,FXlong v);
97 
99 extern FXAPI FXbool atomicBoolCas(volatile FXlong* ptr,FXlong expect,FXlong v);
100 
101 
103 
105 extern FXAPI FXulong atomicSet(volatile FXulong* ptr,FXulong v);
106 
108 extern FXAPI FXulong atomicAdd(volatile FXulong* ptr,FXulong v);
109 
111 extern FXAPI FXulong atomicCas(volatile FXulong* ptr,FXulong expect,FXulong v);
112 
114 extern FXAPI FXbool atomicBoolCas(volatile FXulong* ptr,FXulong expect,FXulong v);
115 
116 
118 
120 extern FXAPI FXptr atomicRead(volatile FXptr* ptr);
121 
123 extern FXAPI void atomicWrite(volatile FXptr* ptr,FXptr v);
124 
126 extern FXAPI FXptr atomicSet(volatile FXptr* ptr,FXptr v);
127 
129 extern FXAPI FXptr atomicAdd(volatile FXptr* ptr,FXival v);
130 
132 extern FXAPI FXptr atomicCas(volatile FXptr* ptr,FXptr expect,FXptr v);
133 
135 extern FXAPI FXbool atomicBoolCas(volatile FXptr* ptr,FXptr expect,FXptr v);
136 
138 extern FXAPI FXbool atomicBoolDCas(volatile FXptr* ptr,FXptr cmpa,FXptr cmpb,FXptr a,FXptr b);
139 
140 
142 
144 template <typename EType>
145 inline EType* atomicSet(EType *volatile *ptr,EType* v){
146  return (EType*)atomicSet((volatile FXptr*)ptr,(FXptr)v);
147  }
148 
149 
151 template <typename EType>
152 inline EType* atomicAdd(EType *volatile *ptr,FXival v){
153  return (EType*)atomicAdd((volatile FXptr*)ptr,v*((FXival)sizeof(EType)));
154  }
155 
156 
158 template <typename EType>
159 inline EType* atomicCas(EType *volatile *ptr,EType* expect,EType* v){
160  return (EType*)atomicCas((volatile FXptr*)ptr,(FXptr)expect,(FXptr)v);
161  }
162 
163 
165 template <typename EType>
166 inline FXbool atomicBoolCas(EType *volatile *ptr,EType* expect,EType* v){
167  return atomicBoolCas((volatile FXptr*)ptr,(FXptr)expect,(FXptr)v);
168  }
169 
170 
172 template <typename EType>
173 inline FXbool atomicBoolDCas(EType *volatile *ptr,EType* cmpa,EType* cmpb,EType* a,EType* b){
174  return atomicBoolDCas((volatile FXptr*)ptr,(FXptr)cmpa,(FXptr)cmpb,(FXptr)a,(FXptr)b);
175  }
176 
177 
178 }
179 
180 #endif

Copyright © 1997-2016 Jeroen van der Zijp