2
0

thread_tcache_enabled.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #define JEMALLOC_MANGLE
  2. #include "jemalloc_test.h"
  3. void *
  4. je_thread_start(void *arg)
  5. {
  6. int err;
  7. size_t sz;
  8. bool e0, e1;
  9. sz = sizeof(bool);
  10. if ((err = mallctl("thread.tcache.enabled", &e0, &sz, NULL, 0))) {
  11. if (err == ENOENT) {
  12. #ifdef JEMALLOC_TCACHE
  13. assert(false);
  14. #endif
  15. }
  16. goto label_return;
  17. }
  18. if (e0) {
  19. e1 = false;
  20. assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz)
  21. == 0);
  22. assert(e0);
  23. }
  24. e1 = true;
  25. assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
  26. assert(e0 == false);
  27. e1 = true;
  28. assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
  29. assert(e0);
  30. e1 = false;
  31. assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
  32. assert(e0);
  33. e1 = false;
  34. assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
  35. assert(e0 == false);
  36. free(malloc(1));
  37. e1 = true;
  38. assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
  39. assert(e0 == false);
  40. free(malloc(1));
  41. e1 = true;
  42. assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
  43. assert(e0);
  44. free(malloc(1));
  45. e1 = false;
  46. assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
  47. assert(e0);
  48. free(malloc(1));
  49. e1 = false;
  50. assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0);
  51. assert(e0 == false);
  52. free(malloc(1));
  53. label_return:
  54. return (NULL);
  55. }
  56. int
  57. main(void)
  58. {
  59. int ret = 0;
  60. je_thread_t thread;
  61. malloc_printf("Test begin\n");
  62. je_thread_start(NULL);
  63. je_thread_create(&thread, je_thread_start, NULL);
  64. je_thread_join(thread, (void *)&ret);
  65. je_thread_start(NULL);
  66. je_thread_create(&thread, je_thread_start, NULL);
  67. je_thread_join(thread, (void *)&ret);
  68. je_thread_start(NULL);
  69. malloc_printf("Test end\n");
  70. return (ret);
  71. }