summaryrefslogtreecommitdiff
path: root/src/atomic_ops/sysdeps/gcc/generic-small.template
blob: dd17d2569d3f9f395218eb842c0fa73bf3105c59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
 * Copyright (c) 1996-1999 by Silicon Graphics.  All rights reserved.
 * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
 *
 *
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
 * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
 *
 * Permission is hereby granted to use or copy this program
 * for any purpose, provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 *
 */

AO_INLINE XCTYPE
AO_XSIZE_load(const volatile XCTYPE *addr)
{
  return __atomic_load_n(addr, __ATOMIC_RELAXED);
}
#define AO_HAVE_XSIZE_load

AO_INLINE XCTYPE
AO_XSIZE_load_acquire(const volatile XCTYPE *addr)
{
  return __atomic_load_n(addr, __ATOMIC_ACQUIRE);
}
#define AO_HAVE_XSIZE_load_acquire

/* XSIZE_load_full is generalized using load and nop_full, so that      */
/* XSIZE_load_read is defined using load and nop_read.                  */
/* XSIZE_store_full definition is omitted similar to load_full reason.  */

AO_INLINE void
AO_XSIZE_store(volatile XCTYPE *addr, XCTYPE value)
{
  __atomic_store_n(addr, value, __ATOMIC_RELAXED);
}
#define AO_HAVE_XSIZE_store

AO_INLINE void
AO_XSIZE_store_release(volatile XCTYPE *addr, XCTYPE value)
{
  __atomic_store_n(addr, value, __ATOMIC_RELEASE);
}
#define AO_HAVE_XSIZE_store_release

#ifdef AO_GCC_HAVE_XSIZE_SYNC_CAS

  AO_INLINE XCTYPE
  AO_XSIZE_fetch_compare_and_swap(volatile XCTYPE *addr,
                                  XCTYPE old_val, XCTYPE new_val)
  {
    (void)__atomic_compare_exchange_n(addr,
                                      &old_val /* p_expected */,
                                      new_val /* desired */,
                                      0 /* is_weak: false */,
                                      __ATOMIC_RELAXED /* success */,
                                      __ATOMIC_RELAXED /* failure */);
    return old_val;
  }
# define AO_HAVE_XSIZE_fetch_compare_and_swap

  AO_INLINE XCTYPE
  AO_XSIZE_fetch_compare_and_swap_acquire(volatile XCTYPE *addr,
                                          XCTYPE old_val, XCTYPE new_val)
  {
    (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
                                      __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
    return old_val;
  }
# define AO_HAVE_XSIZE_fetch_compare_and_swap_acquire

  AO_INLINE XCTYPE
  AO_XSIZE_fetch_compare_and_swap_release(volatile XCTYPE *addr,
                                          XCTYPE old_val, XCTYPE new_val)
  {
    (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
                                      __ATOMIC_RELEASE,
                                      __ATOMIC_RELAXED /* failure */);
    return old_val;
  }
# define AO_HAVE_XSIZE_fetch_compare_and_swap_release

  AO_INLINE XCTYPE
  AO_XSIZE_fetch_compare_and_swap_full(volatile XCTYPE *addr,
                                       XCTYPE old_val, XCTYPE new_val)
  {
    (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
                                      __ATOMIC_ACQ_REL,
                                      __ATOMIC_ACQUIRE /* failure */);
    return old_val;
  }
# define AO_HAVE_XSIZE_fetch_compare_and_swap_full

# ifndef AO_GENERALIZE_ASM_BOOL_CAS
    AO_INLINE int
    AO_XSIZE_compare_and_swap(volatile XCTYPE *addr,
                              XCTYPE old_val, XCTYPE new_val)
    {
      return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
                                        __ATOMIC_RELAXED, __ATOMIC_RELAXED);
    }
#   define AO_HAVE_XSIZE_compare_and_swap

    AO_INLINE int
    AO_XSIZE_compare_and_swap_acquire(volatile XCTYPE *addr,
                                      XCTYPE old_val, XCTYPE new_val)
    {
      return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
                                        __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
    }
#   define AO_HAVE_XSIZE_compare_and_swap_acquire

    AO_INLINE int
    AO_XSIZE_compare_and_swap_release(volatile XCTYPE *addr,
                                      XCTYPE old_val, XCTYPE new_val)
    {
      return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
                                              __ATOMIC_RELEASE,
                                              __ATOMIC_RELAXED /* failure */);
    }
#   define AO_HAVE_XSIZE_compare_and_swap_release

    AO_INLINE int
    AO_XSIZE_compare_and_swap_full(volatile XCTYPE *addr,
                                   XCTYPE old_val, XCTYPE new_val)
    {
      return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
                                              __ATOMIC_ACQ_REL,
                                              __ATOMIC_ACQUIRE /* failure */);
    }
#   define AO_HAVE_XSIZE_compare_and_swap_full

# endif /* !AO_GENERALIZE_ASM_BOOL_CAS */

#endif /* AO_GCC_HAVE_XSIZE_SYNC_CAS */