5#ifndef _RTE_TICKETLOCK_H_
6#define _RTE_TICKETLOCK_H_
23#include <rte_stdatomic.h>
33 RTE_ATOMIC(uint32_t) tickets;
35 RTE_ATOMIC(uint16_t) current;
36 RTE_ATOMIC(uint16_t) next;
43#define RTE_TICKETLOCK_INITIALIZER { 0 }
54 rte_atomic_store_explicit(&tl->tickets, 0, rte_memory_order_relaxed);
66 uint16_t me = rte_atomic_fetch_add_explicit(&tl->s.next, 1, rte_memory_order_relaxed);
68 rte_memory_order_acquire);
80 uint16_t i = rte_atomic_load_explicit(&tl->s.current, rte_memory_order_relaxed);
81 rte_atomic_store_explicit(&tl->s.current, i + 1, rte_memory_order_release);
96 oldl.tickets = rte_atomic_load_explicit(&tl->tickets, rte_memory_order_relaxed);
97 newl.tickets = oldl.tickets;
99 if (oldl.s.next == oldl.s.current) {
100 if (rte_atomic_compare_exchange_strong_explicit(&tl->tickets,
101 (uint32_t *)(uintptr_t)&oldl.tickets, newl.tickets,
102 rte_memory_order_acquire, rte_memory_order_relaxed))
121 tic.tickets = rte_atomic_load_explicit(&tl->tickets, rte_memory_order_acquire);
122 return (tic.s.current != tic.s.next);
128#define TICKET_LOCK_INVALID_ID -1
132 RTE_ATOMIC(
int) user;
134} rte_ticketlock_recursive_t;
139#define RTE_TICKETLOCK_RECURSIVE_INITIALIZER {RTE_TICKETLOCK_INITIALIZER, \
140 TICKET_LOCK_INVALID_ID, 0}
167 if (rte_atomic_load_explicit(&tlr->user, rte_memory_order_relaxed) !=
id) {
169 rte_atomic_store_explicit(&tlr->user,
id, rte_memory_order_relaxed);
183 if (--(tlr->count) == 0) {
185 rte_memory_order_relaxed);
203 if (rte_atomic_load_explicit(&tlr->user, rte_memory_order_relaxed) !=
id) {
206 rte_atomic_store_explicit(&tlr->user,
id, rte_memory_order_relaxed);
static int rte_gettid(void)
static __rte_always_inline void rte_wait_until_equal_16(volatile uint16_t *addr, uint16_t expected, rte_memory_order memorder)
#define TICKET_LOCK_INVALID_ID
static void rte_ticketlock_recursive_init(rte_ticketlock_recursive_t *tlr)
static void rte_ticketlock_init(rte_ticketlock_t *tl)
static void rte_ticketlock_unlock(rte_ticketlock_t *tl)
static void rte_ticketlock_recursive_lock(rte_ticketlock_recursive_t *tlr)
static void rte_ticketlock_lock(rte_ticketlock_t *tl)
static void rte_ticketlock_recursive_unlock(rte_ticketlock_recursive_t *tlr)
static int rte_ticketlock_is_locked(rte_ticketlock_t *tl)
static int rte_ticketlock_recursive_trylock(rte_ticketlock_recursive_t *tlr)
static int rte_ticketlock_trylock(rte_ticketlock_t *tl)