@cryptotaxi247 / netdata-1 / commits / 2d7028c2a

database flags are now using atomic operations when available

Costa Tsaousis (ktsaou) committed Jul 2, 2017 at 15:18 UTC 2d7028c2ab7be6da3862718e39fd8f4c9e9d6259
2 files changed +24
m4/ax_c___atomic.m4
+6
@@ -10,13 +10,19 @@ AC_DEFUN([AC_C___ATOMIC],
10 main (int argc, char **argv)
11 {
12 volatile unsigned long ul1 = 1, ul2 = 0, ul3 = 2;
13 + __atomic_load_n(&ul1, __ATOMIC_SEQ_CST);
14 __atomic_compare_exchange(&ul1, &ul2, &ul3, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
15 __atomic_fetch_add(&ul1, 1, __ATOMIC_SEQ_CST);
16 __atomic_fetch_sub(&ul3, 1, __ATOMIC_SEQ_CST);
17 + __atomic_or_fetch(&ul1, ul2, __ATOMIC_SEQ_CST);
18 + __atomic_and_fetch(&ul1, ul2, __ATOMIC_SEQ_CST);
19 volatile unsigned long long ull1 = 1, ull2 = 0, ull3 = 2;
20 + __atomic_load_n(&ull1, __ATOMIC_SEQ_CST);
21 __atomic_compare_exchange(&ull1, &ull2, &ull3, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
22 __atomic_fetch_add(&ull1, 1, __ATOMIC_SEQ_CST);
23 __atomic_fetch_sub(&ull3, 1, __ATOMIC_SEQ_CST);
24 + __atomic_or_fetch(&ull1, ull2, __ATOMIC_SEQ_CST);
25 + __atomic_and_fetch(&ull1, ull2, __ATOMIC_SEQ_CST);
26 return 0;
27 }
28 ]])],
src/rrd.h
+18
@@ -103,9 +103,15 @@ typedef enum rrddim_flags {
103 RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS = 1 << 1 // do not offer RESET or OVERFLOW info to callers
104 } RRDDIM_FLAGS;
105
106 +#ifdef HAVE_C___ATOMIC
107 +#define rrddim_flag_check(rd, flag) (__atomic_load_n(&((rd)->flags), __ATOMIC_SEQ_CST) & flag)
108 +#define rrddim_flag_set(rd, flag) __atomic_or_fetch(&((rd)->flags), flag, __ATOMIC_SEQ_CST)
109 +#define rrddim_flag_clear(rd, flag) __atomic_and_fetch(&((rd)->flags), ~flag, __ATOMIC_SEQ_CST)
110 +#else
111 #define rrddim_flag_check(rd, flag) ((rd)->flags & flag)
112 #define rrddim_flag_set(rd, flag) (rd)->flags |= flag
113 #define rrddim_flag_clear(rd, flag) (rd)->flags &= ~flag
114 +#endif
115
116
117 // ----------------------------------------------------------------------------
@@ -221,9 +227,15 @@ typedef enum rrdset_flags {
227 RRDSET_FLAG_BACKEND_IGNORE = 1 << 5
228 } RRDSET_FLAGS;
229
230 +#ifdef HAVE_C___ATOMIC
231 +#define rrdset_flag_check(st, flag) (__atomic_load_n(&((st)->flags), __ATOMIC_SEQ_CST) & flag)
232 +#define rrdset_flag_set(st, flag) __atomic_or_fetch(&((st)->flags), flag, __ATOMIC_SEQ_CST)
233 +#define rrdset_flag_clear(st, flag) __atomic_and_fetch(&((st)->flags), ~flag, __ATOMIC_SEQ_CST)
234 +#else
235 #define rrdset_flag_check(st, flag) ((st)->flags & flag)
236 #define rrdset_flag_set(st, flag) (st)->flags |= flag
237 #define rrdset_flag_clear(st, flag) (st)->flags &= ~flag
238 +#endif
239
240 struct rrdset {
241 // ------------------------------------------------------------------------
@@ -357,9 +369,15 @@ typedef enum rrdhost_flags {
369 RRDHOST_DELETE_ORPHAN_HOST = 1 << 2 // delete the entire host when orphan
370 } RRDHOST_FLAGS;
371
372 +#ifdef HAVE_C___ATOMIC
373 +#define rrdhost_flag_check(host, flag) (__atomic_load_n(&((host)->flags), __ATOMIC_SEQ_CST) & flag)
374 +#define rrdhost_flag_set(host, flag) __atomic_or_fetch(&((host)->flags), flag, __ATOMIC_SEQ_CST)
375 +#define rrdhost_flag_clear(host, flag) __atomic_and_fetch(&((host)->flags), ~flag, __ATOMIC_SEQ_CST)
376 +#else
377 #define rrdhost_flag_check(host, flag) ((host)->flags & flag)
378 #define rrdhost_flag_set(host, flag) (host)->flags |= flag
379 #define rrdhost_flag_clear(host, flag) (host)->flags &= ~flag
380 +#endif
381
382 // ----------------------------------------------------------------------------
383 // RRD HOST