Commit be70861b authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

fix the data races in toku_malloc and toku_free. closes #1369

git-svn-id: file:///svn/toku/tokudb.1032b+1343@8620 c7de825b-a66e-492c-adef-691d508d4ae1
parent 0dfc3aa5
CPPFLAGS = -I../../include -I.. CPPFLAGS = -I../../include -I..
CFLAGS = -Wall -Werror -g -O0 CFLAGS = -Wall -Werror -g -O0
LDFLAGS = ../libtokuportability.a LDFLAGS = ../libtokuportability.a -lpthread
SRCS = $(wildcard test-*.c) SRCS = $(wildcard test-*.c)
TARGETS = $(patsubst %.c,%,$(SRCS)) TARGETS = $(patsubst %.c,%,$(SRCS))
......
#include <stdio.h>
#include <assert.h>
#include <memory.h>
#include <toku_pthread.h>
void *f(void *arg) {
void *vp = toku_malloc(32);
assert(vp);
toku_free(vp);
return arg;
}
int main(void) {
int r;
int i;
const int max_threads = 2;
toku_pthread_t tids[max_threads];
for (i=0; i<max_threads; i++) {
r = toku_pthread_create(&tids[i], NULL, f, 0); assert(r == 0);
}
for (i=0; i<max_threads; i++) {
void *ret;
r = toku_pthread_join(tids[i], &ret); assert(r == 0);
}
return 0;
}
...@@ -144,7 +144,7 @@ test_main(int argc, const char *argv[]) { ...@@ -144,7 +144,7 @@ test_main(int argc, const char *argv[]) {
test_db_delete(0, 0); test_db_delete(0, 0);
int i; int i;
for (i = 1; i <= (1<<16); i *= 2) { for (i = 1; i <= (1<<8); i *= 2) {
test_db_delete(i, 0); test_db_delete(i, 0);
} }
......
...@@ -6,11 +6,6 @@ ...@@ -6,11 +6,6 @@
int toku_memory_check=0; int toku_memory_check=0;
int toku_calloc_counter = 0;
int toku_malloc_counter = 0;
int toku_realloc_counter = 0;
int toku_free_counter = 0;
typedef void *(*malloc_fun_t)(size_t); typedef void *(*malloc_fun_t)(size_t);
typedef void (*free_fun_t)(void*); typedef void (*free_fun_t)(void*);
typedef void *(*realloc_fun_t)(void*,size_t); typedef void *(*realloc_fun_t)(void*,size_t);
...@@ -20,7 +15,6 @@ static free_fun_t t_free = 0; ...@@ -20,7 +15,6 @@ static free_fun_t t_free = 0;
static realloc_fun_t t_realloc = 0; static realloc_fun_t t_realloc = 0;
void *toku_malloc(size_t size) { void *toku_malloc(size_t size) {
toku_malloc_counter++;
if (t_malloc) if (t_malloc)
return t_malloc(size); return t_malloc(size);
else else
...@@ -31,7 +25,6 @@ void * ...@@ -31,7 +25,6 @@ void *
toku_calloc(size_t nmemb, size_t size) toku_calloc(size_t nmemb, size_t size)
{ {
size_t newsize = nmemb * size; size_t newsize = nmemb * size;
toku_calloc_counter++;
void *vp = toku_malloc(newsize); void *vp = toku_malloc(newsize);
if (vp) memset(vp, 0, newsize); if (vp) memset(vp, 0, newsize);
return vp; return vp;
...@@ -66,7 +59,6 @@ toku_tagmalloc(size_t size, enum typ_tag typtag) ...@@ -66,7 +59,6 @@ toku_tagmalloc(size_t size, enum typ_tag typtag)
void * void *
toku_realloc(void *p, size_t size) toku_realloc(void *p, size_t size)
{ {
toku_realloc_counter++;
if (t_realloc) if (t_realloc)
return t_realloc(p, size); return t_realloc(p, size);
else else
...@@ -76,7 +68,6 @@ toku_realloc(void *p, size_t size) ...@@ -76,7 +68,6 @@ toku_realloc(void *p, size_t size)
void void
toku_free(void* p) toku_free(void* p)
{ {
(void)__sync_fetch_and_add(&toku_free_counter, 1);
if (t_free) if (t_free)
t_free(p); t_free(p);
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment