DPDK
19.02.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
while
(__sync_lock_test_and_set(&sl->
locked
, 1))
65
while
(sl->
locked
)
66
rte_pause
();
67
}
68
#endif
69
76
static
inline
void
77
rte_spinlock_unlock
(
rte_spinlock_t
*sl);
78
79
#ifdef RTE_FORCE_INTRINSICS
80
static
inline
void
81
rte_spinlock_unlock
(
rte_spinlock_t
*sl)
82
{
83
__sync_lock_release(&sl->
locked
);
84
}
85
#endif
86
95
static
inline
int
96
rte_spinlock_trylock
(
rte_spinlock_t
*sl);
97
98
#ifdef RTE_FORCE_INTRINSICS
99
static
inline
int
100
rte_spinlock_trylock
(
rte_spinlock_t
*sl)
101
{
102
return
__sync_lock_test_and_set(&sl->
locked
,1) == 0;
103
}
104
#endif
105
114
static
inline
int
rte_spinlock_is_locked
(
rte_spinlock_t
*sl)
115
{
116
return
sl->
locked
;
117
}
118
125
static
inline
int
rte_tm_supported
(
void
);
126
140
static
inline
void
141
rte_spinlock_lock_tm
(
rte_spinlock_t
*sl);
142
150
static
inline
void
151
rte_spinlock_unlock_tm
(
rte_spinlock_t
*sl);
152
169
static
inline
int
170
rte_spinlock_trylock_tm
(
rte_spinlock_t
*sl);
171
175
typedef
struct
{
176
rte_spinlock_t
sl
;
177
volatile
int
user
;
178
volatile
int
count
;
179
}
rte_spinlock_recursive_t
;
180
184
#define RTE_SPINLOCK_RECURSIVE_INITIALIZER {RTE_SPINLOCK_INITIALIZER, -1, 0}
185
192
static
inline
void
rte_spinlock_recursive_init
(
rte_spinlock_recursive_t
*slr)
193
{
194
rte_spinlock_init
(&slr->
sl
);
195
slr->
user
= -1;
196
slr->
count
= 0;
197
}
198
205
static
inline
void
rte_spinlock_recursive_lock
(
rte_spinlock_recursive_t
*slr)
206
{
207
int
id
=
rte_gettid
();
208
209
if
(slr->
user
!=
id
) {
210
rte_spinlock_lock
(&slr->
sl
);
211
slr->
user
= id;
212
}
213
slr->
count
++;
214
}
221
static
inline
void
rte_spinlock_recursive_unlock
(
rte_spinlock_recursive_t
*slr)
222
{
223
if
(--(slr->
count
) == 0) {
224
slr->
user
= -1;
225
rte_spinlock_unlock
(&slr->
sl
);
226
}
227
228
}
229
238
static
inline
int
rte_spinlock_recursive_trylock
(
rte_spinlock_recursive_t
*slr)
239
{
240
int
id
=
rte_gettid
();
241
242
if
(slr->
user
!=
id
) {
243
if
(
rte_spinlock_trylock
(&slr->
sl
) == 0)
244
return
0;
245
slr->
user
= id;
246
}
247
slr->
count
++;
248
return
1;
249
}
250
251
265
static
inline
void
rte_spinlock_recursive_lock_tm
(
266
rte_spinlock_recursive_t
*slr);
267
275
static
inline
void
rte_spinlock_recursive_unlock_tm
(
276
rte_spinlock_recursive_t
*slr);
277
294
static
inline
int
rte_spinlock_recursive_trylock_tm
(
295
rte_spinlock_recursive_t
*slr);
296
297
#endif
/* _RTE_SPINLOCK_H_ */
Generated by
1.8.1.2