DPDK  20.05.0
rte_ring_peek_c11_mem.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2010-2020 Intel Corporation
4  * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
5  * All rights reserved.
6  * Derived from FreeBSD's bufring.h
7  * Used as BSD-3 Licensed with permission from Kip Macy.
8  */
9 
10 #ifndef _RTE_RING_PEEK_C11_MEM_H_
11 #define _RTE_RING_PEEK_C11_MEM_H_
12 
30 static __rte_always_inline uint32_t
31 __rte_ring_st_get_tail(struct rte_ring_headtail *ht, uint32_t *tail,
32  uint32_t num)
33 {
34  uint32_t h, n, t;
35 
36  h = ht->head;
37  t = ht->tail;
38  n = h - t;
39 
40  RTE_ASSERT(n >= num);
41  num = (n >= num) ? num : 0;
42 
43  *tail = h;
44  return num;
45 }
46 
52 static __rte_always_inline void
53 __rte_ring_st_set_head_tail(struct rte_ring_headtail *ht, uint32_t tail,
54  uint32_t num, uint32_t enqueue)
55 {
56  uint32_t pos;
57 
58  RTE_SET_USED(enqueue);
59 
60  pos = tail + num;
61  ht->head = pos;
62  __atomic_store_n(&ht->tail, pos, __ATOMIC_RELEASE);
63 }
64 
74 static __rte_always_inline uint32_t
75 __rte_ring_hts_get_tail(struct rte_ring_hts_headtail *ht, uint32_t *tail,
76  uint32_t num)
77 {
78  uint32_t n;
79  union __rte_ring_hts_pos p;
80 
81  p.raw = __atomic_load_n(&ht->ht.raw, __ATOMIC_RELAXED);
82  n = p.pos.head - p.pos.tail;
83 
84  RTE_ASSERT(n >= num);
85  num = (n >= num) ? num : 0;
86 
87  *tail = p.pos.tail;
88  return num;
89 }
90 
96 static __rte_always_inline void
97 __rte_ring_hts_set_head_tail(struct rte_ring_hts_headtail *ht, uint32_t tail,
98  uint32_t num, uint32_t enqueue)
99 {
100  union __rte_ring_hts_pos p;
101 
102  RTE_SET_USED(enqueue);
103 
104  p.pos.head = tail + num;
105  p.pos.tail = p.pos.head;
106 
107  __atomic_store_n(&ht->ht.raw, p.raw, __ATOMIC_RELEASE);
108 }
109 
110 #endif /* _RTE_RING_PEEK_C11_MEM_H_ */
volatile uint32_t head
Definition: rte_ring_core.h:72
#define __rte_always_inline
Definition: rte_common.h:193
#define RTE_SET_USED(x)
Definition: rte_common.h:110
volatile uint32_t tail
Definition: rte_ring_core.h:73