This is Unofficial EPICS BASE Doxygen Site
epicsAtomic.h
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2011 LANS LLC, as Operator of
3 * Los Alamos National Laboratory.
4 * Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
5 * National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 
10 /*
11  * Author Jeffrey O. Hill
12  * johill@lanl.gov
13  */
14 
15 #ifndef epicsAtomic_h
16 #define epicsAtomic_h
17 
18 #include <stdlib.h> /* define size_t */
19 
20 #include "compilerSpecific.h"
21 
22 #define EPICS_ATOMIC_INLINE static EPICS_ALWAYS_INLINE
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 typedef void * EpicsAtomicPtrT;
29 
30 /* load target into cache */
32 
33 /* push cache version of target into target */
35 
36 /*
37  * lock out other smp processors from accessing the target,
38  * load target into cache, add one to target, flush cache
39  * to target, allow other smp processors to access the target,
40  * return new value of target as modified by this operation
41  */
42 EPICS_ATOMIC_INLINE size_t epicsAtomicIncrSizeT ( size_t * pTarget );
43 EPICS_ATOMIC_INLINE int epicsAtomicIncrIntT ( int * pTarget );
44 
45 /*
46  * lock out other smp processors from accessing the target,
47  * load target into cache, subtract one from target, flush cache
48  * to target, allow out other smp processors to access the target,
49  * return new value of target as modified by this operation
50  */
51 EPICS_ATOMIC_INLINE size_t epicsAtomicDecrSizeT ( size_t * pTarget );
52 EPICS_ATOMIC_INLINE int epicsAtomicDecrIntT ( int * pTarget );
53 
54 /*
55  * lock out other smp processors from accessing the target,
56  * load target into cache, add/sub delta to/from target, flush cache
57  * to target, allow other smp processors to access the target,
58  * return new value of target as modified by this operation
59  */
60 EPICS_ATOMIC_INLINE size_t epicsAtomicAddSizeT ( size_t * pTarget, size_t delta );
61 EPICS_ATOMIC_INLINE size_t epicsAtomicSubSizeT ( size_t * pTarget, size_t delta );
62 EPICS_ATOMIC_INLINE int epicsAtomicAddIntT ( int * pTarget, int delta );
63 
64 /*
65  * set cache version of target, flush cache to target
66  */
67 EPICS_ATOMIC_INLINE void epicsAtomicSetSizeT ( size_t * pTarget, size_t newValue );
68 EPICS_ATOMIC_INLINE void epicsAtomicSetIntT ( int * pTarget, int newValue );
69 EPICS_ATOMIC_INLINE void epicsAtomicSetPtrT ( EpicsAtomicPtrT * pTarget, EpicsAtomicPtrT newValue );
70 
71 /*
72  * fetch target into cache, return new value of target
73  */
74 EPICS_ATOMIC_INLINE size_t epicsAtomicGetSizeT ( const size_t * pTarget );
75 EPICS_ATOMIC_INLINE int epicsAtomicGetIntT ( const int * pTarget );
76 EPICS_ATOMIC_INLINE EpicsAtomicPtrT epicsAtomicGetPtrT ( const EpicsAtomicPtrT * pTarget );
77 
78 /*
79  * lock out other smp processors from accessing the target,
80  * load target into cache, if target is equal to oldVal set target
81  * to newVal, flush cache to target, allow other smp processors
82  * to access the target, return the original value stored in the
83  * target
84  */
85 EPICS_ATOMIC_INLINE size_t epicsAtomicCmpAndSwapSizeT ( size_t * pTarget,
86  size_t oldVal, size_t newVal );
88  int oldVal, int newVal );
90  EpicsAtomicPtrT * pTarget,
91  EpicsAtomicPtrT oldVal,
92  EpicsAtomicPtrT newVal );
93 
94 #ifdef __cplusplus
95 } /* end of extern "C" */
96 #endif
97 
98 /*
99  * options for in-line compiler intrinsic or OS specific
100  * implementations of the above function prototypes
101  *
102  * for some of the compilers we must define the
103  * in-line functions before they get used in the c++
104  * in-line functions below
105  */
106 #include "epicsAtomicCD.h"
107 
108 #ifdef __cplusplus
109 
110 namespace epics {
111 namespace atomic {
112 
113 /*
114  * overloaded c++ interface
115  */
116 
117 /************* incr ***************/
118 EPICS_ATOMIC_INLINE size_t increment ( size_t & v )
119 {
120  return epicsAtomicIncrSizeT ( & v );
121 }
122 
123 EPICS_ATOMIC_INLINE int increment ( int & v )
124 {
125  return epicsAtomicIncrIntT ( & v );
126 }
127 
128 /************* decr ***************/
129 EPICS_ATOMIC_INLINE size_t decrement ( size_t & v )
130 {
131  return epicsAtomicDecrSizeT ( & v );
132 }
133 
134 EPICS_ATOMIC_INLINE int decrement ( int & v )
135 {
136  return epicsAtomicDecrIntT ( & v );
137 }
138 
139 /************* add ***************/
140 EPICS_ATOMIC_INLINE size_t add ( size_t & v, size_t delta )
141 {
142  return epicsAtomicAddSizeT ( & v, delta );
143 }
144 
145 EPICS_ATOMIC_INLINE int add ( int & v, int delta )
146 {
147  return epicsAtomicAddIntT ( & v, delta );
148 }
149 
150 /************* sub ***************/
151 EPICS_ATOMIC_INLINE size_t subtract ( size_t & v, size_t delta )
152 {
153  return epicsAtomicSubSizeT ( & v, delta );
154 }
155 
156 EPICS_ATOMIC_INLINE int subtract ( int & v, int delta )
157 {
158  return epicsAtomicAddIntT ( & v, -delta );
159 }
160 
161 /************* set ***************/
162 EPICS_ATOMIC_INLINE void set ( size_t & v , size_t newValue )
163 {
164  epicsAtomicSetSizeT ( & v, newValue );
165 }
166 
167 EPICS_ATOMIC_INLINE void set ( int & v, int newValue )
168 {
169  epicsAtomicSetIntT ( & v, newValue );
170 }
171 
172 EPICS_ATOMIC_INLINE void set ( EpicsAtomicPtrT & v, EpicsAtomicPtrT newValue )
173 {
174  epicsAtomicSetPtrT ( & v, newValue );
175 }
176 
177 /************* get ***************/
178 EPICS_ATOMIC_INLINE size_t get ( const size_t & v )
179 {
180  return epicsAtomicGetSizeT ( & v );
181 }
182 
183 EPICS_ATOMIC_INLINE int get ( const int & v )
184 {
185  return epicsAtomicGetIntT ( & v );
186 }
187 
189 {
190  return epicsAtomicGetPtrT ( & v );
191 }
192 
193 /************* cas ***************/
194 EPICS_ATOMIC_INLINE size_t compareAndSwap ( size_t & v,
195  size_t oldVal, size_t newVal )
196 {
197  return epicsAtomicCmpAndSwapSizeT ( & v, oldVal, newVal );
198 }
199 
200 EPICS_ATOMIC_INLINE int compareAndSwap ( int & v, int oldVal, int newVal )
201 {
202  return epicsAtomicCmpAndSwapIntT ( & v, oldVal, newVal );
203 }
204 
206  EpicsAtomicPtrT oldVal,
207  EpicsAtomicPtrT newVal )
208 {
209  return epicsAtomicCmpAndSwapPtrT ( & v, oldVal, newVal );
210 }
211 
212 } /* end of name space atomic */
213 } /* end of name space epics */
214 
215 #endif /* ifdef __cplusplus */
216 
217 #endif /* epicsAtomic_h */
EPICS_ATOMIC_INLINE EpicsAtomicPtrT epicsAtomicGetPtrT(const EpicsAtomicPtrT *pTarget)
EPICS_ATOMIC_INLINE void epicsAtomicSetPtrT(EpicsAtomicPtrT *pTarget, EpicsAtomicPtrT newValue)
EPICS_ATOMIC_INLINE int epicsAtomicGetIntT(const int *pTarget)
EPICS_ATOMIC_INLINE int epicsAtomicCmpAndSwapIntT(int *pTarget, int oldVal, int newVal)
EPICS_ATOMIC_INLINE size_t epicsAtomicCmpAndSwapSizeT(size_t *pTarget, size_t oldVal, size_t newVal)
EPICS_ATOMIC_INLINE size_t epicsAtomicDecrSizeT(size_t *pTarget)
EPICS_ATOMIC_INLINE void epicsAtomicSetIntT(int *pTarget, int newValue)
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
EPICS_ATOMIC_INLINE size_t epicsAtomicAddSizeT(size_t *pTarget, size_t delta)
EPICS_ATOMIC_INLINE size_t epicsAtomicGetSizeT(const size_t *pTarget)
EPICS_ATOMIC_INLINE int epicsAtomicDecrIntT(int *pTarget)
EPICS_ATOMIC_INLINE size_t epicsAtomicSubSizeT(size_t *pTarget, size_t delta)
void * EpicsAtomicPtrT
Definition: epicsAtomic.h:28
EPICS_ATOMIC_INLINE int epicsAtomicIncrIntT(int *pTarget)
#define EPICS_ATOMIC_INLINE
Definition: epicsAtomic.h:22
EPICS_ATOMIC_INLINE void epicsAtomicSetSizeT(size_t *pTarget, size_t newValue)
EPICS_ATOMIC_INLINE size_t epicsAtomicIncrSizeT(size_t *pTarget)
EPICS_ATOMIC_INLINE EpicsAtomicPtrT epicsAtomicCmpAndSwapPtrT(EpicsAtomicPtrT *pTarget, EpicsAtomicPtrT oldVal, EpicsAtomicPtrT newVal)
EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier(void)
Definition: epicsAtomicCD.h:91
EPICS_ATOMIC_INLINE int epicsAtomicAddIntT(int *pTarget, int delta)
EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier(void)