From f718477714aedd9fd598990169db6f512c9cae64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 14 Nov 2018 09:30:49 +0200 Subject: [PATCH] os_aio_validate_skip(): Fix a data race --- storage/innobase/os/os0file.cc | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index 5d0f3f4fc9c..6e4e578feaf 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -1090,21 +1090,14 @@ os_aio_validate_skip() /** Try os_aio_validate() every this many times */ # define OS_AIO_VALIDATE_SKIP 13 - /** The os_aio_validate() call skip counter. - Use a signed type because of the race condition below. */ - static int os_aio_validate_count = OS_AIO_VALIDATE_SKIP; + static int os_aio_validate_count; - /* 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 os_aio_validate() - check in debug builds. */ - --os_aio_validate_count; - - if (os_aio_validate_count > 0) { - return(true); + if (my_atomic_add32_explicit(&os_aio_validate_count, -1, + MY_MEMORY_ORDER_RELAXED) + % OS_AIO_VALIDATE_SKIP) { + return true; } - os_aio_validate_count = OS_AIO_VALIDATE_SKIP; return(os_aio_validate()); } #endif /* UNIV_DEBUG */