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)
44 static inline __attribute__((always_inline
))
45 unsigned long _uatomic_cmpxchg(void *addr
, unsigned long old
,
46 unsigned long _new
, int len
)
51 __asm__
__volatile__ (
52 "membar #StoreLoad | #LoadLoad\n\t"
54 "membar #StoreLoad | #StoreStore\n\t"
56 : "r" (addr
), "r" (old
)
61 #if (BITS_PER_LONG == 64)
64 __asm__
__volatile__ (
65 "membar #StoreLoad | #LoadLoad\n\t"
67 "membar #StoreLoad | #StoreStore\n\t"
69 : "r" (addr
), "r" (old
)
81 #define uatomic_cmpxchg(addr, old, _new) \
82 ((__typeof__(*(addr))) _uatomic_cmpxchg((addr), (unsigned long)(old),\
83 (unsigned long)(_new), \
88 static inline __attribute__((always_inline
))
89 unsigned long _uatomic_exchange(void *addr
, unsigned long val
, int len
)
94 unsigned int old
, oldt
;
96 oldt
= uatomic_read((unsigned int *)addr
);
99 oldt
= _uatomic_cmpxchg(addr
, old
, val
, 4);
100 } while (oldt
!= old
);
104 #if (BITS_PER_LONG == 64)
107 unsigned long old
, oldt
;
109 oldt
= uatomic_read((unsigned long *)addr
);
112 oldt
= _uatomic_cmpxchg(addr
, old
, val
, 8);
113 } while (oldt
!= old
);
123 #define uatomic_xchg(addr, v) \
124 ((__typeof__(*(addr))) _uatomic_exchange((addr), (unsigned long)(v), \
127 /* uatomic_add_return */
129 static inline __attribute__((always_inline
))
130 unsigned long _uatomic_add_return(void *addr
, unsigned long val
, int len
)
135 unsigned int old
, oldt
;
137 oldt
= uatomic_read((unsigned int *)addr
);
140 oldt
= _uatomic_cmpxchg(addr
, old
, old
+ val
, 4);
141 } while (oldt
!= old
);
145 #if (BITS_PER_LONG == 64)
148 unsigned long old
, oldt
;
150 oldt
= uatomic_read((unsigned long *)addr
);
153 oldt
= _uatomic_cmpxchg(addr
, old
, old
+ val
, 8);
154 } while (oldt
!= old
);
164 #define uatomic_add_return(addr, v) \
165 ((__typeof__(*(addr))) _uatomic_add_return((addr), \
166 (unsigned long)(v), \
173 #include <urcu/uatomic_generic.h>
175 #endif /* _URCU_ARCH_UATOMIC_PPC_H */
This page took 0.060836 seconds and 4 git commands to generate.