This is Unofficial EPICS BASE Doxygen Site
epicsAtomicOSD.h
Go to the documentation of this file.
1 
2 /*************************************************************************\
3 * Copyright (c) 2011 LANS LLC, as Operator of
4 * Los Alamos National Laboratory.
5 * Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
6 * National Laboratory.
7 * EPICS BASE is distributed subject to a Software License Agreement found
8 * in file LICENSE that is included with this distribution.
9 \*************************************************************************/
10 
11 /*
12  * Author Jeffrey O. Hill
13  * johill@lanl.gov
14  */
15 
16 #include "libComAPI.h"
17 
18 #ifndef epicsAtomicOSD_h
19 #define epicsAtomicOSD_h
20 
21 #define EPICS_ATOMIC_OS_NAME "Solaris"
22 
23 #if defined ( __SunOS_5_10 )
24 
25 /*
26  * atomic.h exists only in Solaris 10 or higher
27  */
28 #include <atomic.h>
29 
30 #include "epicsAssert.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif /* __cplusplus */
35 
36 #ifndef EPICS_ATOMIC_READ_MEMORY_BARRIER
37 #define EPICS_ATOMIC_READ_MEMORY_BARRIER
39 {
40  membar_consumer ();
41 }
42 #endif
43 
44 #ifndef EPICS_ATOMIC_WRITE_MEMORY_BARRIER
45 #define EPICS_ATOMIC_WRITE_MEMORY_BARRIER
47 {
48  membar_producer ();
49 }
50 #endif
51 
52 #ifndef EPICS_ATOMIC_CAS_INTT
53 #define EPICS_ATOMIC_CAS_INTT
55  int oldVal, int newVal )
56 {
57  STATIC_ASSERT ( sizeof ( int ) == sizeof ( unsigned ) );
58  unsigned * const pTarg = ( unsigned * ) pTarget;
59  return ( int ) atomic_cas_uint ( pTarg, ( unsigned ) oldVal,
60  ( unsigned ) newVal );
61 }
62 #endif
63 
64 #ifndef EPICS_ATOMIC_CAS_SIZET
65 #define EPICS_ATOMIC_CAS_SIZET
67  size_t * pTarget,
68  size_t oldVal, size_t newVal )
69 {
70  STATIC_ASSERT ( sizeof ( ulong_t ) == sizeof ( size_t ) );
71  ulong_t * const pTarg = ( ulong_t * ) pTarget;
72  return ( size_t ) atomic_cas_ulong ( pTarg, oldVal, newVal );
73 }
74 #endif
75 
76 #ifndef EPICS_ATOMIC_CAS_PTRT
77 #define EPICS_ATOMIC_CAS_PTRT
79  EpicsAtomicPtrT * pTarget,
80  EpicsAtomicPtrT oldVal,
81  EpicsAtomicPtrT newVal )
82 {
83  return atomic_cas_ptr ( pTarget, oldVal, newVal );
84 }
85 #endif
86 
87 #ifndef EPICS_ATOMIC_INCR_INTT
88 #define EPICS_ATOMIC_INCR_INTT
89 EPICS_ATOMIC_INLINE int epicsAtomicIncrIntT ( int * pTarget )
90 {
91  STATIC_ASSERT ( sizeof ( unsigned ) == sizeof ( int ) );
92  unsigned * const pTarg = ( unsigned * ) ( pTarget );
93  return ( int ) atomic_inc_uint_nv ( pTarg );
94 }
95 #endif
96 
97 #ifndef EPICS_ATOMIC_INCR_SIZET
98 #define EPICS_ATOMIC_INCR_SIZET
99 EPICS_ATOMIC_INLINE size_t epicsAtomicIncrSizeT ( size_t * pTarget )
100 {
101  STATIC_ASSERT ( sizeof ( ulong_t ) == sizeof ( size_t ) );
102  ulong_t * const pTarg = ( ulong_t * ) pTarget;
103  return ( size_t ) atomic_inc_ulong_nv ( pTarg );
104 }
105 #endif
106 
107 #ifndef EPICS_ATOMIC_DECR_INTT
108 #define EPICS_ATOMIC_DECR_INTT
109 EPICS_ATOMIC_INLINE int epicsAtomicDecrIntT ( int * pTarget )
110 {
111  STATIC_ASSERT ( sizeof ( unsigned ) == sizeof ( int ) );
112  unsigned * const pTarg = ( unsigned * ) ( pTarget );
113  return ( int ) atomic_dec_uint_nv ( pTarg );
114 }
115 #endif
116 
117 #ifndef EPICS_ATOMIC_DECR_SIZET
118 #define EPICS_ATOMIC_DECR_SIZET
119 EPICS_ATOMIC_INLINE size_t epicsAtomicDecrSizeT ( size_t * pTarget )
120 {
121  STATIC_ASSERT ( sizeof ( ulong_t ) == sizeof ( size_t ) );
122  ulong_t * const pTarg = ( ulong_t * ) pTarget;
123  return ( size_t ) atomic_dec_ulong_nv ( pTarg );
124 }
125 #endif
126 
127 #ifndef EPICS_ATOMIC_ADD_INTT
128 #define EPICS_ATOMIC_ADD_INTT
129 EPICS_ATOMIC_INLINE int epicsAtomicAddIntT ( int * pTarget, int delta )
130 {
131  STATIC_ASSERT ( sizeof ( unsigned ) == sizeof ( int ) );
132  unsigned * const pTarg = ( unsigned * ) ( pTarget );
133  return ( int ) atomic_add_int_nv ( pTarg, delta );
134 }
135 #endif
136 
137 #ifndef EPICS_ATOMIC_ADD_SIZET
138 #define EPICS_ATOMIC_ADD_SIZET
139 EPICS_ATOMIC_INLINE size_t epicsAtomicAddSizeT ( size_t * pTarget,
140  size_t delta )
141 {
142  STATIC_ASSERT ( sizeof ( ulong_t ) == sizeof ( size_t ) );
143  ulong_t * const pTarg = ( ulong_t * ) pTarget;
144  return ( size_t ) atomic_add_long_nv ( pTarg, ( long ) delta );
145 }
146 #endif
147 
148 #ifndef EPICS_ATOMIC_SUB_SIZET
149 #define EPICS_ATOMIC_SUB_SIZET
150 EPICS_ATOMIC_INLINE size_t epicsAtomicSubSizeT ( size_t * pTarget,
151  size_t delta )
152 {
153  STATIC_ASSERT ( sizeof ( ulong_t ) == sizeof ( size_t ) );
154  ulong_t * const pTarg = ( ulong_t * ) pTarget;
155  long sdelta = ( long ) delta;
156  return ( size_t ) atomic_add_long_nv ( pTarg, -sdelta );
157 }
158 #endif
159 
160 #ifdef __cplusplus
161 } /* end of extern "C" */
162 #endif /* __cplusplus */
163 
164 #endif /* ifdef __SunOS_5_10 */
165 
166 typedef struct EpicsAtomicLockKey {
167  char dummy;
169 
170 
171 #ifdef __cplusplus
172 extern "C" {
173 #endif /* __cplusplus */
174 
175 LIBCOM_API void epicsAtomicLock ( struct EpicsAtomicLockKey * );
176 LIBCOM_API void epicsAtomicUnlock ( struct EpicsAtomicLockKey * );
177 
178 #ifdef __cplusplus
179 } /* end of extern "C" */
180 #endif /* __cplusplus */
181 
182 #include "epicsAtomicDefault.h"
183 
184 #endif /* epicsAtomicOSD_h */
185 
EPICS_ATOMIC_INLINE size_t epicsAtomicCmpAndSwapSizeT(size_t *pTarget, size_t oldVal, size_t newVal)
An EPICS-specific replacement for ANSI C&#39;s assert.
EPICS_ATOMIC_INLINE size_t epicsAtomicSubSizeT(size_t *pTarget, size_t delta)
struct EpicsAtomicLockKey EpicsAtomicLockKey
EPICS_ATOMIC_INLINE int epicsAtomicCmpAndSwapIntT(int *pTarget, int oldVal, int newVal)
EPICS_ATOMIC_INLINE size_t epicsAtomicAddSizeT(size_t *pTarget, size_t delta)
EPICS_ATOMIC_INLINE size_t epicsAtomicDecrSizeT(size_t *pTarget)
LIBCOM_API void epicsAtomicLock(struct EpicsAtomicLockKey *)
void * EpicsAtomicPtrT
Definition: epicsAtomic.h:28
#define EPICS_ATOMIC_INLINE
Definition: epicsAtomic.h:22
#define STATIC_ASSERT(expr)
Declare a condition that should be true at compile-time.
Definition: epicsAssert.h:86
EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier(void)
EPICS_ATOMIC_INLINE EpicsAtomicPtrT epicsAtomicCmpAndSwapPtrT(EpicsAtomicPtrT *pTarget, EpicsAtomicPtrT oldVal, EpicsAtomicPtrT newVal)
EPICS_ATOMIC_INLINE int epicsAtomicAddIntT(int *pTarget, int delta)
LIBCOM_API void epicsAtomicUnlock(struct EpicsAtomicLockKey *)
EPICS_ATOMIC_INLINE int epicsAtomicDecrIntT(int *pTarget)
EPICS_ATOMIC_INLINE int epicsAtomicIncrIntT(int *pTarget)
EPICS_ATOMIC_INLINE size_t epicsAtomicIncrSizeT(size_t *pTarget)
EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier(void)