This is Unofficial EPICS BASE Doxygen Site
epicsAtomicCD.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 #ifndef epicsAtomicCD_h
17 #define epicsAtomicCD_h
18 
19 #include "epicsAssert.h"
20 
21 #ifndef _MSC_VER
22 # error this header file is only for use with with the Microsoft Compiler
23 #endif
24 
25 #ifdef _MSC_EXTENSIONS
26 
27 #define EPICS_ATOMIC_CMPLR_NAME "MSVC-INTRINSIC"
28 
29 #include <intrin.h>
30 
31 #if defined ( _M_IX86 )
32 # pragma warning( push )
33 # pragma warning( disable : 4793 )
34  EPICS_ATOMIC_INLINE void epicsAtomicMemoryBarrier (void)
35  {
36  long fence;
37  __asm { xchg fence, eax }
38  }
39 # pragma warning( pop )
40 #elif defined ( _M_X64 )
41 # define MS_ATOMIC_64
42 # pragma intrinsic ( __faststorefence )
43  EPICS_ATOMIC_INLINE void epicsAtomicMemoryBarrier (void)
44  {
45  __faststorefence ();
46  }
47 #elif defined ( _M_IA64 )
48 # define MS_ATOMIC_64
49 # pragma intrinsic ( __mf )
50  EPICS_ATOMIC_INLINE void epicsAtomicMemoryBarrier (void)
51  {
52  __mf ();
53  }
54 #else
55 # error unexpected target architecture, msvc version of epicsAtomicCD.h
56 #endif
57 
58 /*
59  * The windows doc appears to recommend defining InterlockedExchange
60  * to be _InterlockedExchange to cause it to be an intrinsic, but that
61  * creates issues when later, in a windows os specific header, we include
62  * windows.h. Therefore, we except some code duplication between the msvc
63  * csAtomic.h and win32 osdAtomic.h to avoid problems, and to keep the
64  * os specific windows.h header file out of the msvc cdAtomic.h
65  */
66 #define MS_LONG long
67 #define MS_InterlockedExchange _InterlockedExchange
68 #define MS_InterlockedCompareExchange _InterlockedCompareExchange
69 #define MS_InterlockedIncrement _InterlockedIncrement
70 #define MS_InterlockedDecrement _InterlockedDecrement
71 #define MS_InterlockedExchange _InterlockedExchange
72 #define MS_InterlockedExchangeAdd _InterlockedExchangeAdd
73 #if defined ( MS_ATOMIC_64 )
74 # define MS_LONGLONG long long
75 # define MS_InterlockedIncrement64 _InterlockedIncrement64
76 # define MS_InterlockedDecrement64 _InterlockedDecrement64
77 # define MS_InterlockedExchange64 _InterlockedExchange64
78 # define MS_InterlockedExchangeAdd64 _InterlockedExchangeAdd64
79 # define MS_InterlockedCompareExchange64 _InterlockedCompareExchange64
80 #endif
81 
82 #ifdef __cplusplus
83 extern "C" {
84 #endif /* __cplusplus */
85 
86 #define EPICS_ATOMIC_READ_MEMORY_BARRIER
88 {
89  epicsAtomicMemoryBarrier ();
90 }
91 
92 #define EPICS_ATOMIC_WRITE_MEMORY_BARRIER
94 {
95  epicsAtomicMemoryBarrier ();
96 }
97 
98 #ifdef __cplusplus
99 } /* end of extern "C" */
100 #endif /* __cplusplus */
101 
102 #include "epicsAtomicMS.h"
103 #include "epicsAtomicDefault.h"
104 
105 #else /* ifdef _MSC_EXTENSIONS */
106 
107 #define EPICS_ATOMIC_CMPLR_NAME "MSVC-DIRECT"
108 
109 /*
110  * if unavailable as an intrinsic we will try
111  * for os specific inline solution
112  */
113 #include "epicsAtomicOSD.h"
114 
115 #endif /* ifdef _MSC_EXTENSIONS */
116 
117 #endif /* epicsAtomicCD_h */
118 
An EPICS-specific replacement for ANSI C&#39;s assert.
EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier(void)
Definition: epicsAtomicCD.h:91
#define EPICS_ATOMIC_INLINE
Definition: epicsAtomic.h:22
EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier(void)