Pin the calling thread to a dedicated jemalloc arena. Call this once at Data Plane core startup, before any allocations. Each core should get a unique `arena_index` (typically core ID). Returns the arena index that was assigned. On wasm32 the standard allocator is used and the supplied index is returned unchanged as a no-op.
(arena_index: u32)
| 102 | /// Returns the arena index that was assigned. On wasm32 the standard allocator |
| 103 | /// is used and the supplied index is returned unchanged as a no-op. |
| 104 | pub fn pin_thread_arena(arena_index: u32) -> Result<u32> { |
| 105 | #[cfg(not(target_arch = "wasm32"))] |
| 106 | { |
| 107 | let narenas = read_narenas()?; |
| 108 | |
| 109 | let target_arena = if (arena_index as usize) < narenas { |
| 110 | arena_index |
| 111 | } else { |
| 112 | create_arena()? |
| 113 | }; |
| 114 | |
| 115 | set_thread_arena(target_arena)?; |
| 116 | Ok(target_arena) |
| 117 | } |
| 118 | #[cfg(target_arch = "wasm32")] |
| 119 | { |
| 120 | // wasm32 uses the standard allocator; per-thread arena pinning is a no-op. |
| 121 | Ok(arena_index) |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /// Query the current number of jemalloc arenas. |
| 126 | #[cfg(not(target_arch = "wasm32"))] |