mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-13 16:26:10 +00:00
lib: make atomic ops C++ compatible
C++ doesn't have ISO C11 stdatomic.h or "_Atomic inttype", so use std::atomic instead to get the headers compatible. Signed-off-by: David Lamparter <equinox@diac24.net>
This commit is contained in:
parent
be566e4e45
commit
c8a65463b2
@ -76,7 +76,7 @@
|
|||||||
* Human-readable description of this debugging record.
|
* Human-readable description of this debugging record.
|
||||||
*/
|
*/
|
||||||
struct debug {
|
struct debug {
|
||||||
_Atomic uint32_t flags;
|
atomic_uint_fast32_t flags;
|
||||||
const char *desc;
|
const char *desc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ struct frr_pthread {
|
|||||||
*/
|
*/
|
||||||
pthread_cond_t *running_cond;
|
pthread_cond_t *running_cond;
|
||||||
pthread_mutex_t *running_cond_mtx;
|
pthread_mutex_t *running_cond_mtx;
|
||||||
_Atomic bool running;
|
atomic_bool running;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fake thread-specific storage. No constraints on usage. Helpful when
|
* Fake thread-specific storage. No constraints on usage. Helpful when
|
||||||
|
@ -26,7 +26,23 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ISO C11 */
|
/* ISO C11 */
|
||||||
#ifdef HAVE_STDATOMIC_H
|
#ifdef __cplusplus
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <atomic>
|
||||||
|
using std::atomic_int;
|
||||||
|
using std::memory_order;
|
||||||
|
using std::memory_order_relaxed;
|
||||||
|
using std::memory_order_acquire;
|
||||||
|
using std::memory_order_release;
|
||||||
|
using std::memory_order_acq_rel;
|
||||||
|
using std::memory_order_consume;
|
||||||
|
using std::memory_order_seq_cst;
|
||||||
|
|
||||||
|
typedef std::atomic<bool> atomic_bool;
|
||||||
|
typedef std::atomic<size_t> atomic_size_t;
|
||||||
|
typedef std::atomic<uint_fast32_t> atomic_uint_fast32_t;
|
||||||
|
|
||||||
|
#elif defined(HAVE_STDATOMIC_H)
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
|
|
||||||
/* These are available in gcc, but not in stdatomic */
|
/* These are available in gcc, but not in stdatomic */
|
||||||
@ -39,6 +55,7 @@
|
|||||||
#elif defined(HAVE___ATOMIC)
|
#elif defined(HAVE___ATOMIC)
|
||||||
|
|
||||||
#define _Atomic volatile
|
#define _Atomic volatile
|
||||||
|
#define _ATOMIC_WANT_TYPEDEFS
|
||||||
|
|
||||||
#define memory_order_relaxed __ATOMIC_RELAXED
|
#define memory_order_relaxed __ATOMIC_RELAXED
|
||||||
#define memory_order_consume __ATOMIC_CONSUME
|
#define memory_order_consume __ATOMIC_CONSUME
|
||||||
@ -74,6 +91,7 @@
|
|||||||
#elif defined(HAVE___SYNC)
|
#elif defined(HAVE___SYNC)
|
||||||
|
|
||||||
#define _Atomic volatile
|
#define _Atomic volatile
|
||||||
|
#define _ATOMIC_WANT_TYPEDEFS
|
||||||
|
|
||||||
#define memory_order_relaxed 0
|
#define memory_order_relaxed 0
|
||||||
#define memory_order_consume 0
|
#define memory_order_consume 0
|
||||||
@ -198,4 +216,15 @@
|
|||||||
#error no atomic functions...
|
#error no atomic functions...
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _ATOMIC_WANT_TYPEDEFS
|
||||||
|
#undef _ATOMIC_WANT_TYPEDEFS
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
typedef _Atomic bool atomic_bool;
|
||||||
|
typedef _Atomic size_t atomic_size_t;
|
||||||
|
typedef _Atomic uint_fast32_t atomic_uint_fast32_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _FRRATOMIC_H */
|
#endif /* _FRRATOMIC_H */
|
||||||
|
@ -54,9 +54,9 @@ struct hash_backet {
|
|||||||
|
|
||||||
struct hashstats {
|
struct hashstats {
|
||||||
/* number of empty hash buckets */
|
/* number of empty hash buckets */
|
||||||
_Atomic uint_fast32_t empty;
|
atomic_uint_fast32_t empty;
|
||||||
/* sum of squares of bucket length */
|
/* sum of squares of bucket length */
|
||||||
_Atomic uint_fast32_t ssq;
|
atomic_uint_fast32_t ssq;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct hash {
|
struct hash {
|
||||||
|
10
lib/memory.h
10
lib/memory.h
@ -33,12 +33,12 @@
|
|||||||
struct memtype {
|
struct memtype {
|
||||||
struct memtype *next, **ref;
|
struct memtype *next, **ref;
|
||||||
const char *name;
|
const char *name;
|
||||||
_Atomic size_t n_alloc;
|
atomic_size_t n_alloc;
|
||||||
_Atomic size_t n_max;
|
atomic_size_t n_max;
|
||||||
_Atomic size_t size;
|
atomic_size_t size;
|
||||||
#ifdef HAVE_MALLOC_USABLE_SIZE
|
#ifdef HAVE_MALLOC_USABLE_SIZE
|
||||||
_Atomic size_t total;
|
atomic_size_t total;
|
||||||
_Atomic size_t max_size;
|
atomic_size_t max_size;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -115,9 +115,9 @@ struct stream_fifo {
|
|||||||
pthread_mutex_t mtx;
|
pthread_mutex_t mtx;
|
||||||
|
|
||||||
/* number of streams in this fifo */
|
/* number of streams in this fifo */
|
||||||
_Atomic size_t count;
|
atomic_size_t count;
|
||||||
#if defined DEV_BUILD
|
#if defined DEV_BUILD
|
||||||
_Atomic size_t max_count;
|
atomic_size_t max_count;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct stream *head;
|
struct stream *head;
|
||||||
|
@ -93,7 +93,8 @@ static void cpu_record_hash_free(void *a)
|
|||||||
static void vty_out_cpu_thread_history(struct vty *vty,
|
static void vty_out_cpu_thread_history(struct vty *vty,
|
||||||
struct cpu_thread_history *a)
|
struct cpu_thread_history *a)
|
||||||
{
|
{
|
||||||
vty_out(vty, "%5d %10lu.%03lu %9u %8lu %9lu %8lu %9lu", a->total_active,
|
vty_out(vty, "%5"PRIdFAST32" %10lu.%03lu %9"PRIuFAST32
|
||||||
|
" %8lu %9lu %8lu %9lu", a->total_active,
|
||||||
a->cpu.total / 1000, a->cpu.total % 1000, a->total_calls,
|
a->cpu.total / 1000, a->cpu.total % 1000, a->total_calls,
|
||||||
a->cpu.total / a->total_calls, a->cpu.max,
|
a->cpu.total / a->total_calls, a->cpu.max,
|
||||||
a->real.total / a->total_calls, a->real.max);
|
a->real.total / a->total_calls, a->real.max);
|
||||||
|
@ -119,13 +119,13 @@ struct thread {
|
|||||||
|
|
||||||
struct cpu_thread_history {
|
struct cpu_thread_history {
|
||||||
int (*func)(struct thread *);
|
int (*func)(struct thread *);
|
||||||
_Atomic unsigned int total_calls;
|
atomic_uint_fast32_t total_calls;
|
||||||
_Atomic unsigned int total_active;
|
atomic_uint_fast32_t total_active;
|
||||||
struct time_stats {
|
struct time_stats {
|
||||||
_Atomic unsigned long total, max;
|
atomic_size_t total, max;
|
||||||
} real;
|
} real;
|
||||||
struct time_stats cpu;
|
struct time_stats cpu;
|
||||||
_Atomic uint32_t types;
|
atomic_uint_fast32_t types;
|
||||||
const char *funcname;
|
const char *funcname;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user