Commit 3f6fe2be authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

refs[t:2656] fix some data races in the brtloader tests

git-svn-id: file:///svn/toku/tokudb@20660 c7de825b-a66e-492c-adef-691d508d4ae1
parent 6d894d3f
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#if 0
}
#endif
#endif #endif
static int event_count, event_count_trigger; static int event_count, event_count_trigger;
...@@ -26,11 +29,15 @@ static void reset_event_counts(void) { ...@@ -26,11 +29,15 @@ static void reset_event_counts(void) {
static void event_hit(void) { static void event_hit(void) {
} }
static int event_add_and_fetch(void) {
return __sync_add_and_fetch(&event_count, 1);
}
static int do_user_errors = 0; static int do_user_errors = 0;
static int loader_poll_callback(void *UU(extra), float UU(progress)) { static int loader_poll_callback(void *UU(extra), float UU(progress)) {
int r; int r;
if (do_user_errors && event_count_trigger == ++event_count) { if (do_user_errors && event_count_trigger == event_add_and_fetch()) {
event_hit(); event_hit();
r = 1; r = 1;
} else { } else {
...@@ -43,7 +50,7 @@ static int do_write_errors = 0; ...@@ -43,7 +50,7 @@ static int do_write_errors = 0;
static size_t bad_fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream) { static size_t bad_fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t r; size_t r;
if (do_write_errors && event_count_trigger == ++event_count) { if (do_write_errors && event_count_trigger == event_add_and_fetch()) {
event_hit(); event_hit();
errno = ENOSPC; errno = ENOSPC;
r = -1; r = -1;
...@@ -58,7 +65,7 @@ static size_t bad_fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stre ...@@ -58,7 +65,7 @@ static size_t bad_fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stre
static ssize_t bad_write(int fd, const void * bp, size_t len) { static ssize_t bad_write(int fd, const void * bp, size_t len) {
ssize_t r; ssize_t r;
if (do_write_errors && event_count_trigger == ++event_count) { if (do_write_errors && event_count_trigger == event_add_and_fetch()) {
event_hit(); event_hit();
errno = ENOSPC; errno = ENOSPC;
r = -1; r = -1;
...@@ -70,7 +77,7 @@ static ssize_t bad_write(int fd, const void * bp, size_t len) { ...@@ -70,7 +77,7 @@ static ssize_t bad_write(int fd, const void * bp, size_t len) {
static ssize_t bad_pwrite(int fd, const void * bp, size_t len, toku_off_t off) { static ssize_t bad_pwrite(int fd, const void * bp, size_t len, toku_off_t off) {
ssize_t r; ssize_t r;
if (do_write_errors && event_count_trigger == ++event_count) { if (do_write_errors && event_count_trigger == event_add_and_fetch()) {
event_hit(); event_hit();
errno = ENOSPC; errno = ENOSPC;
r = -1; r = -1;
...@@ -94,15 +101,14 @@ static void *my_malloc(size_t n) { ...@@ -94,15 +101,14 @@ static void *my_malloc(size_t n) {
void *caller = __builtin_return_address(0); void *caller = __builtin_return_address(0);
if (!((void*)toku_malloc <= caller && caller <= (void*)toku_free)) if (!((void*)toku_malloc <= caller && caller <= (void*)toku_free))
goto skip; goto skip;
my_malloc_count++; (void) __sync_add_and_fetch(&my_malloc_count, 1); // my_malloc_count++;
if (n >= my_big_malloc_limit) { if (n >= my_big_malloc_limit) {
my_big_malloc_count++; (void) __sync_add_and_fetch(&my_big_malloc_count, 1); // my_big_malloc_count++;
if (do_malloc_errors) { if (do_malloc_errors) {
caller = __builtin_return_address(1); caller = __builtin_return_address(1);
if ((void*)toku_xmalloc <= caller && caller <= (void*)toku_malloc_report) if ((void*)toku_xmalloc <= caller && caller <= (void*)toku_malloc_report)
goto skip; goto skip;
event_count++; if (event_add_and_fetch()== event_count_trigger) {
if (event_count == event_count_trigger) {
event_hit(); event_hit();
errno = ENOMEM; errno = ENOMEM;
return NULL; return NULL;
...@@ -113,19 +119,20 @@ static void *my_malloc(size_t n) { ...@@ -113,19 +119,20 @@ static void *my_malloc(size_t n) {
return malloc(n); return malloc(n);
} }
static int do_realloc_errors = 0;
static void *my_realloc(void *p, size_t n) { static void *my_realloc(void *p, size_t n) {
void *caller = __builtin_return_address(0); void *caller = __builtin_return_address(0);
if (!((void*)toku_realloc <= caller && caller <= (void*)toku_free)) if (!((void*)toku_realloc <= caller && caller <= (void*)toku_free))
goto skip; goto skip;
my_realloc_count++; (void) __sync_add_and_fetch(&my_realloc_count, 1); // my_realloc_count++;
if (n >= my_big_malloc_limit) { if (n >= my_big_malloc_limit) {
my_big_realloc_count++; (void) __sync_add_and_fetch(&my_big_realloc_count, 1); // my_big_realloc_count++;
if (do_malloc_errors) { if (do_realloc_errors) {
caller = __builtin_return_address(1); caller = __builtin_return_address(1);
if ((void*)toku_xrealloc <= caller && caller <= (void*)toku_malloc_report) if ((void*)toku_xrealloc <= caller && caller <= (void*)toku_malloc_report)
goto skip; goto skip;
event_count++; if (event_add_and_fetch() == event_count_trigger) {
if (event_count == event_count_trigger) {
event_hit(); event_hit();
errno = ENOMEM; errno = ENOMEM;
return NULL; return NULL;
......
...@@ -123,9 +123,9 @@ static void *my_realloc(void *p, size_t n) { ...@@ -123,9 +123,9 @@ static void *my_realloc(void *p, size_t n) {
void *caller = __builtin_return_address(0); void *caller = __builtin_return_address(0);
if (!((void*)toku_realloc <= caller && caller <= (void*)toku_free)) if (!((void*)toku_realloc <= caller && caller <= (void*)toku_free))
goto skip; goto skip;
(void) __sync_fetch_and_add(&my_realloc_count, 1); // my_realloc_count++; (void) __sync_add_and_fetch(&my_realloc_count, 1); // my_realloc_count++;
if (n >= my_big_malloc_limit) { if (n >= my_big_malloc_limit) {
(void) __sync_fetch_and_add(&my_big_realloc_count, 1); // my_big_realloc_count++; (void) __sync_add_and_fetch(&my_big_realloc_count, 1); // my_big_realloc_count++;
if (do_realloc_errors) { if (do_realloc_errors) {
caller = __builtin_return_address(1); caller = __builtin_return_address(1);
if ((void*)toku_xrealloc <= caller && caller <= (void*)toku_malloc_report) if ((void*)toku_xrealloc <= caller && caller <= (void*)toku_malloc_report)
......
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