update version to 0.5.0
[urcu.git] / urcu / uatomic_arch_sparc64.h
CommitLineData
58de5a4b
MD
1#ifndef _URCU_ARCH_UATOMIC_SPARC64_H
2#define _URCU_ARCH_UATOMIC_SPARC64_H
3
4/*
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
9 *
10 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
11 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
12 *
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.
18 *
19 * Code inspired from libuatomic_ops-1.2, inherited in part from the
20 * Boehm-Demers-Weiser conservative garbage collector.
21 */
22
23#include <urcu/compiler.h>
24#include <urcu/system.h>
25
36bc70a8
MD
26#ifdef __cplusplus
27extern "C" {
28#endif
29
58de5a4b
MD
30/* cmpxchg */
31
32static inline __attribute__((always_inline))
33unsigned long _uatomic_cmpxchg(void *addr, unsigned long old,
34 unsigned long _new, int len)
35{
36 switch (len) {
37 case 4:
38 {
39 __asm__ __volatile__ (
40 "membar #StoreLoad | #LoadLoad\n\t"
41 "cas [%1],%2,%0\n\t"
42 "membar #StoreLoad | #StoreStore\n\t"
43 : "+&r" (_new)
44 : "r" (addr), "r" (old)
45 : "memory");
46
47 return _new;
48 }
49#if (BITS_PER_LONG == 64)
50 case 8:
51 {
52 __asm__ __volatile__ (
53 "membar #StoreLoad | #LoadLoad\n\t"
54 "casx [%1],%2,%0\n\t"
55 "membar #StoreLoad | #StoreStore\n\t"
56 : "+&r" (_new)
57 : "r" (addr), "r" (old)
58 : "memory");
59
60 return _new;
61 }
62#endif
63 }
64 __builtin_trap();
65 return 0;
66}
67
68
69#define uatomic_cmpxchg(addr, old, _new) \
70 ((__typeof__(*(addr))) _uatomic_cmpxchg((addr), (unsigned long)(old),\
71 (unsigned long)(_new), \
72 sizeof(*(addr))))
73
36bc70a8
MD
74#ifdef __cplusplus
75}
76#endif
77
8760d94e
PB
78#include <urcu/uatomic_generic.h>
79
58de5a4b 80#endif /* _URCU_ARCH_UATOMIC_PPC_H */
This page took 0.024797 seconds and 4 git commands to generate.