From 8224d904c1936df35a253ab8340c282ddb1b4f47 Mon Sep 17 00:00:00 2001 From: Yibo Cai Date: Thu, 14 Nov 2019 09:49:47 +0000 Subject: [PATCH] innobase/dict: refine temp_file_num with c++11 atomics Though only atomicity is required, current code uses gcc __sync_xxx builtins which introduces unnecessary memory barriers. Refine with C++11 relaxed memory order. --- storage/innobase/dict/dict0mem.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc index e142755..d8f3f8a 100644 --- a/storage/innobase/dict/dict0mem.cc +++ b/storage/innobase/dict/dict0mem.cc @@ -55,7 +55,7 @@ this program; if not, write to the Free Software Foundation, Inc., /** An interger randomly initialized at startup used to make a temporary table name as unuique as possible. */ -static ib_uint32_t dict_temp_file_num; +static os_atomic_t dict_temp_file_num; /** Display an identifier. @param[in,out] s output stream @@ -714,14 +714,14 @@ char *dict_mem_create_temporary_tablename(mem_heap_t *heap, const char *dbtab, size_t dblen = dbend - dbtab + 1; /* Increment a randomly initialized number for each temp file. */ - os_atomic_increment_uint32(&dict_temp_file_num, 1); + ib_uint32_t file_num = dict_temp_file_num.fetch_add(1, order_relaxed) + 1; size = dblen + (sizeof(TEMP_FILE_PREFIX) + 3 + 20 + 1 + 10); name = static_cast(mem_heap_alloc(heap, size)); memcpy(name, dbtab, dblen); snprintf(name + dblen, size - dblen, TEMP_FILE_PREFIX_INNODB UINT64PF "-" UINT32PF, id, - dict_temp_file_num); + file_num); return (name); } @@ -733,10 +733,11 @@ void dict_mem_init(void) { const byte *buf = reinterpret_cast(&now); - dict_temp_file_num = ut_crc32(buf, sizeof(now)); + ib_uint32_t file_num = ut_crc32(buf, sizeof(now)); + dict_temp_file_num.store(file_num, order_relaxed); DBUG_PRINT("dict_mem_init", ("Starting Temporary file number is " UINT32PF, - dict_temp_file_num)); + file_num)); } /** Validate the search order in the foreign key set. -- 2.7.4