33 #include <rte_lock_annotations.h> 53 #define RTE_RWLOCK_WAIT 0x1 54 #define RTE_RWLOCK_WRITE 0x2 55 #define RTE_RWLOCK_MASK (RTE_RWLOCK_WAIT | RTE_RWLOCK_WRITE) 57 #define RTE_RWLOCK_READ 0x4 59 typedef struct __rte_lockable {
66 #define RTE_RWLOCK_INITIALIZER { 0 } 88 __rte_shared_lock_function(rwl)
89 __rte_no_thread_safety_analysis
95 while (__atomic_load_n(&rwl->cnt, __ATOMIC_RELAXED)
100 x = __atomic_fetch_add(&rwl->cnt, RTE_RWLOCK_READ,
101 __ATOMIC_ACQUIRE) + RTE_RWLOCK_READ;
104 if (
likely(!(x & RTE_RWLOCK_MASK)))
108 __atomic_fetch_sub(&rwl->cnt, RTE_RWLOCK_READ,
125 __rte_shared_trylock_function(0, rwl)
126 __rte_no_thread_safety_analysis
130 x = __atomic_load_n(&rwl->cnt, __ATOMIC_RELAXED);
133 if (x & RTE_RWLOCK_MASK)
137 x = __atomic_fetch_add(&rwl->cnt, RTE_RWLOCK_READ,
138 __ATOMIC_ACQUIRE) + RTE_RWLOCK_READ;
141 if (
unlikely(x & RTE_RWLOCK_MASK)) {
142 __atomic_fetch_sub(&rwl->cnt, RTE_RWLOCK_READ,
158 __rte_unlock_function(rwl)
159 __rte_no_thread_safety_analysis
161 __atomic_fetch_sub(&rwl->cnt, RTE_RWLOCK_READ, __ATOMIC_RELEASE);
176 __rte_exclusive_trylock_function(0, rwl)
177 __rte_no_thread_safety_analysis
181 x = __atomic_load_n(&rwl->cnt, __ATOMIC_RELAXED);
182 if (x < RTE_RWLOCK_WRITE &&
183 __atomic_compare_exchange_n(&rwl->cnt, &x, x + RTE_RWLOCK_WRITE,
184 1, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED))
198 __rte_exclusive_lock_function(rwl)
199 __rte_no_thread_safety_analysis
204 x = __atomic_load_n(&rwl->cnt, __ATOMIC_RELAXED);
207 if (
likely(x < RTE_RWLOCK_WRITE)) {
209 if (__atomic_compare_exchange_n(&rwl->cnt, &x, RTE_RWLOCK_WRITE, 1,
210 __ATOMIC_ACQUIRE, __ATOMIC_RELAXED))
216 __atomic_fetch_or(&rwl->cnt, RTE_RWLOCK_WAIT, __ATOMIC_RELAXED);
219 while (__atomic_load_n(&rwl->cnt, __ATOMIC_RELAXED) > RTE_RWLOCK_WAIT)
233 __rte_unlock_function(rwl)
234 __rte_no_thread_safety_analysis
236 __atomic_fetch_sub(&rwl->cnt, RTE_RWLOCK_WRITE, __ATOMIC_RELEASE);
250 if (__atomic_load_n(&rwl->cnt, __ATOMIC_RELAXED) & RTE_RWLOCK_WRITE)
271 __rte_shared_lock_function(rwl);
281 __rte_unlock_function(rwl);
298 __rte_exclusive_lock_function(rwl);
308 __rte_unlock_function(rwl);
static void rte_rwlock_write_lock_tm(rte_rwlock_t *rwl)
static int rte_rwlock_read_trylock(rte_rwlock_t *rwl) rwl) __rte_no_thread_safety_analysis
static int rte_rwlock_write_is_locked(rte_rwlock_t *rwl)
static void rte_rwlock_read_lock_tm(rte_rwlock_t *rwl)
static void rte_pause(void)
static void rte_rwlock_write_unlock(rte_rwlock_t *rwl) __rte_no_thread_safety_analysis
static int rte_rwlock_write_trylock(rte_rwlock_t *rwl) rwl) __rte_no_thread_safety_analysis
static void rte_rwlock_read_unlock_tm(rte_rwlock_t *rwl)
static void rte_rwlock_write_lock(rte_rwlock_t *rwl) __rte_no_thread_safety_analysis
static void rte_rwlock_init(rte_rwlock_t *rwl)
static void rte_rwlock_write_unlock_tm(rte_rwlock_t *rwl)
static void rte_rwlock_read_lock(rte_rwlock_t *rwl) __rte_no_thread_safety_analysis
static void rte_rwlock_read_unlock(rte_rwlock_t *rwl) __rte_no_thread_safety_analysis