diff --git a/newbrt/brtloader-callback.c b/newbrt/brtloader-callback.c index ac0e336f123..2a9c55384bb 100644 --- a/newbrt/brtloader-callback.c +++ b/newbrt/brtloader-callback.c @@ -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); diff --git a/newbrt/tests/brtloader-error-injector.h b/newbrt/tests/brtloader-error-injector.h index 501bee69ec6..e1530b5efcb 100644 --- a/newbrt/tests/brtloader-error-injector.h +++ b/newbrt/tests/brtloader-error-injector.h @@ -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; diff --git a/toku_include/toku_atomic.h b/toku_include/toku_atomic.h index 07282964ca6..0602e38e5ba 100644 --- a/toku_include/toku_atomic.h +++ b/toku_include/toku_atomic.h @@ -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__