summaryrefslogtreecommitdiffstats
path: root/src/vlib/global_funcs.h
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2021-03-26 13:06:13 +0100
committerDamjan Marion <damarion@cisco.com>2021-03-26 16:33:21 +0100
commit6ffb7c61899eb782416cbd2f117042a583f189f7 (patch)
treef6bd132d53b0aded6b235d13200dba2864afc7d8 /src/vlib/global_funcs.h
parent83f13e45bcd4b1018aa29bb6f32324c32f3a11a8 (diff)
vlib: introduce vlib_get_main_by_index(), vlib_get_n_threads()
Type: improvement Change-Id: If3da7d4338470912f37ff1794620418d928fb77f Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib/global_funcs.h')
-rw-r--r--src/vlib/global_funcs.h22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/vlib/global_funcs.h b/src/vlib/global_funcs.h
index 9dd01fbfb0d..b1d636f7ce4 100644
--- a/src/vlib/global_funcs.h
+++ b/src/vlib/global_funcs.h
@@ -19,15 +19,33 @@
#ifndef included_vlib_global_funcs_h_
#define included_vlib_global_funcs_h_
+always_inline u32
+vlib_get_n_threads ()
+{
+ return vec_len (vlib_mains);
+}
+
always_inline vlib_main_t *
-vlib_get_main (void)
+vlib_get_main_by_index (u32 thread_index)
{
vlib_main_t *vm;
- vm = vlib_mains[vlib_get_thread_index ()];
+ vm = vlib_mains[thread_index];
ASSERT (vm);
return vm;
}
+always_inline vlib_main_t *
+vlib_get_main (void)
+{
+ return vlib_get_main_by_index (vlib_get_thread_index ());
+}
+
+always_inline vlib_main_t *
+vlib_get_first_main (void)
+{
+ return vlib_get_main_by_index (0);
+}
+
always_inline vlib_thread_main_t *
vlib_get_thread_main ()
{