a10146c53a5c2522e5ae66c95d38a0c6195b6be7
[vpp.git] / vnet / vnet / ip / adj_alloc.h
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef __adj_alloc_h__
17 #define __adj_alloc_h__
18
19 /* 
20  * Adjacency allocator: heap-like in that the code
21  * will dole out contiguous chunks of n items. In the interests of 
22  * thread safety, we don't bother about coalescing free blocks of size r
23  * into free blocks of size s, where r < s.
24  * 
25  * We include explicit references to worker thread barrier synchronization
26  * where necessary.  
27  */ 
28
29 #include <vppinfra/vec.h>
30 #include <vlib/vlib.h>
31 #include <vnet/ip/lookup.h>
32
33 typedef struct {
34   u32 ** free_indices_by_size;
35 } aa_header_t;
36
37 #define aa_aligned_header_bytes \
38   vec_aligned_header_bytes (sizeof (aa_header_t), sizeof (void *))
39
40 /* Pool header from user pointer */
41 static inline aa_header_t * aa_header (void * v)
42 {
43   return vec_aligned_header (v, sizeof (aa_header_t), sizeof (void *));
44 }
45
46 ip_adjacency_t * 
47 aa_alloc (ip_adjacency_t * adjs, ip_adjacency_t **blockp, u32 n);
48 void aa_free (ip_adjacency_t * adjs, ip_adjacency_t * adj);
49 ip_adjacency_t * aa_bootstrap (ip_adjacency_t * adjs, u32 n);
50
51 format_function_t format_adj_allocation;
52
53 #endif /* __adj_alloc_h__ */