From 8307fc9d6c44a1ac30535a21c318993fefaea998 Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Mon, 25 Dec 2017 18:40:06 +0300 Subject: [PATCH] fix a data race in debug build (#523) * fix a data race in debug build --- storage/innobase/fil/fil0fil.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 8c86e272853..dd02295eb42 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -188,19 +188,19 @@ bool fil_validate_skip(void) /*===================*/ { - /** The fil_validate() call skip counter. Use a signed type - because of the race condition below. */ + /** The fil_validate() call skip counter. */ static int fil_validate_count = FIL_VALIDATE_SKIP; - /* There is a race condition below, but it does not matter, - because this call is only for heuristic purposes. We want to - reduce the call frequency of the costly fil_validate() check - in debug builds. */ - if (--fil_validate_count > 0) { + /* We want to reduce the call frequency of the costly fil_validate() + check in debug builds. */ + int count = my_atomic_add32_explicit(&fil_validate_count, -1, + MY_MEMORY_ORDER_RELAXED); + if (count > 0) { return(true); } - fil_validate_count = FIL_VALIDATE_SKIP; + my_atomic_store32_explicit(&fil_validate_count, FIL_VALIDATE_SKIP, + MY_MEMORY_ORDER_RELAXED); return(fil_validate()); } #endif /* UNIV_DEBUG */