1 #ifndef _URCU_ARCH_UATOMIC_SPARC64_H
2 #define _URCU_ARCH_UATOMIC_SPARC64_H
5 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
6 * Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
7 * Copyright (c) 1999-2003 by Hewlett-Packard Company. All rights reserved.
8 * Copyright (c) 2009 Mathieu Desnoyers
10 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
11 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
13 * Permission is hereby granted to use or copy this program
14 * for any purpose, provided the above notices are retained on all copies.
15 * Permission to modify the code and to distribute modified code is granted,
16 * provided the above notices are retained, and a notice that the code was
17 * modified is included with the above copyright notice.
19 * Code inspired from libuatomic_ops-1.2, inherited in part from the
20 * Boehm-Demers-Weiser conservative garbage collector.
23 #include <urcu/compiler.h>
24 #include <urcu/system.h>
30 #ifndef __SIZEOF_LONG__
32 #define __SIZEOF_LONG__ 8
34 #define __SIZEOF_LONG__ 4
39 #define BITS_PER_LONG (__SIZEOF_LONG__ * 8)
42 #define uatomic_set(addr, v) STORE_SHARED(*(addr), (v))
43 #define uatomic_read(addr) LOAD_SHARED(*(addr))
47 static inline __attribute__((always_inline
))
48 unsigned long _uatomic_cmpxchg(void *addr
, unsigned long old
,
49 unsigned long _new
, int len
)
54 __asm__
__volatile__ (
55 "membar #StoreLoad | #LoadLoad\n\t"
57 "membar #StoreLoad | #StoreStore\n\t"
59 : "r" (addr
), "r" (old
)
64 #if (BITS_PER_LONG == 64)
67 __asm__
__volatile__ (
68 "membar #StoreLoad | #LoadLoad\n\t"
70 "membar #StoreLoad | #StoreStore\n\t"
72 : "r" (addr
), "r" (old
)
84 #define uatomic_cmpxchg(addr, old, _new) \
85 ((__typeof__(*(addr))) _uatomic_cmpxchg((addr), (unsigned long)(old),\
86 (unsigned long)(_new), \
91 static inline __attribute__((always_inline
))
92 unsigned long _uatomic_exchange(void *addr
, unsigned long val
, int len
)
97 unsigned int old
, oldt
;
99 oldt
= uatomic_read((unsigned int *)addr
);
102 oldt
= _uatomic_cmpxchg(addr
, old
, val
, 4);
103 } while (oldt
!= old
);
107 #if (BITS_PER_LONG == 64)
110 unsigned long old
, oldt
;
112 oldt
= uatomic_read((unsigned long *)addr
);
115 oldt
= _uatomic_cmpxchg(addr
, old
, val
, 8);
116 } while (oldt
!= old
);
126 #define uatomic_xchg(addr, v) \
127 ((__typeof__(*(addr))) _uatomic_exchange((addr), (unsigned long)(v), \
130 /* uatomic_add_return */
132 static inline __attribute__((always_inline
))
133 unsigned long _uatomic_add_return(void *addr
, unsigned long val
, int len
)
138 unsigned int old
, oldt
;
140 oldt
= uatomic_read((unsigned int *)addr
);
143 oldt
= _uatomic_cmpxchg(addr
, old
, old
+ val
, 4);
144 } while (oldt
!= old
);
148 #if (BITS_PER_LONG == 64)
151 unsigned long old
, oldt
;
153 oldt
= uatomic_read((unsigned long *)addr
);
156 oldt
= _uatomic_cmpxchg(addr
, old
, old
+ val
, 8);
157 } while (oldt
!= old
);
167 #define uatomic_add_return(addr, v) \
168 ((__typeof__(*(addr))) _uatomic_add_return((addr), \
169 (unsigned long)(v), \
172 /* uatomic_sub_return, uatomic_add, uatomic_sub, uatomic_inc, uatomic_dec */
174 #define uatomic_sub_return(addr, v) uatomic_add_return((addr), -(v))
176 #define uatomic_add(addr, v) (void)uatomic_add_return((addr), (v))
177 #define uatomic_sub(addr, v) (void)uatomic_sub_return((addr), (v))
179 #define uatomic_inc(addr) uatomic_add((addr), 1)
180 #define uatomic_dec(addr) uatomic_add((addr), -1)
182 #define compat_uatomic_cmpxchg(ptr, old, _new) uatomic_cmpxchg(ptr, old, _new)
188 #endif /* _URCU_ARCH_UATOMIC_PPC_H */
This page took 0.039256 seconds and 4 git commands to generate.