]>
Commit | Line | Data |
---|---|---|
a78e148b | 1 | #define JEMALLOC_MANGLE |
2 | #include "jemalloc_test.h" | |
3 | ||
4 | #define NTHREADS 10 | |
5 | ||
6 | void * | |
4934f93d | 7 | je_thread_start(void *arg) |
a78e148b | 8 | { |
9 | unsigned main_arena_ind = *(unsigned *)arg; | |
10 | void *p; | |
11 | unsigned arena_ind; | |
12 | size_t size; | |
13 | int err; | |
14 | ||
4934f93d | 15 | p = malloc(1); |
a78e148b | 16 | if (p == NULL) { |
4934f93d | 17 | malloc_printf("%s(): Error in malloc()\n", __func__); |
a78e148b | 18 | return (void *)1; |
19 | } | |
20 | ||
21 | size = sizeof(arena_ind); | |
4934f93d | 22 | if ((err = mallctl("thread.arena", &arena_ind, &size, &main_arena_ind, |
23 | sizeof(main_arena_ind)))) { | |
24 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, | |
a78e148b | 25 | strerror(err)); |
26 | return (void *)1; | |
27 | } | |
28 | ||
29 | size = sizeof(arena_ind); | |
4934f93d | 30 | if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, |
a78e148b | 31 | 0))) { |
4934f93d | 32 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, |
a78e148b | 33 | strerror(err)); |
34 | return (void *)1; | |
35 | } | |
36 | assert(arena_ind == main_arena_ind); | |
37 | ||
38 | return (NULL); | |
39 | } | |
40 | ||
41 | int | |
42 | main(void) | |
43 | { | |
44 | int ret = 0; | |
45 | void *p; | |
46 | unsigned arena_ind; | |
47 | size_t size; | |
48 | int err; | |
4934f93d | 49 | je_thread_t threads[NTHREADS]; |
a78e148b | 50 | unsigned i; |
51 | ||
4934f93d | 52 | malloc_printf("Test begin\n"); |
a78e148b | 53 | |
4934f93d | 54 | p = malloc(1); |
a78e148b | 55 | if (p == NULL) { |
4934f93d | 56 | malloc_printf("%s(): Error in malloc()\n", __func__); |
a78e148b | 57 | ret = 1; |
4934f93d | 58 | goto label_return; |
a78e148b | 59 | } |
60 | ||
61 | size = sizeof(arena_ind); | |
4934f93d | 62 | if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 0))) { |
63 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, | |
a78e148b | 64 | strerror(err)); |
65 | ret = 1; | |
4934f93d | 66 | goto label_return; |
a78e148b | 67 | } |
68 | ||
4934f93d | 69 | for (i = 0; i < NTHREADS; i++) |
70 | je_thread_create(&threads[i], je_thread_start, (void *)&arena_ind); | |
a78e148b | 71 | |
72 | for (i = 0; i < NTHREADS; i++) | |
4934f93d | 73 | je_thread_join(threads[i], (void *)&ret); |
a78e148b | 74 | |
4934f93d | 75 | label_return: |
76 | malloc_printf("Test end\n"); | |
a78e148b | 77 | return (ret); |
78 | } |