OpenMPI  0.1.1
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 (c) 2011 Sandia National Laboratories. All rights reserved.
13  * $COPYRIGHT$
14  *
15  * Additional copyrights may follow
16  *
17  * $HEADER$
18  */
19 
20 #ifndef OMPI_SYS_ARCH_ATOMIC_H
21 #define OMPI_SYS_ARCH_ATOMIC_H 1
22 
23 /**********************************************************************
24  *
25  * Memory Barriers
26  *
27  *********************************************************************/
28 #define OPAL_HAVE_ATOMIC_MEM_BARRIER 1
29 
30 static inline void opal_atomic_mb(void)
31 {
32  __sync_synchronize();
33 }
34 
35 static inline void opal_atomic_rmb(void)
36 {
37  __sync_synchronize();
38 }
39 
40 static inline void opal_atomic_wmb(void)
41 {
42  __sync_synchronize();
43 }
44 
45 /**********************************************************************
46  *
47  * Atomic math operations
48  *
49  *********************************************************************/
50 
51 #define OPAL_HAVE_ATOMIC_CMPSET_32 1
52 static inline int opal_atomic_cmpset_acq_32( volatile int32_t *addr,
53  int32_t oldval, int32_t newval)
54 {
55  return __sync_bool_compare_and_swap(addr, oldval, newval);
56 }
57 
58 
59 static inline int opal_atomic_cmpset_rel_32( volatile int32_t *addr,
60  int32_t oldval, int32_t newval)
61 {
62  return __sync_bool_compare_and_swap(addr, oldval, newval);}
63 
64 static inline int opal_atomic_cmpset_32( volatile int32_t *addr,
65  int32_t oldval, int32_t newval)
66 {
67  return __sync_bool_compare_and_swap(addr, oldval, newval);
68 }
69 
70 #define OPAL_HAVE_ATOMIC_MATH_32 1
71 
72 #define OPAL_HAVE_ATOMIC_ADD_32 1
73 static inline int32_t opal_atomic_add_32(volatile int32_t *addr, int32_t delta)
74 {
75  return __sync_fetch_and_add(addr, delta);
76 }
77 
78 #define OPAL_HAVE_ATOMIC_SUB_32 1
79 static inline int32_t opal_atomic_sub_32(volatile int32_t *addr, int32_t delta)
80 {
81  return __sync_fetch_and_sub(addr, delta);
82 }
83 
84 #define OPAL_HAVE_ATOMIC_CMPSET_64 1
85 static inline int opal_atomic_cmpset_acq_64( volatile int64_t *addr,
86  int64_t oldval, int64_t newval)
87 {
88  return __sync_bool_compare_and_swap(addr, oldval, newval);
89 }
90 
91 static inline int opal_atomic_cmpset_rel_64( volatile int64_t *addr,
92  int64_t oldval, int64_t newval)
93 {
94  return __sync_bool_compare_and_swap(addr, oldval, newval);}
95 
96 
97 static inline int opal_atomic_cmpset_64( volatile int64_t *addr,
98  int64_t oldval, int64_t newval)
99 {
100  return __sync_bool_compare_and_swap(addr, oldval, newval);
101 }
102 
103 #define OPAL_HAVE_ATOMIC_MATH_64 1
104 #define OPAL_HAVE_ATOMIC_ADD_64 1
105 static inline int64_t opal_atomic_add_64(volatile int64_t *addr, int64_t delta)
106 {
107  return __sync_fetch_and_add(addr, delta);
108 }
109 
110 #define OPAL_HAVE_ATOMIC_SUB_64 1
111 static inline int64_t opal_atomic_sub_64(volatile int64_t *addr, int64_t delta)
112 {
113  return __sync_fetch_and_sub(addr, delta);
114 }
115 
116 #endif /* ! OMPI_SYS_ARCH_ATOMIC_H */
void opal_atomic_rmb(void)
Read memory barrier.
void opal_atomic_mb(void)
Memory barrier.
void opal_atomic_wmb(void)
Write memory barrier.