FD.io VPP  v18.11-rc0-18-g2a3fb1a
Vector Packet Processing
queue.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * svm_queue.h - shared-memory queues
4  *
5  * Copyright (c) 2009 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #ifndef included_svm_queue_h
21 #define included_svm_queue_h
22 
23 #include <pthread.h>
24 
25 typedef struct _svm_queue
26 {
27  pthread_mutex_t mutex; /* 8 bytes */
28  pthread_cond_t condvar; /* 8 bytes */
29  int head;
30  int tail;
31  volatile int cursize;
32  int maxsize;
33  int elsize;
34  int consumer_pid;
35  int signal_when_queue_non_empty;
36  char data[0];
37 } svm_queue_t;
38 
39 typedef enum
40 {
41  /**
42  * blocking call
43  */
45 
46  /**
47  * non-blocking call
48  */
50 
51  /**
52  * blocking call, return on signal or time-out
53  */
56 
57 svm_queue_t *svm_queue_init (int nels,
58  int elsize,
59  int consumer_pid,
60  int signal_when_queue_non_empty);
61 void svm_queue_free (svm_queue_t * q);
62 int svm_queue_add (svm_queue_t * q, u8 * elem, int nowait);
63 int svm_queue_add2 (svm_queue_t * q, u8 * elem, u8 * elem2, int nowait);
65  u32 time);
66 int svm_queue_sub2 (svm_queue_t * q, u8 * elem);
67 void svm_queue_lock (svm_queue_t * q);
68 void svm_queue_unlock (svm_queue_t * q);
70 int svm_queue_add_nolock (svm_queue_t * q, u8 * elem);
71 int svm_queue_sub_raw (svm_queue_t * q, u8 * elem);
72 
73 /**
74  * Add element to queue with mutex held
75  * @param q queue
76  * @param elem pointer element data to add
77  */
78 void svm_queue_add_raw (svm_queue_t * q, u8 * elem);
79 
80 /*
81  * DEPRECATED please use svm_queue_t instead
82  */
84 
85 #endif /* included_svm_queue_h */
86 
87 /*
88  * fd.io coding-style-patch-verification: ON
89  *
90  * Local Variables:
91  * eval: (c-set-style "gnu")
92  * End:
93  */
void svm_queue_unlock(svm_queue_t *q)
Definition: queue.c:109
void svm_queue_lock(svm_queue_t *q)
Definition: queue.c:103
int svm_queue_add_nolock(svm_queue_t *q, u8 *elem)
Definition: queue.c:124
int svm_queue_sub_raw(svm_queue_t *q, u8 *elem)
Definition: queue.c:394
unsigned char u8
Definition: types.h:56
void svm_queue_add_raw(svm_queue_t *q, u8 *elem)
Add element to queue with mutex held.
Definition: queue.c:158
blocking call, return on signal or time-out
Definition: queue.h:54
svm_queue_t unix_shared_memory_queue_t
Definition: queue.h:83
unsigned int u32
Definition: types.h:88
int svm_queue_sub2(svm_queue_t *q, u8 *elem)
Definition: queue.c:364
void svm_queue_free(svm_queue_t *q)
Definition: queue.c:95
int svm_queue_is_full(svm_queue_t *q)
Definition: queue.c:115
int svm_queue_add(svm_queue_t *q, u8 *elem, int nowait)
Definition: queue.c:174
svm_queue_t * svm_queue_init(int nels, int elsize, int consumer_pid, int signal_when_queue_non_empty)
Definition: queue.c:51
svm_q_conditional_wait_t
Definition: queue.h:39
int svm_queue_add2(svm_queue_t *q, u8 *elem, u8 *elem2, int nowait)
Definition: queue.c:229
blocking call
Definition: queue.h:44
struct _svm_queue svm_queue_t
int svm_queue_sub(svm_queue_t *q, u8 *elem, svm_q_conditional_wait_t cond, u32 time)
Definition: queue.c:293
non-blocking call
Definition: queue.h:49