Skip to content

Commit

Permalink
Revert "Revert "Use stdatomic.h, which is part of C standard since C1…
Browse files Browse the repository at this point in the history
…1.""

This reverts commit dd417cb.
  • Loading branch information
sobomax committed Dec 9, 2020
1 parent 745fe0c commit a91ab9c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
5 changes: 2 additions & 3 deletions statistics.c
Expand Up @@ -34,7 +34,7 @@
* \brief Statistics support
*/


#include <stdatomic.h>
#include <string.h>

#include "mem/shm_mem.h"
Expand All @@ -46,7 +46,6 @@
#include "core_stats.h"
#include "statistics.h"
#include "pt.h"
#include "atomic.h"
#include "globals.h"
#include "rw_locking.h"

Expand Down Expand Up @@ -424,7 +423,7 @@ static int __register_stat(str *module, str *name, stat_var **pvar,
#ifdef NO_ATOMIC_OPS
*(stat->u.val) = 0;
#else
atomic_set(stat->u.val,0);
atomic_init(stat->u.val, 0);
#endif
*pvar = stat;
} else {
Expand Down
14 changes: 6 additions & 8 deletions statistics.h
Expand Up @@ -34,8 +34,9 @@
#ifndef _STATISTICS_H_
#define _STATISTICS_H_

#include <stdatomic.h>

#include "hash_func.h"
#include "atomic.h"

#define STATS_HASH_POWER 8
#define STATS_HASH_SIZE (1<<(STATS_HASH_POWER))
Expand All @@ -52,7 +53,7 @@
#ifdef NO_ATOMIC_OPS
typedef unsigned int stat_val;
#else
typedef atomic_t stat_val;
typedef _Atomic(unsigned long) stat_val;
#endif

typedef unsigned long (*stat_function)(void *);
Expand Down Expand Up @@ -209,20 +210,17 @@ extern gen_lock_t *stat_lock;
#define update_stat( _var, _n) \
do { \
if ( !((_var)->flags&STAT_IS_FUNC) ) {\
if ((long)(_n) >= 0L) \
atomic_add( _n, (_var)->u.val);\
else \
atomic_sub( -(_n), (_var)->u.val);\
atomic_fetch_add((_var)->u.val, _n); \
}\
}while(0)
#define reset_stat( _var) \
do { \
if ( ((_var)->flags&(STAT_NO_RESET|STAT_IS_FUNC))==0 ) {\
atomic_set( (_var)->u.val, 0);\
atomic_store((_var)->u.val, 0); \
}\
}while(0)
#define get_stat_val( _var ) ((unsigned long)\
((_var)->flags&STAT_IS_FUNC)?(_var)->u.f((_var)->context):(_var)->u.val->counter)
((_var)->flags&STAT_IS_FUNC)?(_var)->u.f((_var)->context):atomic_load((_var)->u.val))
#endif /* NO_ATOMIC_OPS */

#define if_update_stat(_c, _var, _n) \
Expand Down

0 comments on commit a91ab9c

Please sign in to comment.