1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

[MDEV-28162] Replace PFS_atomic with std::atomic<T>

PFS_atomic class contains wrappers around my_atomic_* operations, which
are macros to GNU atomic operations (__atomic_*). Due to different
implementations of compilers, clang may encounter errors when compiling
on x86_32 architecture.

The following functions are replaced with C++ std::atomic type in
performance schema code base:
  - PFS_atomic::store_*()
      -> my_atomic_store*
        -> __atomic_store_n()
    => std::atomic<T>::store()

  - PFS_atomic::load_*()
      -> my_atomic_load*
        -> __atomic_load_n()
    => std::atomic<T>::load()

  - PFS_atomic::add_*()
      -> my_atomic_add*
        -> __atomic_fetch_add()
    => std::atomic<T>::fetch_add()

  - PFS_atomic::cas_*()
    -> my_atomic_cas*
      -> __atomic_compare_exchange_n()
    => std::atomic<T>::compare_exchange_strong()

and PFS_atomic class could be dropped completely.

Note that in the wrapper memory order passed to original GNU atomic
extensions are hard-coded as `__ATOMIC_SEQ_CST`, which is equivalent to
`std::memory_order_seq_cst` in C++, and is the default parameter for
std::atomic_* functions.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services.
This commit is contained in:
Meng-Hsiu Chiang
2023-12-06 19:48:53 +00:00
committed by Marko Mäkelä
parent d5bad49011
commit 55db59f16d
18 changed files with 109 additions and 248 deletions

View File

@@ -25,6 +25,7 @@
@file storage/perfschema/pfs_instr_class.cc
Performance schema instruments meta data (implementation).
*/
#include <atomic>
#include "my_global.h"
#include "my_sys.h"
@@ -36,7 +37,6 @@
#include "pfs_timer.h"
#include "pfs_events_waits.h"
#include "pfs_setup_object.h"
#include "pfs_atomic.h"
#include "pfs_program.h"
#include "pfs_buffer_container.h"
#include "mysql/psi/mysql_thread.h"
@@ -76,12 +76,12 @@ static void init_instr_class(PFS_instr_class *klass,
- the performance schema initialization
- a plugin initialization
*/
static uint32 mutex_class_dirty_count= 0;
static uint32 mutex_class_allocated_count= 0;
static uint32 rwlock_class_dirty_count= 0;
static uint32 rwlock_class_allocated_count= 0;
static uint32 cond_class_dirty_count= 0;
static uint32 cond_class_allocated_count= 0;
static std::atomic<uint32> mutex_class_dirty_count(0);
static std::atomic<uint32> mutex_class_allocated_count(0);
static std::atomic<uint32> rwlock_class_dirty_count(0);
static std::atomic<uint32> rwlock_class_allocated_count(0);
static std::atomic<uint32> cond_class_dirty_count(0);
static std::atomic<uint32> cond_class_allocated_count(0);
/** Size of the mutex class array. @sa mutex_class_array */
ulong mutex_class_max= 0;
@@ -137,8 +137,8 @@ PFS_cond_class *cond_class_array= NULL;
- the performance schema initialization
- a plugin initialization
*/
static uint32 thread_class_dirty_count= 0;
static uint32 thread_class_allocated_count= 0;
static std::atomic<uint32> thread_class_dirty_count(0);
static std::atomic<uint32> thread_class_allocated_count(0);
static PFS_thread_class *thread_class_array= NULL;
@@ -185,28 +185,28 @@ LF_HASH table_share_hash;
/** True if table_share_hash is initialized. */
static bool table_share_hash_inited= false;
static uint32 file_class_dirty_count= 0;
static uint32 file_class_allocated_count= 0;
static std::atomic<uint32> file_class_dirty_count(0);
static std::atomic<uint32> file_class_allocated_count(0);
PFS_file_class *file_class_array= NULL;
static uint32 stage_class_dirty_count= 0;
static uint32 stage_class_allocated_count= 0;
static std::atomic<uint32> stage_class_dirty_count(0);
static std::atomic<uint32> stage_class_allocated_count(0);
static PFS_stage_class *stage_class_array= NULL;
static uint32 statement_class_dirty_count= 0;
static uint32 statement_class_allocated_count= 0;
static std::atomic<uint32> statement_class_dirty_count(0);
static std::atomic<uint32> statement_class_allocated_count(0);
static PFS_statement_class *statement_class_array= NULL;
static uint32 socket_class_dirty_count= 0;
static uint32 socket_class_allocated_count= 0;
static std::atomic<uint32> socket_class_dirty_count(0);
static std::atomic<uint32> socket_class_allocated_count(0);
static PFS_socket_class *socket_class_array= NULL;
static uint32 memory_class_dirty_count= 0;
static uint32 memory_class_allocated_count= 0;
static std::atomic<uint32> memory_class_dirty_count(0);
static std::atomic<uint32> memory_class_allocated_count(0);
static PFS_memory_class *memory_class_array= NULL;
@@ -1092,7 +1092,7 @@ PFS_sync_key register_mutex_class(const char *name, uint name_length,
mutex_class_dirty_count is incremented *before* an entry is added
mutex_class_allocated_count is incremented *after* an entry is added
*/
index= PFS_atomic::add_u32(&mutex_class_dirty_count, 1);
index= mutex_class_dirty_count.fetch_add(1);
if (index < mutex_class_max)
{
@@ -1148,7 +1148,7 @@ PFS_sync_key register_mutex_class(const char *name, uint name_length,
empty/NULL/zero, but this won't cause a crash
(mutex_class_array is initialized with MY_ZEROFILL).
*/
PFS_atomic::add_u32(&mutex_class_allocated_count, 1);
mutex_class_allocated_count.fetch_add(1);
return (index + 1);
}
@@ -1178,7 +1178,7 @@ PFS_sync_key register_rwlock_class(const char *name, uint name_length,
REGISTER_CLASS_BODY_PART(index, rwlock_class_array, rwlock_class_max,
name, name_length)
index= PFS_atomic::add_u32(&rwlock_class_dirty_count, 1);
index= rwlock_class_dirty_count.fetch_add(1);
if (index < rwlock_class_max)
{
@@ -1191,7 +1191,7 @@ PFS_sync_key register_rwlock_class(const char *name, uint name_length,
entry->m_timed= false;
/* Set user-defined configuration options for this instrument */
configure_instr_class(entry);
PFS_atomic::add_u32(&rwlock_class_allocated_count, 1);
rwlock_class_allocated_count.fetch_add(1);
return (index + 1);
}
@@ -1217,7 +1217,7 @@ PFS_sync_key register_cond_class(const char *name, uint name_length,
REGISTER_CLASS_BODY_PART(index, cond_class_array, cond_class_max,
name, name_length)
index= PFS_atomic::add_u32(&cond_class_dirty_count, 1);
index= cond_class_dirty_count.fetch_add(1);
if (index < cond_class_max)
{
@@ -1229,7 +1229,7 @@ PFS_sync_key register_cond_class(const char *name, uint name_length,
entry->m_timed= false;
/* Set user-defined configuration options for this instrument */
configure_instr_class(entry);
PFS_atomic::add_u32(&cond_class_allocated_count, 1);
cond_class_allocated_count.fetch_add(1);
return (index + 1);
}
@@ -1311,7 +1311,7 @@ PFS_thread_key register_thread_class(const char *name, uint name_length,
return (index + 1);
}
index= PFS_atomic::add_u32(&thread_class_dirty_count, 1);
index= thread_class_dirty_count.fetch_add(1);
if (index < thread_class_max)
{
@@ -1320,7 +1320,7 @@ PFS_thread_key register_thread_class(const char *name, uint name_length,
strncpy(entry->m_name, name, name_length);
entry->m_name_length= name_length;
entry->m_enabled= true;
PFS_atomic::add_u32(&thread_class_allocated_count, 1);
thread_class_allocated_count.fetch_add(1);
return (index + 1);
}
@@ -1361,7 +1361,7 @@ PFS_file_key register_file_class(const char *name, uint name_length,
REGISTER_CLASS_BODY_PART(index, file_class_array, file_class_max,
name, name_length)
index= PFS_atomic::add_u32(&file_class_dirty_count, 1);
index= file_class_dirty_count.fetch_add(1);
if (index < file_class_max)
{
@@ -1373,7 +1373,7 @@ PFS_file_key register_file_class(const char *name, uint name_length,
entry->m_timed= true;
/* Set user-defined configuration options for this instrument */
configure_instr_class(entry);
PFS_atomic::add_u32(&file_class_allocated_count, 1);
file_class_allocated_count.fetch_add(1);
return (index + 1);
}
@@ -1403,7 +1403,7 @@ PFS_stage_key register_stage_class(const char *name,
REGISTER_CLASS_BODY_PART(index, stage_class_array, stage_class_max,
name, name_length)
index= PFS_atomic::add_u32(&stage_class_dirty_count, 1);
index= stage_class_dirty_count.fetch_add(1);
if (index < stage_class_max)
{
@@ -1427,7 +1427,7 @@ PFS_stage_key register_stage_class(const char *name,
/* Set user-defined configuration options for this instrument */
configure_instr_class(entry);
PFS_atomic::add_u32(&stage_class_allocated_count, 1);
stage_class_allocated_count.fetch_add(1);
return (index + 1);
}
@@ -1454,7 +1454,7 @@ PFS_statement_key register_statement_class(const char *name, uint name_length,
REGISTER_CLASS_BODY_PART(index, statement_class_array, statement_class_max,
name, name_length)
index= PFS_atomic::add_u32(&statement_class_dirty_count, 1);
index= statement_class_dirty_count.fetch_add(1);
if (index < statement_class_max)
{
@@ -1465,7 +1465,7 @@ PFS_statement_key register_statement_class(const char *name, uint name_length,
entry->m_timed= true;
/* Set user-defined configuration options for this instrument */
configure_instr_class(entry);
PFS_atomic::add_u32(&statement_class_allocated_count, 1);
statement_class_allocated_count.fetch_add(1);
return (index + 1);
}
@@ -1537,7 +1537,7 @@ PFS_socket_key register_socket_class(const char *name, uint name_length,
REGISTER_CLASS_BODY_PART(index, socket_class_array, socket_class_max,
name, name_length)
index= PFS_atomic::add_u32(&socket_class_dirty_count, 1);
index= socket_class_dirty_count.fetch_add(1);
if (index < socket_class_max)
{
@@ -1549,7 +1549,7 @@ PFS_socket_key register_socket_class(const char *name, uint name_length,
entry->m_timed= false;
/* Set user-defined configuration options for this instrument */
configure_instr_class(entry);
PFS_atomic::add_u32(&socket_class_allocated_count, 1);
socket_class_allocated_count.fetch_add(1);
return (index + 1);
}
@@ -1590,7 +1590,7 @@ PFS_memory_key register_memory_class(const char *name, uint name_length,
REGISTER_CLASS_BODY_PART(index, memory_class_array, memory_class_max,
name, name_length)
index= PFS_atomic::add_u32(&memory_class_dirty_count, 1);
index= memory_class_dirty_count.fetch_add(1);
if (index < memory_class_max)
{
@@ -1601,7 +1601,7 @@ PFS_memory_key register_memory_class(const char *name, uint name_length,
/* Set user-defined configuration options for this instrument */
configure_instr_class(entry);
entry->m_timed= false; /* Immutable */
PFS_atomic::add_u32(&memory_class_allocated_count, 1);
memory_class_allocated_count.fetch_add(1);
return (index + 1);
}