2
0

MALLOCX_ARENA.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "test/jemalloc_test.h"
  2. #define NTHREADS 10
  3. static bool have_dss =
  4. #ifdef JEMALLOC_DSS
  5. true
  6. #else
  7. false
  8. #endif
  9. ;
  10. void *
  11. thd_start(void *arg)
  12. {
  13. unsigned thread_ind = (unsigned)(uintptr_t)arg;
  14. unsigned arena_ind;
  15. void *p;
  16. size_t sz;
  17. sz = sizeof(arena_ind);
  18. assert_d_eq(mallctl("arenas.extend", &arena_ind, &sz, NULL, 0), 0,
  19. "Error in arenas.extend");
  20. if (thread_ind % 4 != 3) {
  21. size_t mib[3];
  22. size_t miblen = sizeof(mib) / sizeof(size_t);
  23. const char *dss_precs[] = {"disabled", "primary", "secondary"};
  24. unsigned prec_ind = thread_ind %
  25. (sizeof(dss_precs)/sizeof(char*));
  26. const char *dss = dss_precs[prec_ind];
  27. int expected_err = (have_dss || prec_ind == 0) ? 0 : EFAULT;
  28. assert_d_eq(mallctlnametomib("arena.0.dss", mib, &miblen), 0,
  29. "Error in mallctlnametomib()");
  30. mib[1] = arena_ind;
  31. assert_d_eq(mallctlbymib(mib, miblen, NULL, NULL, (void *)&dss,
  32. sizeof(const char *)), expected_err,
  33. "Error in mallctlbymib()");
  34. }
  35. p = mallocx(1, MALLOCX_ARENA(arena_ind));
  36. assert_ptr_not_null(p, "Unexpected mallocx() error");
  37. dallocx(p, 0);
  38. return (NULL);
  39. }
  40. TEST_BEGIN(test_MALLOCX_ARENA)
  41. {
  42. thd_t thds[NTHREADS];
  43. unsigned i;
  44. for (i = 0; i < NTHREADS; i++) {
  45. thd_create(&thds[i], thd_start,
  46. (void *)(uintptr_t)i);
  47. }
  48. for (i = 0; i < NTHREADS; i++)
  49. thd_join(thds[i], NULL);
  50. }
  51. TEST_END
  52. int
  53. main(void)
  54. {
  55. return (test(
  56. test_MALLOCX_ARENA));
  57. }