SolarCapture C Bindings
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
ext_packet_list.h
Go to the documentation of this file.
1 
8 #ifndef __SOLAR_CAPTURE_EXT_PACKET_LIST_H__
9 #define __SOLAR_CAPTURE_EXT_PACKET_LIST_H__
10 
15  struct sc_packet* head;
16  struct sc_packet** tail;
17  int num_pkts;
18  int num_frags;
19 };
20 
26 static inline void __sc_packet_list_init(struct sc_packet_list* l)
27 {
28  l->num_pkts = 0;
29  l->num_frags = 0;
30  l->tail = &l->head;
31 }
39 static inline void sc_packet_list_init(struct sc_packet_list* l)
40 {
41  __sc_packet_list_init(l);
42  l->head = NULL;
43 }
44 
49 static inline int sc_packet_list_is_empty(const struct sc_packet_list* l)
50 {
51  return l->num_pkts == 0;
52 }
53 
54 
62 static inline void sc_packet_list_finalise(struct sc_packet_list* l)
63 {
64  *(l->tail) = NULL;
65 }
66 
67 
72 static inline struct sc_packet* sc_packet_list_tail(struct sc_packet_list* l)
73 {
74  return (struct sc_packet*)
75  ((char*) l->tail - SC_MEMBER_OFFSET(struct sc_packet, next));
76 }
77 
88 static inline void __sc_packet_list_push_head(struct sc_packet_list* pl,
89  struct sc_packet* p)
90 {
91  p->next = pl->head;
92  pl->head = p;
93  pl->num_pkts += 1;
94  pl->num_frags += p->frags_n;
95 }
96 /* \endcond */
97 
104 static inline void sc_packet_list_push_head(struct sc_packet_list* pl,
105  struct sc_packet* p)
106 {
107  if( pl->num_pkts == 0 )
108  pl->tail = &(p->next);
109  __sc_packet_list_push_head(pl, p);
110 }
111 
120 static inline void __sc_packet_list_append(struct sc_packet_list* l,
121  struct sc_packet* p)
122 {
123  *(l->tail) = p;
124  l->tail = &p->next;
125  ++l->num_pkts;
126  l->num_frags += p->frags_n;
127 }
135 static inline void sc_packet_list_append(struct sc_packet_list* l,
136  struct sc_packet* p)
137 {
138  __sc_packet_list_append(l, p);
139  p->next = NULL;
140 }
141 
143 static inline void __sc_packet_list_append_list(struct sc_packet_list* l,
144  struct sc_packet* head,
145  struct sc_packet** tail,
146  int num_pkts, int num_frags)
147 {
148  *(l->tail) = head;
149  l->num_pkts += num_pkts;
150  l->num_frags += num_frags;
151  l->tail = tail;
152 }
165 static inline void sc_packet_list_append_list(struct sc_packet_list* dest,
166  struct sc_packet_list* src)
167 {
168  assert(!sc_packet_list_is_empty(src));
169  __sc_packet_list_append_list(dest, src->head, src->tail,
170  src->num_pkts, src->num_frags);
171 }
172 
182 static inline struct sc_packet*
183  __sc_packet_list_pop_head(struct sc_packet_list* pl)
184 {
185  struct sc_packet* p = pl->head;
186  pl->head = p->next;
187  pl->num_pkts -= 1;
188  pl->num_frags -= p->frags_n;
189  return p;
190 }
201 static inline struct sc_packet*
203 {
204  struct sc_packet* p = __sc_packet_list_pop_head(pl);
205  if( pl->num_pkts == 0 )
206  pl->tail = &pl->head;
207  else
209 
210  return p;
211 }
212 
213 #endif /* __SOLAR_CAPTURE_EXT_PACKET_LIST_H__ */
214 
struct sc_packet ** tail
Definition: ext_packet_list.h:16
static void sc_packet_prefetch_r(struct sc_packet *p)
Prefetch a packet for reading.
Definition: ext_packet.h:153
uint8_t frags_n
Definition: ext_packet.h:62
static void sc_packet_list_finalise(struct sc_packet_list *l)
Finalise a list.
Definition: ext_packet_list.h:62
static int sc_packet_list_is_empty(const struct sc_packet_list *l)
Check if packet list is empty.
Definition: ext_packet_list.h:49
static void sc_packet_list_init(struct sc_packet_list *l)
Initialise a list.
Definition: ext_packet_list.h:39
int num_pkts
Definition: ext_packet_list.h:17
Representation of a packet.
Definition: ext_packet.h:56
static struct sc_packet * sc_packet_list_tail(struct sc_packet_list *l)
Return the tail of current tail of the list.
Definition: ext_packet_list.h:72
static void sc_packet_list_append_list(struct sc_packet_list *dest, struct sc_packet_list *src)
Append a list to a list.
Definition: ext_packet_list.h:165
int num_frags
Definition: ext_packet_list.h:18
static void sc_packet_list_append(struct sc_packet_list *l, struct sc_packet *p)
Append a packet to a list and finalise.
Definition: ext_packet_list.h:135
A list of packets or packet buffers.
Definition: ext_packet_list.h:14
#define SC_MEMBER_OFFSET(c_type, mbr_name)
Calculate memory offset of a field within a struct.
Definition: ext_packet.h:29
struct sc_packet * next
Definition: ext_packet.h:69
static struct sc_packet * sc_packet_list_pop_head(struct sc_packet_list *pl)
Remove and return the head of the list.
Definition: ext_packet_list.h:202
static void sc_packet_list_push_head(struct sc_packet_list *pl, struct sc_packet *p)
Push a packet to the head of a list.
Definition: ext_packet_list.h:104
struct sc_packet * head
Definition: ext_packet_list.h:15