]>
Commit | Line | Data |
---|---|---|
a78e148b | 1 | #define JEMALLOC_MANGLE |
2 | #include "jemalloc_test.h" | |
3 | ||
4 | void * | |
4934f93d | 5 | je_thread_start(void *arg) |
a78e148b | 6 | { |
7 | int err; | |
8 | void *p; | |
9 | uint64_t a0, a1, d0, d1; | |
10 | uint64_t *ap0, *ap1, *dp0, *dp1; | |
11 | size_t sz, usize; | |
12 | ||
13 | sz = sizeof(a0); | |
4934f93d | 14 | if ((err = mallctl("thread.allocated", &a0, &sz, NULL, 0))) { |
a78e148b | 15 | if (err == ENOENT) { |
16 | #ifdef JEMALLOC_STATS | |
17 | assert(false); | |
18 | #endif | |
4934f93d | 19 | goto label_return; |
a78e148b | 20 | } |
4934f93d | 21 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, |
a78e148b | 22 | strerror(err)); |
23 | exit(1); | |
24 | } | |
25 | sz = sizeof(ap0); | |
4934f93d | 26 | if ((err = mallctl("thread.allocatedp", &ap0, &sz, NULL, 0))) { |
a78e148b | 27 | if (err == ENOENT) { |
28 | #ifdef JEMALLOC_STATS | |
29 | assert(false); | |
30 | #endif | |
4934f93d | 31 | goto label_return; |
a78e148b | 32 | } |
4934f93d | 33 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, |
a78e148b | 34 | strerror(err)); |
35 | exit(1); | |
36 | } | |
37 | assert(*ap0 == a0); | |
38 | ||
39 | sz = sizeof(d0); | |
4934f93d | 40 | if ((err = mallctl("thread.deallocated", &d0, &sz, NULL, 0))) { |
a78e148b | 41 | if (err == ENOENT) { |
42 | #ifdef JEMALLOC_STATS | |
43 | assert(false); | |
44 | #endif | |
4934f93d | 45 | goto label_return; |
a78e148b | 46 | } |
4934f93d | 47 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, |
a78e148b | 48 | strerror(err)); |
49 | exit(1); | |
50 | } | |
51 | sz = sizeof(dp0); | |
4934f93d | 52 | if ((err = mallctl("thread.deallocatedp", &dp0, &sz, NULL, 0))) { |
a78e148b | 53 | if (err == ENOENT) { |
54 | #ifdef JEMALLOC_STATS | |
55 | assert(false); | |
56 | #endif | |
4934f93d | 57 | goto label_return; |
a78e148b | 58 | } |
4934f93d | 59 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, |
a78e148b | 60 | strerror(err)); |
61 | exit(1); | |
62 | } | |
63 | assert(*dp0 == d0); | |
64 | ||
4934f93d | 65 | p = malloc(1); |
a78e148b | 66 | if (p == NULL) { |
4934f93d | 67 | malloc_printf("%s(): Error in malloc()\n", __func__); |
a78e148b | 68 | exit(1); |
69 | } | |
70 | ||
71 | sz = sizeof(a1); | |
4934f93d | 72 | mallctl("thread.allocated", &a1, &sz, NULL, 0); |
a78e148b | 73 | sz = sizeof(ap1); |
4934f93d | 74 | mallctl("thread.allocatedp", &ap1, &sz, NULL, 0); |
a78e148b | 75 | assert(*ap1 == a1); |
76 | assert(ap0 == ap1); | |
77 | ||
4934f93d | 78 | usize = malloc_usable_size(p); |
a78e148b | 79 | assert(a0 + usize <= a1); |
80 | ||
4934f93d | 81 | free(p); |
a78e148b | 82 | |
83 | sz = sizeof(d1); | |
4934f93d | 84 | mallctl("thread.deallocated", &d1, &sz, NULL, 0); |
a78e148b | 85 | sz = sizeof(dp1); |
4934f93d | 86 | mallctl("thread.deallocatedp", &dp1, &sz, NULL, 0); |
a78e148b | 87 | assert(*dp1 == d1); |
88 | assert(dp0 == dp1); | |
89 | ||
90 | assert(d0 + usize <= d1); | |
91 | ||
4934f93d | 92 | label_return: |
a78e148b | 93 | return (NULL); |
94 | } | |
95 | ||
96 | int | |
97 | main(void) | |
98 | { | |
99 | int ret = 0; | |
4934f93d | 100 | je_thread_t thread; |
a78e148b | 101 | |
4934f93d | 102 | malloc_printf("Test begin\n"); |
a78e148b | 103 | |
4934f93d | 104 | je_thread_start(NULL); |
a78e148b | 105 | |
4934f93d | 106 | je_thread_create(&thread, je_thread_start, NULL); |
107 | je_thread_join(thread, (void *)&ret); | |
a78e148b | 108 | |
4934f93d | 109 | je_thread_start(NULL); |
a78e148b | 110 | |
4934f93d | 111 | je_thread_create(&thread, je_thread_start, NULL); |
112 | je_thread_join(thread, (void *)&ret); | |
a78e148b | 113 | |
4934f93d | 114 | je_thread_start(NULL); |
a78e148b | 115 | |
4934f93d | 116 | malloc_printf("Test end\n"); |
a78e148b | 117 | return (ret); |
118 | } |