Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/rust/helpers/atomic_ext.c
121797 views
1
// SPDX-License-Identifier: GPL-2.0
2
3
#include <asm/barrier.h>
4
#include <asm/rwonce.h>
5
#include <linux/atomic.h>
6
7
__rust_helper s8 rust_helper_atomic_i8_read(s8 *ptr)
8
{
9
return READ_ONCE(*ptr);
10
}
11
12
__rust_helper s8 rust_helper_atomic_i8_read_acquire(s8 *ptr)
13
{
14
return smp_load_acquire(ptr);
15
}
16
17
__rust_helper s16 rust_helper_atomic_i16_read(s16 *ptr)
18
{
19
return READ_ONCE(*ptr);
20
}
21
22
__rust_helper s16 rust_helper_atomic_i16_read_acquire(s16 *ptr)
23
{
24
return smp_load_acquire(ptr);
25
}
26
27
__rust_helper void rust_helper_atomic_i8_set(s8 *ptr, s8 val)
28
{
29
WRITE_ONCE(*ptr, val);
30
}
31
32
__rust_helper void rust_helper_atomic_i8_set_release(s8 *ptr, s8 val)
33
{
34
smp_store_release(ptr, val);
35
}
36
37
__rust_helper void rust_helper_atomic_i16_set(s16 *ptr, s16 val)
38
{
39
WRITE_ONCE(*ptr, val);
40
}
41
42
__rust_helper void rust_helper_atomic_i16_set_release(s16 *ptr, s16 val)
43
{
44
smp_store_release(ptr, val);
45
}
46
47
/*
48
* xchg helpers depend on ARCH_SUPPORTS_ATOMIC_RMW and on the
49
* architecture provding xchg() support for i8 and i16.
50
*
51
* The architectures that currently support Rust (x86_64, armv7,
52
* arm64, riscv, and loongarch) satisfy these requirements.
53
*/
54
__rust_helper s8 rust_helper_atomic_i8_xchg(s8 *ptr, s8 new)
55
{
56
return xchg(ptr, new);
57
}
58
59
__rust_helper s16 rust_helper_atomic_i16_xchg(s16 *ptr, s16 new)
60
{
61
return xchg(ptr, new);
62
}
63
64
__rust_helper s8 rust_helper_atomic_i8_xchg_acquire(s8 *ptr, s8 new)
65
{
66
return xchg_acquire(ptr, new);
67
}
68
69
__rust_helper s16 rust_helper_atomic_i16_xchg_acquire(s16 *ptr, s16 new)
70
{
71
return xchg_acquire(ptr, new);
72
}
73
74
__rust_helper s8 rust_helper_atomic_i8_xchg_release(s8 *ptr, s8 new)
75
{
76
return xchg_release(ptr, new);
77
}
78
79
__rust_helper s16 rust_helper_atomic_i16_xchg_release(s16 *ptr, s16 new)
80
{
81
return xchg_release(ptr, new);
82
}
83
84
__rust_helper s8 rust_helper_atomic_i8_xchg_relaxed(s8 *ptr, s8 new)
85
{
86
return xchg_relaxed(ptr, new);
87
}
88
89
__rust_helper s16 rust_helper_atomic_i16_xchg_relaxed(s16 *ptr, s16 new)
90
{
91
return xchg_relaxed(ptr, new);
92
}
93
94
/*
95
* try_cmpxchg helpers depend on ARCH_SUPPORTS_ATOMIC_RMW and on the
96
* architecture provding try_cmpxchg() support for i8 and i16.
97
*
98
* The architectures that currently support Rust (x86_64, armv7,
99
* arm64, riscv, and loongarch) satisfy these requirements.
100
*/
101
__rust_helper bool rust_helper_atomic_i8_try_cmpxchg(s8 *ptr, s8 *old, s8 new)
102
{
103
return try_cmpxchg(ptr, old, new);
104
}
105
106
__rust_helper bool rust_helper_atomic_i16_try_cmpxchg(s16 *ptr, s16 *old, s16 new)
107
{
108
return try_cmpxchg(ptr, old, new);
109
}
110
111
__rust_helper bool rust_helper_atomic_i8_try_cmpxchg_acquire(s8 *ptr, s8 *old, s8 new)
112
{
113
return try_cmpxchg_acquire(ptr, old, new);
114
}
115
116
__rust_helper bool rust_helper_atomic_i16_try_cmpxchg_acquire(s16 *ptr, s16 *old, s16 new)
117
{
118
return try_cmpxchg_acquire(ptr, old, new);
119
}
120
121
__rust_helper bool rust_helper_atomic_i8_try_cmpxchg_release(s8 *ptr, s8 *old, s8 new)
122
{
123
return try_cmpxchg_release(ptr, old, new);
124
}
125
126
__rust_helper bool rust_helper_atomic_i16_try_cmpxchg_release(s16 *ptr, s16 *old, s16 new)
127
{
128
return try_cmpxchg_release(ptr, old, new);
129
}
130
131
__rust_helper bool rust_helper_atomic_i8_try_cmpxchg_relaxed(s8 *ptr, s8 *old, s8 new)
132
{
133
return try_cmpxchg_relaxed(ptr, old, new);
134
}
135
136
__rust_helper bool rust_helper_atomic_i16_try_cmpxchg_relaxed(s16 *ptr, s16 *old, s16 new)
137
{
138
return try_cmpxchg_relaxed(ptr, old, new);
139
}
140
141