5#ifndef _RTE_SPINLOCK_H_
6#define _RTE_SPINLOCK_H_
25#ifdef RTE_FORCE_INTRINSICS
29#include <rte_lock_annotations.h>
31#include <rte_stdatomic.h>
40typedef struct __rte_capability("spinlock") {
41 volatile RTE_ATOMIC(
int) locked;
47#define RTE_SPINLOCK_INITIALIZER { 0 }
69 __rte_acquire_capability(sl);
71#ifdef RTE_FORCE_INTRINSICS
74 __rte_no_thread_safety_analysis
78 while (!rte_atomic_compare_exchange_strong_explicit(&sl->locked, &exp, 1,
79 rte_memory_order_acquire, rte_memory_order_relaxed)) {
81 0, rte_memory_order_relaxed);
95 __rte_release_capability(sl);
97#ifdef RTE_FORCE_INTRINSICS
100 __rte_no_thread_safety_analysis
102 rte_atomic_store_explicit(&sl->locked, 0, rte_memory_order_release);
117 __rte_try_acquire_capability(
true, sl);
119#ifdef RTE_FORCE_INTRINSICS
122 __rte_no_thread_safety_analysis
125 return rte_atomic_compare_exchange_strong_explicit(&sl->locked, &exp, 1,
126 rte_memory_order_acquire, rte_memory_order_relaxed);
140 return rte_atomic_load_explicit(&sl->locked, rte_memory_order_acquire);
166 __rte_acquire_capability(sl);
177 __rte_release_capability(sl);
198 __rte_try_acquire_capability(
true, sl);
212#define RTE_SPINLOCK_RECURSIVE_INITIALIZER {RTE_SPINLOCK_INITIALIZER, -1, 0}
223 rte_atomic_store_explicit(&slr->
owner, -1, rte_memory_order_relaxed);
234 __rte_no_thread_safety_analysis
238 if (rte_atomic_load_explicit(&slr->owner, rte_memory_order_relaxed) !=
id) {
240 rte_atomic_store_explicit(&slr->owner,
id, rte_memory_order_relaxed);
251 __rte_no_thread_safety_analysis
253 RTE_ASSERT(rte_atomic_load_explicit(&slr->owner, rte_memory_order_relaxed) ==
rte_gettid());
254 RTE_ASSERT(slr->count > 0);
255 if (--(slr->count) == 0) {
256 rte_atomic_store_explicit(&slr->owner, -1, rte_memory_order_relaxed);
271 __rte_no_thread_safety_analysis
275 if (rte_atomic_load_explicit(&slr->owner, rte_memory_order_relaxed) !=
id) {
278 rte_atomic_store_explicit(&slr->owner,
id, rte_memory_order_relaxed);
#define __rte_warn_unused_result
static int rte_gettid(void)
static __rte_always_inline void rte_wait_until_equal_32(volatile uint32_t *addr, uint32_t expected, rte_memory_order memorder)
static __rte_warn_unused_result int rte_spinlock_trylock(rte_spinlock_t *sl) sl)
static int rte_tm_supported(void)
static __rte_warn_unused_result int rte_spinlock_recursive_trylock_tm(rte_spinlock_recursive_t *slr)
static void rte_spinlock_recursive_lock_tm(rte_spinlock_recursive_t *slr)
static void rte_spinlock_unlock(rte_spinlock_t *sl)
static void rte_spinlock_recursive_unlock_tm(rte_spinlock_recursive_t *slr)
static void rte_spinlock_lock(rte_spinlock_t *sl)
static void rte_spinlock_lock_tm(rte_spinlock_t *sl)
static void rte_spinlock_recursive_init(rte_spinlock_recursive_t *slr)
static __rte_warn_unused_result int rte_spinlock_recursive_trylock(rte_spinlock_recursive_t *slr) __rte_no_thread_safety_analysis
static void rte_spinlock_recursive_unlock(rte_spinlock_recursive_t *slr) __rte_no_thread_safety_analysis
static void rte_spinlock_unlock_tm(rte_spinlock_t *sl)
static __rte_warn_unused_result int rte_spinlock_trylock_tm(rte_spinlock_t *sl) sl)
static int rte_spinlock_is_locked(rte_spinlock_t *sl)
static void rte_spinlock_recursive_lock(rte_spinlock_recursive_t *slr) __rte_no_thread_safety_analysis
static void rte_spinlock_init(rte_spinlock_t *sl)