X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Fmem.h;h=f2930a11253310ac2b807c027627a71a342a69dc;hb=dd4d8ac29202fe54e74a13ce86d1ba3f79d1555f;hp=e31ec82e7c5cd7e0f59e45bdedb90ed3b2c556c8;hpb=d67a428b3b2183cd78d7fca82e8afe2f26387810;p=vpp.git diff --git a/src/vppinfra/mem.h b/src/vppinfra/mem.h index e31ec82e7c5..f2930a11253 100644 --- a/src/vppinfra/mem.h +++ b/src/vppinfra/mem.h @@ -60,6 +60,27 @@ /* Per CPU heaps. */ extern void *clib_per_cpu_mheaps[CLIB_MAX_MHEAPS]; +always_inline void +clib_mem_set_thread_index (void) +{ + /* + * Find an unused slot in the per-cpu-mheaps array, + * and grab it for this thread. We need to be able to + * push/pop the thread heap without affecting other thread(s). + */ + int i; + if (__os_thread_index != 0) + return; + for (i = 0; i < ARRAY_LEN (clib_per_cpu_mheaps); i++) + if (clib_atomic_bool_cmp_and_swap (&clib_per_cpu_mheaps[i], + 0, clib_per_cpu_mheaps[0])) + { + os_set_thread_index (i); + break; + } + ASSERT (__os_thread_index > 0); +} + always_inline void * clib_mem_get_per_cpu_heap (void) {