DPDK
19.05.0
Main Page
Related Pages
Data Structures
Files
Examples
File List
Globals
lib
librte_eal
common
include
generic
rte_spinlock.h
Go to the documentation of this file.
1
/* SPDX-License-Identifier: BSD-3-Clause
2
* Copyright(c) 2010-2014 Intel Corporation
3
*/
4
5
#ifndef _RTE_SPINLOCK_H_
6
#define _RTE_SPINLOCK_H_
7
21
#include <
rte_lcore.h
>
22
#ifdef RTE_FORCE_INTRINSICS
23
#include <
rte_common.h
>
24
#endif
25
#include <
rte_pause.h
>
26
30
typedef
struct
{
31
volatile
int
locked
;
32
}
rte_spinlock_t
;
33
37
#define RTE_SPINLOCK_INITIALIZER { 0 }
38
45
static
inline
void
46
rte_spinlock_init
(
rte_spinlock_t
*sl)
47
{
48
sl->
locked
= 0;
49
}
50
57
static
inline
void
58
rte_spinlock_lock
(
rte_spinlock_t
*sl);
59
60
#ifdef RTE_FORCE_INTRINSICS
61
static
inline
void
62
rte_spinlock_lock
(
rte_spinlock_t
*sl)
63
{
64
int
exp = 0;
65
66
while
(!__atomic_compare_exchange_n(&sl->
locked
, &exp, 1, 0,
67
__ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) {
68
while
(__atomic_load_n(&sl->
locked
, __ATOMIC_RELAXED))
69
rte_pause
();
70
exp = 0;
71
}
72
}
73
#endif
74
81
static
inline
void
82
rte_spinlock_unlock
(
rte_spinlock_t
*sl);
83
84
#ifdef RTE_FORCE_INTRINSICS
85
static
inline
void
86
rte_spinlock_unlock
(
rte_spinlock_t
*sl)
87
{
88
__atomic_store_n(&sl->
locked
, 0, __ATOMIC_RELEASE);
89
}
90
#endif
91
100
static
inline
int
101
rte_spinlock_trylock
(
rte_spinlock_t
*sl);
102
103
#ifdef RTE_FORCE_INTRINSICS
104
static
inline
int
105
rte_spinlock_trylock
(
rte_spinlock_t
*sl)
106
{
107
int
exp = 0;
108
return
__atomic_compare_exchange_n(&sl->
locked
, &exp, 1,
109
0,
/* disallow spurious failure */
110
__ATOMIC_ACQUIRE, __ATOMIC_RELAXED);
111
}
112
#endif
113
122
static
inline
int
rte_spinlock_is_locked
(
rte_spinlock_t
*sl)
123
{
124
return
__atomic_load_n(&sl->
locked
, __ATOMIC_ACQUIRE);
125
}
126
133
static
inline
int
rte_tm_supported
(
void
);
134
148
static
inline
void
149
rte_spinlock_lock_tm
(
rte_spinlock_t
*sl);
150
158
static
inline
void
159
rte_spinlock_unlock_tm
(
rte_spinlock_t
*sl);
160
177
static
inline
int
178
rte_spinlock_trylock_tm
(
rte_spinlock_t
*sl);
179
183
typedef
struct
{
184
rte_spinlock_t
sl
;
185
volatile
int
user
;
186
volatile
int
count
;
187
}
rte_spinlock_recursive_t
;
188
192
#define RTE_SPINLOCK_RECURSIVE_INITIALIZER {RTE_SPINLOCK_INITIALIZER, -1, 0}
193
200
static
inline
void
rte_spinlock_recursive_init
(
rte_spinlock_recursive_t
*slr)
201
{
202
rte_spinlock_init
(&slr->
sl
);
203
slr->
user
= -1;
204
slr->
count
= 0;
205
}
206
213
static
inline
void
rte_spinlock_recursive_lock
(
rte_spinlock_recursive_t
*slr)
214
{
215
int
id
=
rte_gettid
();
216
217
if
(slr->
user
!=
id
) {
218
rte_spinlock_lock
(&slr->
sl
);
219
slr->
user
= id;
220
}
221
slr->
count
++;
222
}
229
static
inline
void
rte_spinlock_recursive_unlock
(
rte_spinlock_recursive_t
*slr)
230
{
231
if
(--(slr->
count
) == 0) {
232
slr->
user
= -1;
233
rte_spinlock_unlock
(&slr->
sl
);
234
}
235
236
}
237
246
static
inline
int
rte_spinlock_recursive_trylock
(
rte_spinlock_recursive_t
*slr)
247
{
248
int
id
=
rte_gettid
();
249
250
if
(slr->
user
!=
id
) {
251
if
(
rte_spinlock_trylock
(&slr->
sl
) == 0)
252
return
0;
253
slr->
user
= id;
254
}
255
slr->
count
++;
256
return
1;
257
}
258
259
273
static
inline
void
rte_spinlock_recursive_lock_tm
(
274
rte_spinlock_recursive_t
*slr);
275
283
static
inline
void
rte_spinlock_recursive_unlock_tm
(
284
rte_spinlock_recursive_t
*slr);
285
302
static
inline
int
rte_spinlock_recursive_trylock_tm
(
303
rte_spinlock_recursive_t
*slr);
304
305
#endif
/* _RTE_SPINLOCK_H_ */
Generated by
1.8.1.2