1
0
mirror of https://github.com/fluencelabs/redis synced 2025-07-15 08:41:34 +00:00
Files
deps
hiredis
jemalloc
bin
doc
include
src
test
aligned_alloc.c
aligned_alloc.exp
allocated.c
allocated.exp
allocm.c
allocm.exp
bitmap.c
bitmap.exp
jemalloc_test.h.in
mremap.c
mremap.exp
posix_memalign.c
posix_memalign.exp
rallocm.c
rallocm.exp
thread_arena.c
thread_arena.exp
thread_tcache_enabled.c
thread_tcache_enabled.exp
.gitignore
COPYING
ChangeLog
INSTALL
Makefile.in
README
VERSION
autogen.sh
config.guess
config.stamp.in
config.sub
configure
configure.ac
install-sh
linenoise
lua
Makefile
src
tests
utils
.gitignore
00-RELEASENOTES
BUGS
CONTRIBUTING
COPYING
Changelog
INSTALL
MANIFESTO
Makefile
README
redis.conf
runtest
redis/deps/jemalloc/test/allocated.c

119 lines
2.3 KiB
C
Raw Normal View History

2011-05-09 10:52:55 +02:00
#define JEMALLOC_MANGLE
#include "jemalloc_test.h"
void *
je_thread_start(void *arg)
2011-05-09 10:52:55 +02:00
{
int err;
void *p;
uint64_t a0, a1, d0, d1;
uint64_t *ap0, *ap1, *dp0, *dp1;
size_t sz, usize;
sz = sizeof(a0);
if ((err = mallctl("thread.allocated", &a0, &sz, NULL, 0))) {
2011-05-09 10:52:55 +02:00
if (err == ENOENT) {
#ifdef JEMALLOC_STATS
assert(false);
#endif
goto label_return;
2011-05-09 10:52:55 +02:00
}
malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
2011-05-09 10:52:55 +02:00
strerror(err));
exit(1);
}
sz = sizeof(ap0);
if ((err = mallctl("thread.allocatedp", &ap0, &sz, NULL, 0))) {
2011-05-09 10:52:55 +02:00
if (err == ENOENT) {
#ifdef JEMALLOC_STATS
assert(false);
#endif
goto label_return;
2011-05-09 10:52:55 +02:00
}
malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
2011-05-09 10:52:55 +02:00
strerror(err));
exit(1);
}
assert(*ap0 == a0);
sz = sizeof(d0);
if ((err = mallctl("thread.deallocated", &d0, &sz, NULL, 0))) {
2011-05-09 10:52:55 +02:00
if (err == ENOENT) {
#ifdef JEMALLOC_STATS
assert(false);
#endif
goto label_return;
2011-05-09 10:52:55 +02:00
}
malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
2011-05-09 10:52:55 +02:00
strerror(err));
exit(1);
}
sz = sizeof(dp0);
if ((err = mallctl("thread.deallocatedp", &dp0, &sz, NULL, 0))) {
2011-05-09 10:52:55 +02:00
if (err == ENOENT) {
#ifdef JEMALLOC_STATS
assert(false);
#endif
goto label_return;
2011-05-09 10:52:55 +02:00
}
malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
2011-05-09 10:52:55 +02:00
strerror(err));
exit(1);
}
assert(*dp0 == d0);
p = malloc(1);
2011-05-09 10:52:55 +02:00
if (p == NULL) {
malloc_printf("%s(): Error in malloc()\n", __func__);
2011-05-09 10:52:55 +02:00
exit(1);
}
sz = sizeof(a1);
mallctl("thread.allocated", &a1, &sz, NULL, 0);
2011-05-09 10:52:55 +02:00
sz = sizeof(ap1);
mallctl("thread.allocatedp", &ap1, &sz, NULL, 0);
2011-05-09 10:52:55 +02:00
assert(*ap1 == a1);
assert(ap0 == ap1);
usize = malloc_usable_size(p);
2011-05-09 10:52:55 +02:00
assert(a0 + usize <= a1);
free(p);
2011-05-09 10:52:55 +02:00
sz = sizeof(d1);
mallctl("thread.deallocated", &d1, &sz, NULL, 0);
2011-05-09 10:52:55 +02:00
sz = sizeof(dp1);
mallctl("thread.deallocatedp", &dp1, &sz, NULL, 0);
2011-05-09 10:52:55 +02:00
assert(*dp1 == d1);
assert(dp0 == dp1);
assert(d0 + usize <= d1);
label_return:
2011-05-09 10:52:55 +02:00
return (NULL);
}
int
main(void)
{
int ret = 0;
je_thread_t thread;
2011-05-09 10:52:55 +02:00
malloc_printf("Test begin\n");
2011-05-09 10:52:55 +02:00
je_thread_start(NULL);
2011-05-09 10:52:55 +02:00
je_thread_create(&thread, je_thread_start, NULL);
je_thread_join(thread, (void *)&ret);
2011-05-09 10:52:55 +02:00
je_thread_start(NULL);
2011-05-09 10:52:55 +02:00
je_thread_create(&thread, je_thread_start, NULL);
je_thread_join(thread, (void *)&ret);
2011-05-09 10:52:55 +02:00
je_thread_start(NULL);
2011-05-09 10:52:55 +02:00
malloc_printf("Test end\n");
2011-05-09 10:52:55 +02:00
return (ret);
}