OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

atomic.h
1 /*
2 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2006 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * $COPYRIGHT$
13 *
14 * Additional copyrights may follow
15 *
16 * $HEADER$
17 */
18
19 #ifndef OMPI_SYS_ARCH_ATOMIC_H
20 #define OMPI_SYS_ARCH_ATOMIC_H 1
21
22 #include <windows.h>
23 #if defined(HAVE_WDM_H)
24 #include <wdm.h>
25 #endif /* HAVE_WDM_H */
26
27 /**********************************************************************
28 *
29 * Memory Barriers
30 *
31 *********************************************************************/
32 #define OPAL_HAVE_ATOMIC_MEM_BARRIER 1
33
34 static inline void opal_atomic_mb(void)
35 {
36 #if defined(HAVE_WDM_H)
37 return KeMemoryBarrier();
38 #endif /* HAVE_WDM_H */
39 }
40
41 static inline void opal_atomic_rmb(void)
42 {
43 #if defined(HAVE_WDM_H)
44 return KeMemoryBarrier();
45 #endif /* HAVE_WDM_H */
46 }
47
48 static inline void opal_atomic_wmb(void)
49 {
50 #if defined(HAVE_WDM_H)
51 return KeMemoryBarrier();
52 #endif /* HAVE_WDM_H */
53 }
54
55 /**********************************************************************
56 *
57 * Atomic math operations
58 *
59 *********************************************************************/
60
61 #define OPAL_HAVE_ATOMIC_CMPSET_32 1
62 static inline int opal_atomic_cmpset_acq_32( volatile int32_t *addr,
63 int32_t oldval, int32_t newval)
64 {
65 #if HAVE_INTERLOCKEDCOMPAREEXCHANGEACQUIRE
66 int32_t ret = InterlockedCompareExchangeAcquire( (long volatile*)addr,
67 (long)newval, (long)oldval);
68 #else
69 int32_t ret = InterlockedCompareExchange( (long volatile*)addr,
70 (long)newval, (long)oldval );
71 #endif /* HAVE_INTERLOCKEDCOMPAREEXCHANGEACQUIRE */
72 return (oldval == ret) ? 1: 0;
73 }
74
75
76 static inline int opal_atomic_cmpset_rel_32( volatile int32_t *addr,
77 int32_t oldval, int32_t newval)
78 {
79 #if HAVE_INTERLOCKEDCOMPAREEXCHANGERELEASE
80 int32_t ret = InterlockedCompareExchangeRelease( (long volatile*)addr,
81 (long)newval, (long)oldval );
82 #else
83 int32_t ret = InterlockedCompareExchange( (long volatile*)addr,
84 (long)newval, (long)oldval );
85 #endif /* HAVE_INTERLOCKEDCOMPAREEXCHANGERELEASE */
86 return (oldval == ret) ? 1: 0;
87 }
88
89 static inline int opal_atomic_cmpset_32( volatile int32_t *addr,
90 int32_t oldval, int32_t newval)
91 {
92 int32_t ret = InterlockedCompareExchange ((long volatile*) addr,
93 (long) newval, (long) oldval);
94
95 return (oldval == ret) ? 1: 0;
96 }
97
98 #define OPAL_HAVE_ATOMIC_MATH_32 1
99
100 #define OPAL_HAVE_ATOMIC_ADD_32 1
101 static inline int32_t opal_atomic_add_32(volatile int32_t *addr, int32_t delta)
102 {
103 return InterlockedExchangeAdd ((LONG volatile *) addr,
104 (LONG) delta);
105 }
106
107 #define OPAL_HAVE_ATOMIC_SUB_32 1
108 static inline int32_t opal_atomic_sub_32(volatile int32_t *addr, int32_t delta)
109 {
110 return InterlockedExchangeAdd( (LONG volatile *) addr,
111 (LONG) (-delta));
112 }
113
114 #if HAVE_INTERLOCKEDCOMPAREEXCHANGE64
115 #define OPAL_HAVE_ATOMIC_CMPSET_64 1
116 static inline int opal_atomic_cmpset_acq_64( volatile int64_t *addr,
117 int64_t oldval, int64_t newval)
118 {
119 /* The address should be 64 bits aligned otherwise ...
120 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/interlockedcompareexchange64.asp
121 */
122 #if HAVE_INTERLOCKEDCOMPAREEXCHANGEACQUIRE64
123 int64_t ret = InterlockedCompareExchangeAcquire64 ((int64_t volatile*) addr,
124 (int64_t) newval, (int64_t) oldval);
125 #else
126 int64_t ret = InterlockedCompareExchange64 ((int64_t volatile*) addr,
127 (int64_t) newval, (int64_t) oldval);
128 #endif /* HAVE_INTERLOCKEDCOMPAREEXCHANGEACQUIRE64 */
129 return (oldval == ret) ? 1: 0;
130 }
131
132 static inline int opal_atomic_cmpset_rel_64( volatile int64_t *addr,
133 int64_t oldval, int64_t newval)
134 {
135 #if HAVE_INTERLOCKEDCOMPAREEXCHANGERELEASE64
136 int64_t ret = InterlockedCompareExchangeRelease64 ((int64_t volatile*) addr,
137 (int64_t) newval, (int64_t) oldval);
138 #else
139 int64_t ret = InterlockedCompareExchange64 ((int64_t volatile*) addr,
140 (int64_t) newval, (int64_t) oldval);
141 #endif /* HAVE_INTERLOCKEDCOMPAREEXCHANGERELEASE64 */
142 return (oldval == ret) ? 1: 0;
143 }
144
145
146 static inline int opal_atomic_cmpset_64( volatile int64_t *addr,
147 int64_t oldval, int64_t newval)
148 {
149 int64_t ret = InterlockedCompareExchange64 ((int64_t volatile*) addr,
150 (int64_t) newval, (int64_t) oldval);
151 return (oldval == ret) ? 1: 0;
152 }
153
154 #define OPAL_HAVE_ATOMIC_MATH_64 1
155 #define OPAL_HAVE_ATOMIC_ADD_64 1
156 static inline int64_t opal_atomic_add_64(volatile int64_t *addr, int64_t delta)
157 {
158 return InterlockedExchangeAdd64 ((int64_t volatile *) addr,
159 (int64_t) delta);
160 }
161
162 #define OPAL_HAVE_ATOMIC_SUB_64 1
163 static inline int64_t opal_atomic_sub_64(volatile int64_t *addr, int64_t delta)
164 {
165 return InterlockedExchangeAdd64 ((int64_t volatile *) addr,
166 (int64_t) (-delta));
167 }
168
169 #else
170
171 #define OPAL_HAVE_ATOMIC_CMPSET_64 0
172 #define OPAL_HAVE_ATOMIC_MATH_64 0
173 #define OPAL_HAVE_ATOMIC_ADD_64 0
174 #define OPAL_HAVE_ATOMIC_SUB_64 0
175
176 #endif /* HAVE_INTERLOCKEDCOMPAREEXCHANGE64 */
177
178 #endif /* ! OMPI_SYS_ARCH_ATOMIC_H */
opal_atomic_rmb
void opal_atomic_rmb(void)
Read memory barrier.
opal_atomic_mb
void opal_atomic_mb(void)
Memory barrier.
opal_atomic_wmb
void opal_atomic_wmb(void)
Write memory barrier.