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

#3992 fix races found by cilkscreen refs[t:3992]

git-svn-id: file:///svn/toku/tokudb@35214 c7de825b-a66e-492c-adef-691d508d4ae1
parent faf3a583
......@@ -11,6 +11,14 @@
#include "memory.h"
#include "brtloader-internal.h"
static void error_callback_lock(brtloader_error_callback loader_error) {
int r = toku_pthread_mutex_lock(&loader_error->mutex); assert(r == 0);
}
static void error_callback_unlock(brtloader_error_callback loader_error) {
int r = toku_pthread_mutex_unlock(&loader_error->mutex); assert(r == 0);
}
int brt_loader_init_error_callback(brtloader_error_callback loader_error) {
memset(loader_error, 0, sizeof *loader_error);
int r = toku_pthread_mutex_init(&loader_error->mutex, NULL); assert(r == 0);
......@@ -25,7 +33,10 @@ void brt_loader_destroy_error_callback(brtloader_error_callback loader_error) {
}
int brt_loader_get_error(brtloader_error_callback loader_error) {
return loader_error->error;
error_callback_lock(loader_error);
int r = loader_error->error;
error_callback_unlock(loader_error);
return r;
}
void brt_loader_set_error_function(brtloader_error_callback loader_error, brt_loader_error_func error_function, void *error_extra) {
......@@ -33,14 +44,6 @@ void brt_loader_set_error_function(brtloader_error_callback loader_error, brt_lo
loader_error->extra = error_extra;
}
static void error_callback_lock(brtloader_error_callback loader_error) {
int r = toku_pthread_mutex_lock(&loader_error->mutex); assert(r == 0);
}
static void error_callback_unlock(brtloader_error_callback loader_error) {
int r = toku_pthread_mutex_unlock(&loader_error->mutex); assert(r == 0);
}
static void copy_dbt(DBT *dest, DBT *src) {
if (src) {
dest->data = toku_malloc(src->size);
......
......@@ -15,11 +15,20 @@ extern "C" {
#include "toku_atomic.h"
static toku_pthread_mutex_t event_mutex = TOKU_PTHREAD_MUTEX_INITIALIZER;
static void lock_events(void) {
int r = toku_pthread_mutex_lock(&event_mutex); assert(r == 0);
}
static void unlock_events(void) {
int r = toku_pthread_mutex_unlock(&event_mutex); assert(r == 0);
}
static int event_count, event_count_trigger;
__attribute__((__unused__))
static void reset_event_counts(void) {
lock_events();
event_count = event_count_trigger = 0;
unlock_events();
}
__attribute__((__unused__))
......@@ -28,7 +37,11 @@ static void event_hit(void) {
__attribute__((__unused__))
static int event_add_and_fetch(void) {
return toku_sync_increment_and_fetch_int32(&event_count);
lock_events();
int r = ++event_count;
unlock_events();
return r;
// return toku_sync_increment_and_fetch_int32(&event_count);
}
static int do_user_errors = 0;
......
......@@ -9,7 +9,6 @@ static inline uint32_t
toku_sync_fetch_and_add_uint32(volatile uint32_t *a, uint32_t b) {
// icc previously required _InterlockedExchangeAdd((LONG*)a, b);
return __sync_fetch_and_add(a, b);
}
static inline uint32_t toku_sync_fetch_and_increment_uint32(volatile uint32_t *a) {
......@@ -38,11 +37,11 @@ static inline int32_t toku_sync_add_and_fetch_int32(volatile int32_t *a, int32_t
}
static inline int32_t toku_sync_increment_and_fetch_int32(volatile int32_t *a) {
return toku_sync_add_and_fetch_int32(a, 1);
return __sync_add_and_fetch(a, 1);
}
static inline int32_t toku_sync_decrement_and_fetch_int32(volatile int32_t *a) {
return toku_sync_add_and_fetch_int32(a, -1);
return __sync_add_and_fetch(a, -1);
}
#if __GNUC__ && __i386__
......
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