]> git.saurik.com Git - redis.git/blob - deps/jemalloc/test/thread_tcache_enabled.c
Jemalloc updated to 3.0.0.
[redis.git] / deps / jemalloc / test / thread_tcache_enabled.c
1 #define JEMALLOC_MANGLE
2 #include "jemalloc_test.h"
3
4 void *
5 je_thread_start(void *arg)
6 {
7 int err;
8 size_t sz;
9 bool e0, e1;
10
11 sz = sizeof(bool);
12 if ((err = mallctl("thread.tcache.enabled", &e0, &sz, NULL, 0))) {
13 if (err == ENOENT) {
14 #ifdef JEMALLOC_TCACHE
15 assert(false);
16 #endif
17 }
18 goto label_return;
19 }
20
21 if (e0) {
22 e1 = false;
23 assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz)
24 == 0);
25 assert(e0);
26 }
27
28 e1 = true;
29 assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
30 assert(e0 == false);
31
32 e1 = true;
33 assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
34 assert(e0);
35
36 e1 = false;
37 assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
38 assert(e0);
39
40 e1 = false;
41 assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
42 assert(e0 == false);
43
44 free(malloc(1));
45 e1 = true;
46 assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
47 assert(e0 == false);
48
49 free(malloc(1));
50 e1 = true;
51 assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
52 assert(e0);
53
54 free(malloc(1));
55 e1 = false;
56 assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
57 assert(e0);
58
59 free(malloc(1));
60 e1 = false;
61 assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
62 assert(e0 == false);
63
64 free(malloc(1));
65 label_return:
66 return (NULL);
67 }
68
69 int
70 main(void)
71 {
72 int ret = 0;
73 je_thread_t thread;
74
75 malloc_printf("Test begin\n");
76
77 je_thread_start(NULL);
78
79 je_thread_create(&thread, je_thread_start, NULL);
80 je_thread_join(thread, (void *)&ret);
81
82 je_thread_start(NULL);
83
84 je_thread_create(&thread, je_thread_start, NULL);
85 je_thread_join(thread, (void *)&ret);
86
87 je_thread_start(NULL);
88
89 malloc_printf("Test end\n");
90 return (ret);
91 }