diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-02-07 11:49:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-02-07 12:42:05 +0000 |
commit | 2e85f9325a797977eea9dfea0a925775ddd211d9 (patch) | |
tree | 452c7f30d62fca5755f659b99e4e53c7b03afc21 /database/engine/rrdenginelib.h | |
parent | Releasing debian version 1.19.0-4. (diff) | |
download | netdata-2e85f9325a797977eea9dfea0a925775ddd211d9.tar.xz netdata-2e85f9325a797977eea9dfea0a925775ddd211d9.zip |
Merging upstream version 1.29.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'database/engine/rrdenginelib.h')
-rw-r--r-- | database/engine/rrdenginelib.h | 57 |
1 files changed, 49 insertions, 8 deletions
diff --git a/database/engine/rrdenginelib.h b/database/engine/rrdenginelib.h index 5685b65a5..ebab93c8f 100644 --- a/database/engine/rrdenginelib.h +++ b/database/engine/rrdenginelib.h @@ -3,10 +3,9 @@ #ifndef NETDATA_RRDENGINELIB_H #define NETDATA_RRDENGINELIB_H -#include "rrdengine.h" - /* Forward declarations */ struct rrdeng_page_descr; +struct rrdengine_instance; #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) @@ -28,11 +27,43 @@ struct rrdeng_page_descr; typedef uintptr_t rrdeng_stats_t; #ifdef __ATOMIC_RELAXED -#define rrd_stat_atomic_add(p, n) do {(void) __atomic_fetch_add(p, n, __ATOMIC_RELAXED);} while(0) +#define rrd_atomic_fetch_add(p, n) __atomic_fetch_add(p, n, __ATOMIC_RELAXED) +#define rrd_atomic_add_fetch(p, n) __atomic_add_fetch(p, n, __ATOMIC_RELAXED) #else -#define rrd_stat_atomic_add(p, n) do {(void) __sync_fetch_and_add(p, n);} while(0) +#define rrd_atomic_fetch_add(p, n) __sync_fetch_and_add(p, n) +#define rrd_atomic_add_fetch(p, n) __sync_add_and_fetch(p, n) #endif +#define rrd_stat_atomic_add(p, n) rrd_atomic_fetch_add(p, n) + +/* returns -1 if it didn't find the first cleared bit, the position otherwise. Starts from LSB. */ +static inline int find_first_zero(unsigned x) +{ + return ffs((int)(~x)) - 1; +} + +/* Starts from LSB. */ +static inline uint8_t check_bit(unsigned x, size_t pos) +{ + return !!(x & (1 << pos)); +} + +/* Starts from LSB. val is 0 or 1 */ +static inline void modify_bit(unsigned *x, unsigned pos, uint8_t val) +{ + switch(val) { + case 0: + *x &= ~(1U << pos); + break; + case 1: + *x |= 1U << pos; + break; + default: + error("modify_bit() called with invalid argument."); + break; + } +} + #define RRDENG_PATH_MAX (4096) /* returns old *ptr value */ @@ -56,8 +87,8 @@ struct completion { static inline void init_completion(struct completion *p) { p->completed = 0; - assert(0 == uv_cond_init(&p->cond)); - assert(0 == uv_mutex_init(&p->mutex)); + fatal_assert(0 == uv_cond_init(&p->cond)); + fatal_assert(0 == uv_mutex_init(&p->mutex)); } static inline void destroy_completion(struct completion *p) @@ -72,7 +103,7 @@ static inline void wait_for_completion(struct completion *p) while (0 == p->completed) { uv_cond_wait(&p->cond, &p->mutex); } - assert(1 == p->completed); + fatal_assert(1 == p->completed); uv_mutex_unlock(&p->mutex); } @@ -97,7 +128,17 @@ static inline void crc32set(void *crcp, uLong crc) extern void print_page_cache_descr(struct rrdeng_page_descr *page_cache_descr); extern void print_page_descr(struct rrdeng_page_descr *descr); extern int check_file_properties(uv_file file, uint64_t *file_size, size_t min_size); -extern int open_file_direct_io(char *path, int flags, uv_file *file); +extern int open_file_for_io(char *path, int flags, uv_file *file, int direct); +static inline int open_file_direct_io(char *path, int flags, uv_file *file) +{ + return open_file_for_io(path, flags, file, 1); +} +static inline int open_file_buffered_io(char *path, int flags, uv_file *file) +{ + return open_file_for_io(path, flags, file, 0); +} extern char *get_rrdeng_statistics(struct rrdengine_instance *ctx, char *str, size_t size); +extern int compute_multidb_diskspace(); +extern int is_legacy_child(const char *machine_guid); #endif /* NETDATA_RRDENGINELIB_H */
\ No newline at end of file |