aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlibmemory/memory_shared.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-11-27 11:42:13 -0500
committerFlorin Coras <florin.coras@gmail.com>2019-12-10 01:13:05 +0000
commit39d69112fcec114fde34955ceb41555221d3ba11 (patch)
tree156f21a0e66bf596b2c1e5184d82c80d99ea0a79 /src/vlibmemory/memory_shared.c
parent6b3f25caff262b536a5449ac5461dd041c92a655 (diff)
api: multiple connections per process
Type: feature Signed-off-by: Dave Barach <dave@barachs.net> Change-Id: I2272521d6e69edcd385ef684af6dd4eea5eaa953
Diffstat (limited to 'src/vlibmemory/memory_shared.c')
-rw-r--r--src/vlibmemory/memory_shared.c52
1 files changed, 28 insertions, 24 deletions
diff --git a/src/vlibmemory/memory_shared.c b/src/vlibmemory/memory_shared.c
index b927f95f17b..0b232adf899 100644
--- a/src/vlibmemory/memory_shared.c
+++ b/src/vlibmemory/memory_shared.c
@@ -35,6 +35,7 @@
#include <vlib/unix/unix.h>
#include <vlibmemory/memory_api.h>
#include <vlibmemory/vl_memory_msg_enum.h>
+#include <vlibapi/api_common.h>
#define vl_typedefs
#include <vlibmemory/vl_memory_api_h.h>
@@ -52,7 +53,7 @@ vl_msg_api_alloc_internal (svm_region_t * vlib_rp, int nbytes, int pool,
svm_queue_t *q;
void *oldheap;
vl_shmem_hdr_t *shmem_hdr;
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
shmem_hdr = (void *) vlib_rp->user_ctx;
@@ -121,9 +122,9 @@ vl_msg_api_alloc_internal (svm_region_t * vlib_rp, int nbytes, int pool,
q->head);
msg_idp = (u16 *) (rv->data);
msg_id = clib_net_to_host_u16 (*msg_idp);
- if (msg_id < vec_len (api_main.msg_names))
+ if (msg_id < vec_len (vlibapi_get_main ()->msg_names))
clib_warning ("msg id %d name %s", (u32) msg_id,
- api_main.msg_names[msg_id]);
+ vlibapi_get_main ()->msg_names[msg_id]);
}
shmem_hdr->garbage_collects++;
goto collected;
@@ -201,7 +202,7 @@ void *
vl_msg_api_alloc (int nbytes)
{
int pool;
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
/*
@@ -226,7 +227,7 @@ void *
vl_msg_api_alloc_or_null (int nbytes)
{
int pool;
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
pool = (am->our_pid == shmem_hdr->vl_pid);
@@ -237,7 +238,8 @@ vl_msg_api_alloc_or_null (int nbytes)
void *
vl_msg_api_alloc_as_if_client (int nbytes)
{
- return vl_msg_api_alloc_internal (api_main.vlib_rp, nbytes, 0,
+ api_main_t *am = vlibapi_get_main ();
+ return vl_msg_api_alloc_internal (am->vlib_rp, nbytes, 0,
0 /* may_return_null */ );
}
@@ -254,7 +256,8 @@ vl_msg_api_alloc_zero_as_if_client (int nbytes)
void *
vl_msg_api_alloc_as_if_client_or_null (int nbytes)
{
- return vl_msg_api_alloc_internal (api_main.vlib_rp, nbytes, 0,
+ api_main_t *am = vlibapi_get_main ();
+ return vl_msg_api_alloc_internal (am->vlib_rp, nbytes, 0,
1 /* may_return_null */ );
}
@@ -312,7 +315,8 @@ vl_msg_api_free_w_region (svm_region_t * vlib_rp, void *a)
void
vl_msg_api_free (void *a)
{
- vl_msg_api_free_w_region (api_main.vlib_rp, a);
+ api_main_t *am = vlibapi_get_main ();
+ vl_msg_api_free_w_region (am->vlib_rp, a);
}
static void
@@ -320,7 +324,7 @@ vl_msg_api_free_nolock (void *a)
{
msgbuf_t *rv;
void *oldheap;
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
rv = (msgbuf_t *) (((u8 *) a) - offsetof (msgbuf_t, data));
/*
@@ -343,7 +347,7 @@ vl_msg_api_free_nolock (void *a)
void
vl_set_memory_root_path (const char *name)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
am->root_path = name;
}
@@ -351,7 +355,7 @@ vl_set_memory_root_path (const char *name)
void
vl_set_memory_uid (int uid)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
am->api_uid = uid;
}
@@ -359,7 +363,7 @@ vl_set_memory_uid (int uid)
void
vl_set_memory_gid (int gid)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
am->api_gid = gid;
}
@@ -367,7 +371,7 @@ vl_set_memory_gid (int gid)
void
vl_set_global_memory_baseva (u64 baseva)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
am->global_baseva = baseva;
}
@@ -375,7 +379,7 @@ vl_set_global_memory_baseva (u64 baseva)
void
vl_set_global_memory_size (u64 size)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
am->global_size = size;
}
@@ -383,7 +387,7 @@ vl_set_global_memory_size (u64 size)
void
vl_set_api_memory_size (u64 size)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
am->api_size = size;
}
@@ -391,7 +395,7 @@ vl_set_api_memory_size (u64 size)
void
vl_set_global_pvt_heap_size (u64 size)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
am->global_pvt_heap_size = size;
}
@@ -399,7 +403,7 @@ vl_set_global_pvt_heap_size (u64 size)
void
vl_set_api_pvt_heap_size (u64 size)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
am->api_pvt_heap_size = size;
}
@@ -407,7 +411,7 @@ vl_set_api_pvt_heap_size (u64 size)
static void
vl_api_default_mem_config (vl_shmem_hdr_t * shmem_hdr)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
u32 vlib_input_queue_length;
/* vlib main input queue */
@@ -493,7 +497,7 @@ void
vl_init_shmem (svm_region_t * vlib_rp, vl_api_shm_elem_config_t * config,
int is_vlib, int is_private_region)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
vl_shmem_hdr_t *shmem_hdr = 0;
void *oldheap;
ASSERT (vlib_rp);
@@ -536,7 +540,7 @@ vl_map_shmem (const char *region_name, int is_vlib)
{
svm_map_region_args_t _a, *a = &_a;
svm_region_t *vlib_rp, *root_rp;
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
int i;
struct timespec ts, tsrem;
char *vpe_api_region_suffix = "-vpe-api";
@@ -706,7 +710,7 @@ vl_map_shmem (const char *region_name, int is_vlib)
void
vl_register_mapped_shmem_region (svm_region_t * rp)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
vec_add1 (am->mapped_shmem_regions, rp);
}
@@ -716,7 +720,7 @@ vl_unmap_shmem_internal (u8 is_client)
{
svm_region_t *rp;
int i;
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
if (!svm_get_root_rp ())
return;
@@ -753,7 +757,7 @@ vl_unmap_shmem_client (void)
void
vl_msg_api_send_shmem (svm_queue_t * q, u8 * elem)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
void *msg = (void *) *(uword *) elem;
if (am->tx_trace && am->tx_trace->enabled)
@@ -800,7 +804,7 @@ vl_mem_api_can_send (svm_queue_t * q)
void
vl_msg_api_send_shmem_nolock (svm_queue_t * q, u8 * elem)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
void *msg = (void *) *(uword *) elem;
if (am->tx_trace && am->tx_trace->enabled)