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

@@ -34,7 +34,6 @@
#include "pfs_host.h"
#include "pfs_user.h"
#include "pfs_events_transactions.h"
#include "pfs_atomic.h"
#include "pfs_buffer_container.h"
#include "pfs_builtin_memory.h"
#include "m_string.h"
@@ -62,7 +61,7 @@ int init_events_transactions_history_long(uint events_transactions_history_long_
{
events_transactions_history_long_size= events_transactions_history_long_sizing;
events_transactions_history_long_full= false;
PFS_atomic::store_u32(&events_transactions_history_long_index.m_u32, 0);
events_transactions_history_long_index.m_u32.store(0);
if (events_transactions_history_long_size == 0)
return 0;
@@ -135,7 +134,7 @@ void insert_events_transactions_history_long(PFS_events_transactions *transactio
assert(events_transactions_history_long_array != NULL);
uint index= PFS_atomic::add_u32(&events_transactions_history_long_index.m_u32, 1);
uint index= events_transactions_history_long_index.m_u32.fetch_add(1);
index= index % events_transactions_history_long_size;
if (index == 0)
@@ -176,7 +175,7 @@ void reset_events_transactions_history(void)
/** Reset table EVENTS_TRANSACTIONS_HISTORY_LONG data. */
void reset_events_transactions_history_long(void)
{
PFS_atomic::store_u32(&events_transactions_history_long_index.m_u32, 0);
events_transactions_history_long_index.m_u32.store(0);
events_transactions_history_long_full= false;
PFS_events_transactions *pfs= events_transactions_history_long_array;