aboutsummaryrefslogtreecommitdiffstats
path: root/vnet/vnet/ip/adj_alloc.h
blob: a10146c53a5c2522e5ae66c95d38a0c6195b6be7 (plain)
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
/*
 * Copyright (c) 2016 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.
 */

#ifndef __adj_alloc_h__
#define __adj_alloc_h__

/* 
 * Adjacency allocator: heap-like in that the code
 * will dole out contiguous chunks of n items. In the interests of 
 * thread safety, we don't bother about coalescing free blocks of size r
 * into free blocks of size s, where r < s.
 * 
 * We include explicit references to worker thread barrier synchronization
 * where necessary.  
 */ 

#include <vppinfra/vec.h>
#include <vlib/vlib.h>
#include <vnet/ip/lookup.h>

typedef struct {
  u32 ** free_indices_by_size;
} aa_header_t;

#define aa_aligned_header_bytes \
  vec_aligned_header_bytes (sizeof (aa_header_t), sizeof (void *))

/* Pool header from user pointer */
static inline aa_header_t * aa_header (void * v)
{
  return vec_aligned_header (v, sizeof (aa_header_t), sizeof (void *));
}

ip_adjacency_t * 
aa_alloc (ip_adjacency_t * adjs, ip_adjacency_t **blockp, u32 n);
void aa_free (ip_adjacency_t * adjs, ip_adjacency_t * adj);
ip_adjacency_t * aa_bootstrap (ip_adjacency_t * adjs, u32 n);

format_function_t format_adj_allocation;

#endif /* __adj_alloc_h__ */