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