1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/memory/jemalloc/src/test/ALLOCM_ARENA.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 1.4 +#define JEMALLOC_MANGLE 1.5 +#include "jemalloc_test.h" 1.6 + 1.7 +#define NTHREADS 10 1.8 + 1.9 +void * 1.10 +je_thread_start(void *arg) 1.11 +{ 1.12 + unsigned thread_ind = (unsigned)(uintptr_t)arg; 1.13 + unsigned arena_ind; 1.14 + int r; 1.15 + void *p; 1.16 + size_t rsz, sz; 1.17 + 1.18 + sz = sizeof(arena_ind); 1.19 + if (mallctl("arenas.extend", &arena_ind, &sz, NULL, 0) 1.20 + != 0) { 1.21 + malloc_printf("Error in arenas.extend\n"); 1.22 + abort(); 1.23 + } 1.24 + 1.25 + if (thread_ind % 4 != 3) { 1.26 + size_t mib[3]; 1.27 + size_t miblen = sizeof(mib) / sizeof(size_t); 1.28 + const char *dss_precs[] = {"disabled", "primary", "secondary"}; 1.29 + const char *dss = dss_precs[thread_ind % 4]; 1.30 + if (mallctlnametomib("arena.0.dss", mib, &miblen) != 0) { 1.31 + malloc_printf("Error in mallctlnametomib()\n"); 1.32 + abort(); 1.33 + } 1.34 + mib[1] = arena_ind; 1.35 + if (mallctlbymib(mib, miblen, NULL, NULL, (void *)&dss, 1.36 + sizeof(const char *))) { 1.37 + malloc_printf("Error in mallctlbymib()\n"); 1.38 + abort(); 1.39 + } 1.40 + } 1.41 + 1.42 + r = allocm(&p, &rsz, 1, ALLOCM_ARENA(arena_ind)); 1.43 + if (r != ALLOCM_SUCCESS) { 1.44 + malloc_printf("Unexpected allocm() error\n"); 1.45 + abort(); 1.46 + } 1.47 + 1.48 + return (NULL); 1.49 +} 1.50 + 1.51 +int 1.52 +main(void) 1.53 +{ 1.54 + je_thread_t threads[NTHREADS]; 1.55 + unsigned i; 1.56 + 1.57 + malloc_printf("Test begin\n"); 1.58 + 1.59 + for (i = 0; i < NTHREADS; i++) { 1.60 + je_thread_create(&threads[i], je_thread_start, 1.61 + (void *)(uintptr_t)i); 1.62 + } 1.63 + 1.64 + for (i = 0; i < NTHREADS; i++) 1.65 + je_thread_join(threads[i], NULL); 1.66 + 1.67 + malloc_printf("Test end\n"); 1.68 + return (0); 1.69 +}