Make libnetdata headers compilable by C++. (#10185)

This commit is contained in:
Tomáš Kopal 2020-11-07 01:10:50 +01:00 committed by GitHub
parent b362797e98
commit bcb9c86827
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 46 additions and 30 deletions

View File

@ -535,7 +535,7 @@ enum user_or_group_id_type {
struct user_or_group_ids{
enum user_or_group_id_type type;
avl_tree index;
avl_tree_type index;
struct user_or_group_id *root;
char filename[FILENAME_MAX + 1];
@ -1691,7 +1691,7 @@ int file_descriptor_compare(void* a, void* b) {
// int file_descriptor_iterator(avl *a) { if(a) {}; return 0; }
avl_tree all_files_index = {
avl_tree_type all_files_index = {
NULL,
file_descriptor_compare
};

View File

@ -22,7 +22,7 @@
#define STATSD_FIRST_PTR_MUTEX_UNLOCK(index) netdata_mutex_unlock(&((index)->first_mutex))
#define STATSD_DICTIONARY_OPTIONS DICTIONARY_FLAG_DEFAULT
#else
#define STATSD_AVL_TREE avl_tree
#define STATSD_AVL_TREE avl_tree_type
#define STATSD_AVL_INSERT avl_insert
#define STATSD_AVL_SEARCH avl_search
#define STATSD_AVL_INDEX_INIT { .root = NULL, .compar = statsd_metric_compare }

View File

@ -81,7 +81,7 @@ struct tc_device {
RRDSET *st_tokens;
RRDSET *st_ctokens;
avl_tree classes_index;
avl_tree_type classes_index;
struct tc_class *classes;
struct tc_class *last_class;
@ -102,7 +102,7 @@ static int tc_device_compare(void* a, void* b) {
else return strcmp(((struct tc_device *)a)->id, ((struct tc_device *)b)->id);
}
avl_tree tc_device_root_index = {
avl_tree_type tc_device_root_index = {
NULL,
tc_device_compare
};

View File

@ -322,7 +322,7 @@ inline void rrdcalc_add_to_host(RRDHOST *host, RRDCALC *rc) {
if(rc->calculation) {
rc->calculation->status = &rc->status;
rc->calculation->this = &rc->value;
rc->calculation->myself = &rc->value;
rc->calculation->after = &rc->db_after;
rc->calculation->before = &rc->db_before;
rc->calculation->rrdcalc = rc;
@ -330,7 +330,7 @@ inline void rrdcalc_add_to_host(RRDHOST *host, RRDCALC *rc) {
if(rc->warning) {
rc->warning->status = &rc->status;
rc->warning->this = &rc->value;
rc->warning->myself = &rc->value;
rc->warning->after = &rc->db_after;
rc->warning->before = &rc->db_before;
rc->warning->rrdcalc = rc;
@ -338,7 +338,7 @@ inline void rrdcalc_add_to_host(RRDHOST *host, RRDCALC *rc) {
if(rc->critical) {
rc->critical->status = &rc->status;
rc->critical->this = &rc->value;
rc->critical->myself = &rc->value;
rc->critical->after = &rc->db_after;
rc->critical->before = &rc->db_before;
rc->critical->rrdcalc = rc;

View File

@ -17,7 +17,7 @@
/* Search |tree| for an item matching |item|, and return it if found.
Otherwise return |NULL|. */
avl *avl_search(avl_tree *tree, avl *item) {
avl *avl_search(avl_tree_type *tree, avl *item) {
avl *p;
// assert (tree != NULL && item != NULL);
@ -40,7 +40,7 @@ avl *avl_search(avl_tree *tree, avl *item) {
If a duplicate item is found in the tree,
returns a pointer to the duplicate without inserting |item|.
*/
avl *avl_insert(avl_tree *tree, avl *item) {
avl *avl_insert(avl_tree_type *tree, avl *item) {
avl *y, *z; /* Top node to update balance factor, and parent. */
avl *p, *q; /* Iterator, and parent. */
avl *n; /* Newly inserted node. */
@ -136,7 +136,7 @@ avl *avl_insert(avl_tree *tree, avl *item) {
/* Deletes from |tree| and returns an item matching |item|.
Returns a null pointer if no matching item found. */
avl *avl_remove(avl_tree *tree, avl *item) {
avl *avl_remove(avl_tree_type *tree, avl *item) {
/* Stack of nodes. */
avl *pa[AVL_MAX_HEIGHT]; /* Nodes. */
unsigned char da[AVL_MAX_HEIGHT]; /* |avl_link[]| indexes. */
@ -306,7 +306,7 @@ int avl_walker(avl *node, int (*callback)(void * /*entry*/, void * /*data*/), vo
return total;
}
int avl_traverse(avl_tree *tree, int (*callback)(void * /*entry*/, void * /*data*/), void *data) {
int avl_traverse(avl_tree_type *tree, int (*callback)(void * /*entry*/, void * /*data*/), void *data) {
if(tree->root)
return avl_walker(tree->root, callback, data);
else
@ -396,7 +396,7 @@ int avl_traverse_lock(avl_tree_lock *tree, int (*callback)(void * /*entry*/, voi
return ret;
}
void avl_init(avl_tree *tree, int (*compar)(void * /*a*/, void * /*b*/)) {
void avl_init(avl_tree_type *tree, int (*compar)(void * /*a*/, void * /*b*/)) {
tree->root = NULL;
tree->compar = compar;
}

View File

@ -34,13 +34,13 @@ typedef struct avl {
} avl;
/* An AVL tree */
typedef struct avl_tree {
typedef struct avl_tree_type {
avl *root;
int (*compar)(void *a, void *b);
} avl_tree;
} avl_tree_type;
typedef struct avl_tree_lock {
avl_tree avl_tree;
avl_tree_type avl_tree;
#ifndef AVL_WITHOUT_PTHREADS
#ifdef AVL_LOCK_WITH_MUTEX
@ -60,7 +60,7 @@ typedef struct avl_tree_lock {
* be properly allocated by the caller.
*/
avl *avl_insert_lock(avl_tree_lock *tree, avl *item) NEVERNULL WARNUNUSED;
avl *avl_insert(avl_tree *tree, avl *item) NEVERNULL WARNUNUSED;
avl *avl_insert(avl_tree_type *tree, avl *item) NEVERNULL WARNUNUSED;
/* Remove an element a from the AVL tree t
* returns a pointer to the removed element
@ -68,22 +68,22 @@ avl *avl_insert(avl_tree *tree, avl *item) NEVERNULL WARNUNUSED;
* (equal as returned by t->compar())
*/
avl *avl_remove_lock(avl_tree_lock *tree, avl *item) WARNUNUSED;
avl *avl_remove(avl_tree *tree, avl *item) WARNUNUSED;
avl *avl_remove(avl_tree_type *tree, avl *item) WARNUNUSED;
/* Find the element into the tree that equal to a
* (equal as returned by t->compar())
* returns NULL is no element is equal to a
*/
avl *avl_search_lock(avl_tree_lock *tree, avl *item);
avl *avl_search(avl_tree *tree, avl *item);
avl *avl_search(avl_tree_type *tree, avl *item);
/* Initialize the avl_tree_lock
*/
void avl_init_lock(avl_tree_lock *tree, int (*compar)(void *a, void *b));
void avl_init(avl_tree *tree, int (*compar)(void *a, void *b));
void avl_init(avl_tree_type *tree, int (*compar)(void *a, void *b));
int avl_traverse_lock(avl_tree_lock *tree, int (*callback)(void *entry, void *data), void *data);
int avl_traverse(avl_tree *tree, int (*callback)(void *entry, void *data), void *data);
int avl_traverse(avl_tree_type *tree, int (*callback)(void *entry, void *data), void *data);
#endif /* avl.h */

View File

@ -111,7 +111,7 @@
#define CONFIG_VALUE_CHECKED 0x08 // has been checked if the value is different from the default
struct config_option {
avl avl; // the index entry of this entry - this has to be first!
avl avl_node; // the index entry of this entry - this has to be first!
uint8_t flags;
uint32_t hash; // a simple hash to speed up searching
@ -124,7 +124,7 @@ struct config_option {
};
struct section {
avl avl; // the index entry of this section - this has to be first!
avl avl_node; // the index entry of this section - this has to be first!
uint32_t hash; // a simple hash to speed up searching
// we first compare hashes, and only if the hashes are equal we do string comparisons

View File

@ -13,7 +13,7 @@ struct dictionary_stats {
};
typedef struct name_value {
avl avl; // the index - this has to be first!
avl avl_node; // the index - this has to be first!
uint32_t hash; // a simple hash to speed up searching
// we first compare hashes, and only if the hashes are equal we do string comparisons
@ -23,7 +23,7 @@ typedef struct name_value {
} NAME_VALUE;
typedef struct dictionary {
avl_tree values_index;
avl_tree_type values_index;
uint8_t flags;

View File

@ -80,7 +80,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL
}
if(unlikely(v->hash == this_hash && !strcmp(v->name, "this"))) {
n = (exp->this)?*exp->this:NAN;
n = (exp->myself)?*exp->myself:NAN;
buffer_strcat(exp->error_msg, "[ $this = ");
print_parsed_as_constant(exp->error_msg, n);
buffer_strcat(exp->error_msg, " ] ");

View File

@ -28,7 +28,7 @@ typedef struct eval_expression {
const char *parsed_as;
RRDCALC_STATUS *status;
calculated_number *this;
calculated_number *myself;
time_t *after;
time_t *before;

View File

@ -3,6 +3,10 @@
#ifndef NETDATA_LIB_H
#define NETDATA_LIB_H 1
# ifdef __cplusplus
extern "C" {
# endif
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@ -328,4 +332,8 @@ extern char *netdata_configured_host_prefix;
// BEWARE: Outside of the C code this also exists in alarm-notify.sh
#define DEFAULT_CLOUD_BASE_URL "https://app.netdata.cloud"
# ifdef __cplusplus
}
# endif
#endif // NETDATA_LIB_H

View File

@ -3,6 +3,10 @@
#ifndef NETDATA_LOG_H
#define NETDATA_LOG_H 1
# ifdef __cplusplus
extern "C" {
# endif
#include "../libnetdata.h"
#define D_WEB_BUFFER 0x0000000000000001
@ -98,4 +102,8 @@ extern void error_int( const char *prefix, const char *file, const char *functio
extern void fatal_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... ) NORETURN PRINTFLIKE(4, 5);
extern void log_access( const char *fmt, ... ) PRINTFLIKE(1, 2);
# ifdef __cplusplus
}
# endif
#endif /* NETDATA_LOG_H */

View File

@ -57,7 +57,7 @@ struct registry {
DICTIONARY *persons; // dictionary of REGISTRY_PERSON *, with key the REGISTRY_PERSON.guid
DICTIONARY *machines; // dictionary of REGISTRY_MACHINE *, with key the REGISTRY_MACHINE.guid
avl_tree registry_urls_root_index;
avl_tree_type registry_urls_root_index;
netdata_mutex_t lock;
};

View File

@ -30,7 +30,7 @@ typedef struct registry_person_url REGISTRY_PERSON_URL;
struct registry_person {
char guid[GUID_LEN + 1]; // the person GUID
avl_tree person_urls; // dictionary of PERSON_URLs
avl_tree_type person_urls; // dictionary of PERSON_URLs
uint32_t first_t; // the first time we saw this
uint32_t last_t; // the last time we saw this

View File

@ -58,7 +58,7 @@ struct spawn_cmd_info {
/* spawn command queue */
struct spawn_queue {
avl_tree cmd_tree;
avl_tree_type cmd_tree;
/* concurrency control of command queue */
uv_mutex_t mutex;