diff options
author | Daniel Black <daniel@mariadb.org> | 2021-07-18 17:03:04 +1000 |
---|---|---|
committer | Daniel Black <daniel@mariadb.org> | 2021-07-23 13:20:11 +1000 |
commit | cb121be859d29599f8cca97a727eee347fdfd92c (patch) | |
tree | 8e4ab6a7a6af2b318ed8b35407eb7c872b0f3bae | |
parent | 3700a3b5048a0a4583fae983ee37c88111250327 (diff) | |
download | mariadb-git-bb-10.7-danielblack-MDEV-26157-openmp-statistics-fork.tar.gz |
WIP: use of omp atomic for statisic_{inc,dec,add,sub}bb-10.7-danielblack-MDEV-26157-openmp-statistics-fork
TODO:
When parallel threads start to operate on a single
per session status variable there is more chance that inaccuracies
will occur. With the advent of atomics can maybe we use
"SAFE_STATISTICS" by default. The high content global variables
are being replaces with more optimium low contention counters.
thread_safe_{inc,dec,add,sub} could be removed as they are no
longer in use. But is this an API for plugins that needs to be
preserved?
-rw-r--r-- | include/my_pthread.h | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/include/my_pthread.h b/include/my_pthread.h index d38d69d04a0..e9a49046a29 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -735,30 +735,14 @@ int set_mysys_var(struct st_my_thread_var *mysys_var); */ #ifndef thread_safe_increment -#ifdef _WIN32 -#define thread_safe_increment(V,L) InterlockedIncrement((long*) &(V)) -#define thread_safe_decrement(V,L) InterlockedDecrement((long*) &(V)) -#else #define thread_safe_increment(V,L) \ - (mysql_mutex_lock((L)), (V)++, mysql_mutex_unlock((L))) + std::atomic_fetch_add((long*) &(V), 1) #define thread_safe_decrement(V,L) \ - (mysql_mutex_lock((L)), (V)--, mysql_mutex_unlock((L))) -#endif + std::atomic_fetch_sub((long*) &(V), 1) +#define thread_safe_add(V,C,L) std::atomic_fetch_add((long*) &(V), (C)) +#define thread_safe_sub(V,C,L) std::atomic_fetch_sub((long*) &(V), (C)) #endif -#ifndef thread_safe_add -#ifdef _WIN32 -#define thread_safe_add(V,C,L) InterlockedExchangeAdd((long*) &(V),(C)) -#define thread_safe_sub(V,C,L) InterlockedExchangeAdd((long*) &(V),-(long) (C)) -#else -#define thread_safe_add(V,C,L) \ - (mysql_mutex_lock((L)), (V)+=(C), mysql_mutex_unlock((L))) -#define thread_safe_sub(V,C,L) \ - (mysql_mutex_lock((L)), (V)-=(C), mysql_mutex_unlock((L))) -#endif -#endif - - /* statistics_xxx functions are for non critical statistic, maintained in global variables. @@ -771,10 +755,10 @@ int set_mysys_var(struct st_my_thread_var *mysys_var); - the lock given is not honored. */ #ifdef SAFE_STATISTICS -#define statistic_increment(V,L) thread_safe_increment((V),(L)) -#define statistic_decrement(V,L) thread_safe_decrement((V),(L)) -#define statistic_add(V,C,L) thread_safe_add((V),(C),(L)) -#define statistic_sub(V,C,L) thread_safe_sub((V),(C),(L)) +#define statistic_increment(V,L) _Pragma("omp atomic") (V)++ +#define statistic_decrement(V,L) _Pragma("omp atomic") (V)-- +#define statistic_add(V,C,L) _Pragma("omp atomic") (V)+=(C) +#define statistic_sub(V,C,L) _Pragma("omp atomic") (V)-=(C) #else #define statistic_decrement(V,L) (V)-- #define statistic_increment(V,L) (V)++ |