]>
git.saurik.com Git - redis.git/blob - deps/jemalloc/test/allocated.c
10 #define JEMALLOC_MANGLE
11 #include "jemalloc_test.h"
14 thread_start(void *arg
)
18 uint64_t a0
, a1
, d0
, d1
;
19 uint64_t *ap0
, *ap1
, *dp0
, *dp1
;
23 if ((err
= JEMALLOC_P(mallctl
)("thread.allocated", &a0
, &sz
, NULL
,
31 fprintf(stderr
, "%s(): Error in mallctl(): %s\n", __func__
,
36 if ((err
= JEMALLOC_P(mallctl
)("thread.allocatedp", &ap0
, &sz
, NULL
,
44 fprintf(stderr
, "%s(): Error in mallctl(): %s\n", __func__
,
51 if ((err
= JEMALLOC_P(mallctl
)("thread.deallocated", &d0
, &sz
, NULL
,
59 fprintf(stderr
, "%s(): Error in mallctl(): %s\n", __func__
,
64 if ((err
= JEMALLOC_P(mallctl
)("thread.deallocatedp", &dp0
, &sz
, NULL
,
72 fprintf(stderr
, "%s(): Error in mallctl(): %s\n", __func__
,
78 p
= JEMALLOC_P(malloc
)(1);
80 fprintf(stderr
, "%s(): Error in malloc()\n", __func__
);
85 JEMALLOC_P(mallctl
)("thread.allocated", &a1
, &sz
, NULL
, 0);
87 JEMALLOC_P(mallctl
)("thread.allocatedp", &ap1
, &sz
, NULL
, 0);
91 usize
= JEMALLOC_P(malloc_usable_size
)(p
);
92 assert(a0
+ usize
<= a1
);
97 JEMALLOC_P(mallctl
)("thread.deallocated", &d1
, &sz
, NULL
, 0);
99 JEMALLOC_P(mallctl
)("thread.deallocatedp", &dp1
, &sz
, NULL
, 0);
103 assert(d0
+ usize
<= d1
);
115 fprintf(stderr
, "Test begin\n");
119 if (pthread_create(&thread
, NULL
, thread_start
, NULL
)
121 fprintf(stderr
, "%s(): Error in pthread_create()\n", __func__
);
125 pthread_join(thread
, (void *)&ret
);
129 if (pthread_create(&thread
, NULL
, thread_start
, NULL
)
131 fprintf(stderr
, "%s(): Error in pthread_create()\n", __func__
);
135 pthread_join(thread
, (void *)&ret
);
140 fprintf(stderr
, "Test end\n");