DPDK  22.07.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_compat.h>
96 #include <rte_seqcount.h>
97 #include <rte_spinlock.h>
98 
102 typedef struct {
105 } rte_seqlock_t;
106 
110 #define RTE_SEQLOCK_INITIALIZER \
111  { \
112  .count = RTE_SEQCOUNT_INITIALIZER, \
113  .lock = RTE_SPINLOCK_INITIALIZER \
114  }
115 
128 __rte_experimental
129 static inline void
131 {
132  rte_seqcount_init(&seqlock->count);
133  rte_spinlock_init(&seqlock->lock);
134 }
135 
154 __rte_experimental
155 static inline uint32_t
157 {
158  return rte_seqcount_read_begin(&seqlock->count);
159 }
160 
180 __rte_experimental
181 static inline bool
182 rte_seqlock_read_retry(const rte_seqlock_t *seqlock, uint32_t begin_sn)
183 {
184  return rte_seqcount_read_retry(&seqlock->count, begin_sn);
185 }
186 
215 __rte_experimental
216 static inline void
218 {
219  /* To synchronize with other writers. */
220  rte_spinlock_lock(&seqlock->lock);
221 
222  rte_seqcount_write_begin(&seqlock->count);
223 }
224 
240 __rte_experimental
241 static inline void
243 {
244  rte_seqcount_write_end(&seqlock->count);
245 
246  rte_spinlock_unlock(&seqlock->lock);
247 }
248 
249 #ifdef __cplusplus
250 }
251 #endif
252 
253 #endif /* _RTE_SEQLOCK_H_ */
static __rte_experimental uint32_t rte_seqlock_read_begin(const rte_seqlock_t *seqlock)
Definition: rte_seqlock.h:156
static __rte_experimental void rte_seqlock_write_unlock(rte_seqlock_t *seqlock)
Definition: rte_seqlock.h:242
static void rte_spinlock_lock(rte_spinlock_t *sl)
static __rte_experimental void rte_seqcount_init(rte_seqcount_t *seqcount)
Definition: rte_seqcount.h:53
static __rte_experimental bool rte_seqcount_read_retry(const rte_seqcount_t *seqcount, uint32_t begin_sn)
Definition: rte_seqcount.h:151
rte_seqcount_t count
Definition: rte_seqlock.h:103
static void rte_spinlock_unlock(rte_spinlock_t *sl)
static __rte_experimental void rte_seqlock_write_lock(rte_seqlock_t *seqlock)
Definition: rte_seqlock.h:217
rte_spinlock_t lock
Definition: rte_seqlock.h:104
static void rte_spinlock_init(rte_spinlock_t *sl)
Definition: rte_spinlock.h:46
static __rte_experimental void rte_seqcount_write_begin(rte_seqcount_t *seqcount)
Definition: rte_seqcount.h:201
static __rte_experimental bool rte_seqlock_read_retry(const rte_seqlock_t *seqlock, uint32_t begin_sn)
Definition: rte_seqlock.h:182
static __rte_experimental uint32_t rte_seqcount_read_begin(const rte_seqcount_t *seqcount)
Definition: rte_seqcount.h:106
static __rte_experimental void rte_seqcount_write_end(rte_seqcount_t *seqcount)
Definition: rte_seqcount.h:232
static __rte_experimental void rte_seqlock_init(rte_seqlock_t *seqlock)
Definition: rte_seqlock.h:130