[Commits] 8de492e: Clean-up InnoDB atomics

Sergey Vojtovich svoj at mariadb.org
Fri Sep 9 14:54:36 EEST 2016


revision-id: 8de492e7956cc027065978b57fc784a46523c83c (mariadb-10.2.1-10-g8de492e)
parent(s): 4e3df18231ee9b903271ff283f7dc4ebf8c7bad4
committer: Sergey Vojtovich
timestamp: 2016-09-09 15:54:34 +0400
message:

Clean-up InnoDB atomics

Replaced os_compare_and_swap_uint32 with my_atomic_add32().

---
 storage/innobase/include/os0atomic.h | 18 ------------------
 storage/innobase/include/os0once.h   | 13 +++++++------
 2 files changed, 7 insertions(+), 24 deletions(-)

diff --git a/storage/innobase/include/os0atomic.h b/storage/innobase/include/os0atomic.h
index 03a979f..336d7fe 100644
--- a/storage/innobase/include/os0atomic.h
+++ b/storage/innobase/include/os0atomic.h
@@ -141,9 +141,6 @@ compare to, new_val is the value to swap in. */
 # define os_compare_and_swap_ulint(ptr, old_val, new_val) \
 	(win_cmp_and_xchg_ulint(ptr, new_val, old_val) == old_val)
 
-# define os_compare_and_swap_uint32(ptr, old_val, new_val) \
-	(InterlockedCompareExchange(ptr, new_val, old_val) == old_val)
-
 /* windows thread objects can always be passed to windows atomic functions */
 # define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
 	(win_cmp_and_xchg_dword(ptr, new_val, old_val) == old_val)
@@ -196,9 +193,6 @@ compare to, new_val is the value to swap in. */
 # define os_compare_and_swap_lint(ptr, old_val, new_val) \
 	os_compare_and_swap(ptr, old_val, new_val)
 
-# define os_compare_and_swap_uint32(ptr, old_val, new_val) \
-	os_compare_and_swap(ptr, old_val, new_val)
-
 #else
 
 UNIV_INLINE
@@ -225,18 +219,6 @@ os_compare_and_swap_lint(volatile lint* ptr, lint old_val, lint new_val)
 #endif
 }
 
-UNIV_INLINE
-bool
-os_compare_and_swap_uint32(volatile ib_uint32_t* ptr, ib_uint32_t old_val, ib_uint32_t new_val)
-{
-#ifdef HAVE_IB_GCC_ATOMIC_SEQ_CST
-	return __atomic_compare_exchange_n(ptr, &old_val, new_val, 0,
-			__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
-#else
-	return __sync_bool_compare_and_swap(ptr, old_val, new_val);
-#endif
-}
-
 #endif /* HAVE_GCC_SYNC_BUILTINS */
 
 # ifdef HAVE_IB_ATOMIC_PTHREAD_T_GCC
diff --git a/storage/innobase/include/os0once.h b/storage/innobase/include/os0once.h
index 8cde402..a36cccc 100644
--- a/storage/innobase/include/os0once.h
+++ b/storage/innobase/include/os0once.h
@@ -79,20 +79,21 @@ class os_once {
 		void			(*do_func)(void*),
 		void*			do_func_arg)
 	{
-		/* Avoid calling os_compare_and_swap_uint32() in the most
-		common case. */
+		int32 oldval = NEVER_DONE;
+
+		/* Avoid calling my_atomic_cas32() in the most common case. */
 		if (*state == DONE) {
 			return;
 		}
 
-		if (os_compare_and_swap_uint32(state,
-					       NEVER_DONE, IN_PROGRESS)) {
+		if (my_atomic_cas32((int32*) state, &oldval, IN_PROGRESS)) {
 			/* We are the first. Call the function. */
 
 			do_func(do_func_arg);
 
-			const bool	swapped = os_compare_and_swap_uint32(
-				state, IN_PROGRESS, DONE);
+			oldval= IN_PROGRESS;
+			const bool	swapped = my_atomic_cas32(
+				(int32*) state, &oldval, DONE);
 
 			ut_a(swapped);
 		} else {


More information about the commits mailing list