DPDK  24.03.0
rte_seqlock.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2022 Ericsson AB
3  */
4 
5 #ifndef _RTE_SEQLOCK_H_
6 #define _RTE_SEQLOCK_H_
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
90 #include <stdbool.h>
91 #include <stdint.h>
92 
93 #include <rte_atomic.h>
94 #include <rte_branch_prediction.h>
95 #include <rte_seqcount.h>
96 #include <rte_spinlock.h>
97 
101 typedef struct {
104 } rte_seqlock_t;
105 
109 #define RTE_SEQLOCK_INITIALIZER \
110  { \
111  .count = RTE_SEQCOUNT_INITIALIZER, \
112  .lock = RTE_SPINLOCK_INITIALIZER \
113  }
114 
124 static inline void
126 {
127  rte_seqcount_init(&seqlock->count);
128  rte_spinlock_init(&seqlock->lock);
129 }
130 
145 static inline uint32_t
147 {
148  return rte_seqcount_read_begin(&seqlock->count);
149 }
150 
167 static inline bool
168 rte_seqlock_read_retry(const rte_seqlock_t *seqlock, uint32_t begin_sn)
169 {
170  return rte_seqcount_read_retry(&seqlock->count, begin_sn);
171 }
172 
198 static inline void
200  __rte_exclusive_lock_function(&seqlock->lock)
201 {
202  /* To synchronize with other writers. */
203  rte_spinlock_lock(&seqlock->lock);
204 
205  rte_seqcount_write_begin(&seqlock->count);
206 }
207 
220 static inline void
222  __rte_unlock_function(&seqlock->lock)
223 {
224  rte_seqcount_write_end(&seqlock->count);
225 
226  rte_spinlock_unlock(&seqlock->lock);
227 }
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 
233 #endif /* _RTE_SEQLOCK_H_ */
static void rte_seqlock_init(rte_seqlock_t *seqlock)
Definition: rte_seqlock.h:125
static void rte_spinlock_lock(rte_spinlock_t *sl)
static void rte_seqlock_write_unlock(rte_seqlock_t *seqlock)
Definition: rte_seqlock.h:221
rte_seqcount_t count
Definition: rte_seqlock.h:102
static void rte_spinlock_unlock(rte_spinlock_t *sl)
static void rte_seqcount_write_begin(rte_seqcount_t *seqcount)
Definition: rte_seqcount.h:182
static uint32_t rte_seqcount_read_begin(const rte_seqcount_t *seqcount)
Definition: rte_seqcount.h:97
static bool rte_seqlock_read_retry(const rte_seqlock_t *seqlock, uint32_t begin_sn)
Definition: rte_seqlock.h:168
static void rte_seqlock_write_lock(rte_seqlock_t *seqlock)
Definition: rte_seqlock.h:199
rte_spinlock_t lock
Definition: rte_seqlock.h:103
static void rte_seqcount_init(rte_seqcount_t *seqcount)
Definition: rte_seqcount.h:49
static void rte_spinlock_init(rte_spinlock_t *sl)
Definition: rte_spinlock.h:47
static uint32_t rte_seqlock_read_begin(const rte_seqlock_t *seqlock)
Definition: rte_seqlock.h:146
static void rte_seqcount_write_end(rte_seqcount_t *seqcount)
Definition: rte_seqcount.h:209
static bool rte_seqcount_read_retry(const rte_seqcount_t *seqcount, uint32_t begin_sn)
Definition: rte_seqcount.h:137