]> git.saurik.com Git - redis.git/blob - deps/jemalloc/test/thread_arena.c
2ffdb5e800470630f786f9b267374103f5c51bc3
[redis.git] / deps / jemalloc / test / thread_arena.c
1 #define JEMALLOC_MANGLE
2 #include "jemalloc_test.h"
3
4 #define NTHREADS 10
5
6 void *
7 je_thread_start(void *arg)
8 {
9 unsigned main_arena_ind = *(unsigned *)arg;
10 void *p;
11 unsigned arena_ind;
12 size_t size;
13 int err;
14
15 p = malloc(1);
16 if (p == NULL) {
17 malloc_printf("%s(): Error in malloc()\n", __func__);
18 return (void *)1;
19 }
20
21 size = sizeof(arena_ind);
22 if ((err = mallctl("thread.arena", &arena_ind, &size, &main_arena_ind,
23 sizeof(main_arena_ind)))) {
24 malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
25 strerror(err));
26 return (void *)1;
27 }
28
29 size = sizeof(arena_ind);
30 if ((err = mallctl("thread.arena", &arena_ind, &size, NULL,
31 0))) {
32 malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
33 strerror(err));
34 return (void *)1;
35 }
36 assert(arena_ind == main_arena_ind);
37
38 return (NULL);
39 }
40
41 int
42 main(void)
43 {
44 int ret = 0;
45 void *p;
46 unsigned arena_ind;
47 size_t size;
48 int err;
49 je_thread_t threads[NTHREADS];
50 unsigned i;
51
52 malloc_printf("Test begin\n");
53
54 p = malloc(1);
55 if (p == NULL) {
56 malloc_printf("%s(): Error in malloc()\n", __func__);
57 ret = 1;
58 goto label_return;
59 }
60
61 size = sizeof(arena_ind);
62 if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 0))) {
63 malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
64 strerror(err));
65 ret = 1;
66 goto label_return;
67 }
68
69 for (i = 0; i < NTHREADS; i++) {
70 je_thread_create(&threads[i], je_thread_start,
71 (void *)&arena_ind);
72 }
73
74 for (i = 0; i < NTHREADS; i++)
75 je_thread_join(threads[i], (void *)&ret);
76
77 label_return:
78 malloc_printf("Test end\n");
79 return (ret);
80 }