1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
/*
* Copyright (c) 2015 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <vppinfra/dlist.h>
typedef struct
{
dlist_elt_t *test_pool;
u32 head_index;
} test_main_t;
test_main_t test_main;
int
test_dlist_main (unformat_input_t * input)
{
test_main_t *tm = &test_main;
dlist_elt_t *head, *elt;
u32 elt_index, head_index;
u32 value;
int i;
pool_get (tm->test_pool, head);
head_index = head - tm->test_pool;
clib_dlist_init (tm->test_pool, head - tm->test_pool);
for (i = 1; i <= 3; i++)
{
pool_get (tm->test_pool, elt);
elt_index = elt - tm->test_pool;
clib_dlist_init (tm->test_pool, elt_index);
elt->value = i;
clib_dlist_addtail (tm->test_pool, head_index, elt_index);
}
head = pool_elt_at_index (tm->test_pool, head_index);
fformat (stdout, "Dump forward links\n");
elt_index = head->next;
i = 1;
value = 0;
while (value != ~0)
{
elt = pool_elt_at_index (tm->test_pool, elt_index);
fformat (stdout, "elt %d value %d\n", i++, elt->value);
elt_index = elt->next;
value = elt->value;
}
fformat (stdout, "Dump reverse links\n");
elt_index = head->prev;
i = 1;
value = 0;
while (value != ~0)
{
elt = pool_elt_at_index (tm->test_pool, elt_index);
fformat (stdout, "elt %d value %d\n", i++, elt->value);
elt_index = elt->prev;
value = elt->value;
}
fformat (stdout, "remove first element\n");
elt_index = clib_dlist_remove_head (tm->test_pool, head_index);
elt = pool_elt_at_index (tm->test_pool, elt_index);
fformat (stdout, "removed index %d value %d\n", elt_index, elt->value);
head = pool_elt_at_index (tm->test_pool, head_index);
fformat (stdout, "Dump forward links\n");
elt_index = head->next;
i = 1;
value = 0;
while (value != ~0)
{
elt = pool_elt_at_index (tm->test_pool, elt_index);
fformat (stdout, "elt %d value %d\n", i++, elt->value);
elt_index = elt->next;
value = elt->value;
}
fformat (stdout, "Dump reverse links\n");
elt_index = head->prev;
i = 1;
value = 0;
while (value != ~0)
{
elt = pool_elt_at_index (tm->test_pool, elt_index);
fformat (stdout, "elt %d value %d\n", i++, elt->value);
elt_index = elt->prev;
value = elt->value;
}
fformat (stdout, "re-insert index %d value %d at head\n", 1, 1);
clib_dlist_addhead (tm->test_pool, head_index, 1);
fformat (stdout, "Dump forward links\n");
elt_index = head->next;
i = 1;
value = 0;
while (value != ~0)
{
elt = pool_elt_at_index /*
*------------------------------------------------------------------
* memory_client.c - API message handling, client code.
*
* Copyright (c) 2010 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*------------------------------------------------------------------
*/
#include <setjmp.h>
#include <svm/svm.h>
#include <svm/ssvm.h>
#include <vppinfra/serialize.h>
#include <vppinfra/hash.h>
#include <vlibmemory/memory_client.h>
#include <vlibapi/api_common.h>
/* A hack. vl_client_get_first_plugin_msg_id depends on it */
#include <vlibmemory/socket_client.h>
#include <vlibmemory/vl_memory_msg_enum.h>
#define vl_typedefs /* define message structures */
#include <vlibmemory/vl_memory_api_h.h>
#undef vl_typedefs
#define vl_endianfun /* define message structures */
#include <vlibmemory/vl_memory_api_h.h>
#undef vl_endianfun
#define vl_calcsizefun
#include <vlibmemory/vl_memory_api_h.h>
#undef vl_calcsizefun
/* instantiate all the print functions we know about */
#define vl_printfun
#include <vlibmemory/vl_memory_api_h.h>
#undef vl_printfun
memory_client_main_t memory_client_main;
__thread memory_client_main_t *my_memory_client_main = &memory_client_main;
typedef struct rx_thread_fn_arg
{
api_main_t *am;
memory_client_main_t *mm;
} rx_thread_fn_arg_t;
static void *
rx_thread_fn (void *arg)
{
rx_thread_fn_arg_t *a = (rx_thread_fn_arg_t *) arg;
memory_client_main_t *mm;
svm_queue_t *q;
vlibapi_set_main (a->am);
vlibapi_set_memory_client_main (a->mm);
free (a);
mm = vlibapi_get_memory_client_main ();
q = vlibapi_get_main ()->vl_input_queue;
/* So we can make the rx thread terminate cleanly */
if (setjmp (mm->rx_thread_jmpbuf) == 0)
{
mm->rx_thread_jmpbuf_valid = 1;
clib_mem_set_thread_index ();
while (1)
vl_msg_api_queue_handler (q);
}
pthread_exit (0);
}
static void
vl_api_rx_thread_exit_t_handler (vl_api_rx_thread_exit_t * mp)
{
memory_client_main_t *mm = vlibapi_get_memory_client_main ();
if (mm->rx_thread_jmpbuf_valid)
longjmp (mm->rx_thread_jmpbuf, 1);
}
static void
vl_api_name_and_crc_free (void)
{
api_main_t *am = vlibapi_get_main ();
int i;
u8 **keys = 0;
hash_pair_t *hp;
if (!am->msg_index_by_name_and_crc)
return;
/* *INDENT-OFF* */
hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
({
vec_add1 (keys, (u8 *) hp->key);
}));
/* *INDENT-ON* */
for (i = 0;
|