fix a data race in debug build (#523)

* fix a data race in debug build
This commit is contained in:
Eugene Kosov 2017-12-25 18:40:06 +03:00 committed by Sergey Vojtovich
parent 1761e38208
commit 8307fc9d6c

View File

@ -188,19 +188,19 @@ bool
fil_validate_skip(void) fil_validate_skip(void)
/*===================*/ /*===================*/
{ {
/** The fil_validate() call skip counter. Use a signed type /** The fil_validate() call skip counter. */
because of the race condition below. */
static int fil_validate_count = FIL_VALIDATE_SKIP; static int fil_validate_count = FIL_VALIDATE_SKIP;
/* There is a race condition below, but it does not matter, /* We want to reduce the call frequency of the costly fil_validate()
because this call is only for heuristic purposes. We want to check in debug builds. */
reduce the call frequency of the costly fil_validate() check int count = my_atomic_add32_explicit(&fil_validate_count, -1,
in debug builds. */ MY_MEMORY_ORDER_RELAXED);
if (--fil_validate_count > 0) { if (count > 0) {
return(true); 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()); return(fil_validate());
} }
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */