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
|
/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef _atomic_h_cleanup_
#define _atomic_h_cleanup_ "atomic/solaris.h"
#include <atomic.h>
#define MY_ATOMIC_MODE "solaris-atomic"
#if defined(__GNUC__)
#define atomic_typeof(T,V) __typeof__(V)
#else
#define atomic_typeof(T,V) T
#endif
#define uintptr_t void *
#define atomic_or_ptr_nv(X,Y) (void *)atomic_or_ulong_nv((volatile ulong_t *)X, Y)
#define make_atomic_cas_body(S) \
atomic_typeof(uint ## S ## _t, *cmp) sav; \
sav = atomic_cas_ ## S( \
(volatile uint ## S ## _t *)a, \
(uint ## S ## _t)*cmp, \
(uint ## S ## _t)set); \
if (! (ret= (sav == *cmp))) \
*cmp= sav;
#define make_atomic_add_body(S) \
int ## S nv; /* new value */ \
nv= atomic_add_ ## S ## _nv((volatile uint ## S ## _t *)a, v); \
v= nv - v
/* ------------------------------------------------------------------------ */
#ifdef MY_ATOMIC_MODE_DUMMY
#define make_atomic_load_body(S) ret= *a
#define make_atomic_store_body(S) *a= v
#else /* MY_ATOMIC_MODE_DUMMY */
#define make_atomic_load_body(S) \
ret= atomic_or_ ## S ## _nv((volatile uint ## S ## _t *)a, 0)
#define make_atomic_store_body(S) \
(void) atomic_swap_ ## S((volatile uint ## S ## _t *)a, (uint ## S ## _t)v)
#endif
#define make_atomic_fas_body(S) \
v= atomic_swap_ ## S((volatile uint ## S ## _t *)a, (uint ## S ## _t)v)
#else /* cleanup */
#undef uintptr_t
#undef atomic_or_ptr_nv
#endif
|