2
0

MALLOCX_ARENA.c 1.2 KB

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