]>
Commit | Line | Data |
---|---|---|
21b26915 | 1 | #define JEMALLOC_MANGLE |
2 | #include "jemalloc_test.h" | |
3 | ||
4 | #define NTHREADS 10 | |
5 | ||
6 | void * | |
7 | je_thread_start(void *arg) | |
8 | { | |
9 | unsigned thread_ind = (unsigned)(uintptr_t)arg; | |
10 | unsigned arena_ind; | |
11 | int r; | |
12 | void *p; | |
13 | size_t rsz, sz; | |
14 | ||
15 | sz = sizeof(arena_ind); | |
16 | if (mallctl("arenas.extend", &arena_ind, &sz, NULL, 0) | |
17 | != 0) { | |
18 | malloc_printf("Error in arenas.extend\n"); | |
19 | abort(); | |
20 | } | |
21 | ||
22 | if (thread_ind % 4 != 3) { | |
23 | size_t mib[3]; | |
24 | size_t miblen = sizeof(mib) / sizeof(size_t); | |
25 | const char *dss_precs[] = {"disabled", "primary", "secondary"}; | |
26 | const char *dss = dss_precs[thread_ind % 4]; | |
27 | if (mallctlnametomib("arena.0.dss", mib, &miblen) != 0) { | |
28 | malloc_printf("Error in mallctlnametomib()\n"); | |
29 | abort(); | |
30 | } | |
31 | mib[1] = arena_ind; | |
32 | if (mallctlbymib(mib, miblen, NULL, NULL, (void *)&dss, | |
33 | sizeof(const char *))) { | |
34 | malloc_printf("Error in mallctlbymib()\n"); | |
35 | abort(); | |
36 | } | |
37 | } | |
38 | ||
39 | r = allocm(&p, &rsz, 1, ALLOCM_ARENA(arena_ind)); | |
40 | if (r != ALLOCM_SUCCESS) { | |
41 | malloc_printf("Unexpected allocm() error\n"); | |
42 | abort(); | |
43 | } | |
44 | ||
45 | return (NULL); | |
46 | } | |
47 | ||
48 | int | |
49 | main(void) | |
50 | { | |
51 | je_thread_t threads[NTHREADS]; | |
52 | unsigned i; | |
53 | ||
54 | malloc_printf("Test begin\n"); | |
55 | ||
56 | for (i = 0; i < NTHREADS; i++) { | |
57 | je_thread_create(&threads[i], je_thread_start, | |
58 | (void *)(uintptr_t)i); | |
59 | } | |
60 | ||
61 | for (i = 0; i < NTHREADS; i++) | |
62 | je_thread_join(threads[i], NULL); | |
63 | ||
64 | malloc_printf("Test end\n"); | |
65 | return (0); | |
66 | } |