michael@0: #define JEMALLOC_MANGLE michael@0: #include "jemalloc_test.h" michael@0: michael@0: void * michael@0: je_thread_start(void *arg) michael@0: { michael@0: int err; michael@0: size_t sz; michael@0: bool e0, e1; michael@0: michael@0: sz = sizeof(bool); michael@0: if ((err = mallctl("thread.tcache.enabled", &e0, &sz, NULL, 0))) { michael@0: if (err == ENOENT) { michael@0: #ifdef JEMALLOC_TCACHE michael@0: assert(false); michael@0: #endif michael@0: } michael@0: goto label_return; michael@0: } michael@0: michael@0: if (e0) { michael@0: e1 = false; michael@0: assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) michael@0: == 0); michael@0: assert(e0); michael@0: } michael@0: michael@0: e1 = true; michael@0: assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); michael@0: assert(e0 == false); michael@0: michael@0: e1 = true; michael@0: assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); michael@0: assert(e0); michael@0: michael@0: e1 = false; michael@0: assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); michael@0: assert(e0); michael@0: michael@0: e1 = false; michael@0: assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); michael@0: assert(e0 == false); michael@0: michael@0: free(malloc(1)); michael@0: e1 = true; michael@0: assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); michael@0: assert(e0 == false); michael@0: michael@0: free(malloc(1)); michael@0: e1 = true; michael@0: assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); michael@0: assert(e0); michael@0: michael@0: free(malloc(1)); michael@0: e1 = false; michael@0: assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); michael@0: assert(e0); michael@0: michael@0: free(malloc(1)); michael@0: e1 = false; michael@0: assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); michael@0: assert(e0 == false); michael@0: michael@0: free(malloc(1)); michael@0: label_return: michael@0: return (NULL); michael@0: } michael@0: michael@0: int michael@0: main(void) michael@0: { michael@0: int ret = 0; michael@0: je_thread_t thread; michael@0: michael@0: malloc_printf("Test begin\n"); michael@0: michael@0: je_thread_start(NULL); michael@0: michael@0: je_thread_create(&thread, je_thread_start, NULL); michael@0: je_thread_join(thread, (void *)&ret); michael@0: michael@0: je_thread_start(NULL); michael@0: michael@0: je_thread_create(&thread, je_thread_start, NULL); michael@0: je_thread_join(thread, (void *)&ret); michael@0: michael@0: je_thread_start(NULL); michael@0: michael@0: malloc_printf("Test end\n"); michael@0: return (ret); michael@0: }