X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=src%2Frrd.h;h=2f4f2127fffb202b7b94510770d2bbc250fd536e;hb=f74a2240c8b8e7a469170d6300bfd4fb79ef52c1;hp=2b872ed7dccacb6b312fd4cbbe17622303f44834;hpb=1be6d4a6aebabe0f302b5f267bc3bdff6e084517;p=netdata.git diff --git a/src/rrd.h b/src/rrd.h index 2b872ed7..2f4f2127 100644 --- a/src/rrd.h +++ b/src/rrd.h @@ -273,7 +273,7 @@ struct rrdset { char *cache_dir; // the directory to store dimensions char cache_filename[FILENAME_MAX+1]; // the filename to store this set - pthread_rwlock_t rrdset_rwlock; // protects dimensions linked list + netdata_rwlock_t rrdset_rwlock; // protects dimensions linked list size_t counter; // the number of times we added values to this database size_t counter_done; // the number of times rrdset_done() has been called @@ -325,9 +325,10 @@ struct rrdset { }; typedef struct rrdset RRDSET; -#define rrdset_rdlock(st) pthread_rwlock_rdlock(&((st)->rrdset_rwlock)) -#define rrdset_wrlock(st) pthread_rwlock_wrlock(&((st)->rrdset_rwlock)) -#define rrdset_unlock(st) pthread_rwlock_unlock(&((st)->rrdset_rwlock)) +#define rrdset_rdlock(st) netdata_rwlock_rdlock(&((st)->rrdset_rwlock)) +#define rrdset_wrlock(st) netdata_rwlock_wrlock(&((st)->rrdset_rwlock)) +#define rrdset_unlock(st) netdata_rwlock_unlock(&((st)->rrdset_rwlock)) + // ---------------------------------------------------------------------------- // these loop macros make sure the linked list is accessed with the right lock @@ -375,7 +376,7 @@ struct rrdhost { uint32_t flags; // flags about this RRDHOST int rrd_update_every; // the update frequency of the host - int rrd_history_entries; // the number of history entries for the host's charts + long rrd_history_entries; // the number of history entries for the host's charts RRD_MEMORY_MODE rrd_memory_mode; // the memory more for the charts of this host char *cache_dir; // the directory to save RRD cache files @@ -393,7 +394,7 @@ struct rrdhost { volatile int rrdpush_error_shown:1; // 1 when we have logged a communication error int rrdpush_socket; // the fd of the socket to the remote host, or -1 pthread_t rrdpush_thread; // the sender thread - pthread_mutex_t rrdpush_mutex; // exclusive access to rrdpush_buffer + netdata_mutex_t rrdpush_mutex; // exclusive access to rrdpush_buffer int rrdpush_pipe[2]; // collector to sender thread communication BUFFER *rrdpush_buffer; // collector fills it, sender sends them @@ -439,7 +440,7 @@ struct rrdhost { // ------------------------------------------------------------------------ // locks - pthread_rwlock_t rrdhost_rwlock; // lock for this RRDHOST (protects rrdset_root linked list) + netdata_rwlock_t rrdhost_rwlock; // lock for this RRDHOST (protects rrdset_root linked list) avl_tree_lock rrdset_root_index; // the host's charts index (by id) avl_tree_lock rrdset_root_index_name; // the host's charts index (by name) @@ -452,9 +453,9 @@ struct rrdhost { typedef struct rrdhost RRDHOST; extern RRDHOST *localhost; -#define rrdhost_rdlock(h) pthread_rwlock_rdlock(&((h)->rrdhost_rwlock)) -#define rrdhost_wrlock(h) pthread_rwlock_wrlock(&((h)->rrdhost_rwlock)) -#define rrdhost_unlock(h) pthread_rwlock_unlock(&((h)->rrdhost_rwlock)) +#define rrdhost_rdlock(host) netdata_rwlock_rdlock(&((host)->rrdhost_rwlock)) +#define rrdhost_wrlock(host) netdata_rwlock_wrlock(&((host)->rrdhost_rwlock)) +#define rrdhost_unlock(host) netdata_rwlock_unlock(&((host)->rrdhost_rwlock)) // ---------------------------------------------------------------------------- // these loop macros make sure the linked list is accessed with the right lock @@ -469,10 +470,11 @@ extern RRDHOST *localhost; // ---------------------------------------------------------------------------- // global lock for all RRDHOSTs -extern pthread_rwlock_t rrd_rwlock; -#define rrd_rdlock() pthread_rwlock_rdlock(&rrd_rwlock) -#define rrd_wrlock() pthread_rwlock_wrlock(&rrd_rwlock) -#define rrd_unlock() pthread_rwlock_unlock(&rrd_rwlock) +extern netdata_rwlock_t rrd_rwlock; + +#define rrd_rdlock() netdata_rwlock_rdlock(&rrd_rwlock) +#define rrd_wrlock() netdata_rwlock_wrlock(&rrd_rwlock) +#define rrd_unlock() netdata_rwlock_unlock(&rrd_rwlock) // ---------------------------------------------------------------------------- @@ -489,7 +491,7 @@ extern RRDHOST *rrdhost_find_or_create( , const char *guid , const char *os , int update_every - , int history + , long history , RRD_MEMORY_MODE mode , int health_enabled , int rrdpush_enabled @@ -497,20 +499,20 @@ extern RRDHOST *rrdhost_find_or_create( , char *rrdpush_api_key ); -#ifdef NETDATA_INTERNAL_CHECKS -extern void rrdhost_check_wrlock_int(RRDHOST *host, const char *file, const char *function, const unsigned long line); -extern void rrdhost_check_rdlock_int(RRDHOST *host, const char *file, const char *function, const unsigned long line); -extern void rrdset_check_rdlock_int(RRDSET *st, const char *file, const char *function, const unsigned long line); -extern void rrdset_check_wrlock_int(RRDSET *st, const char *file, const char *function, const unsigned long line); -extern void rrd_check_rdlock_int(const char *file, const char *function, const unsigned long line); -extern void rrd_check_wrlock_int(const char *file, const char *function, const unsigned long line); - -#define rrdhost_check_rdlock(host) rrdhost_check_rdlock_int(host, __FILE__, __FUNCTION__, __LINE__) -#define rrdhost_check_wrlock(host) rrdhost_check_wrlock_int(host, __FILE__, __FUNCTION__, __LINE__) -#define rrdset_check_rdlock(st) rrdset_check_rdlock_int(st, __FILE__, __FUNCTION__, __LINE__) -#define rrdset_check_wrlock(st) rrdset_check_wrlock_int(st, __FILE__, __FUNCTION__, __LINE__) -#define rrd_check_rdlock() rrd_check_rdlock_int(__FILE__, __FUNCTION__, __LINE__) -#define rrd_check_wrlock() rrd_check_wrlock_int(__FILE__, __FUNCTION__, __LINE__) +#if defined(NETDATA_INTERNAL_CHECKS) && defined(NETDATA_VERIFY_LOCKS) +extern void __rrdhost_check_wrlock(RRDHOST *host, const char *file, const char *function, const unsigned long line); +extern void __rrdhost_check_rdlock(RRDHOST *host, const char *file, const char *function, const unsigned long line); +extern void __rrdset_check_rdlock(RRDSET *st, const char *file, const char *function, const unsigned long line); +extern void __rrdset_check_wrlock(RRDSET *st, const char *file, const char *function, const unsigned long line); +extern void __rrd_check_rdlock(const char *file, const char *function, const unsigned long line); +extern void __rrd_check_wrlock(const char *file, const char *function, const unsigned long line); + +#define rrdhost_check_rdlock(host) __rrdhost_check_rdlock(host, __FILE__, __FUNCTION__, __LINE__) +#define rrdhost_check_wrlock(host) __rrdhost_check_wrlock(host, __FILE__, __FUNCTION__, __LINE__) +#define rrdset_check_rdlock(st) __rrdset_check_rdlock(st, __FILE__, __FUNCTION__, __LINE__) +#define rrdset_check_wrlock(st) __rrdset_check_wrlock(st, __FILE__, __FUNCTION__, __LINE__) +#define rrd_check_rdlock() __rrd_check_rdlock(__FILE__, __FUNCTION__, __LINE__) +#define rrd_check_wrlock() __rrd_check_wrlock(__FILE__, __FUNCTION__, __LINE__) #else #define rrdhost_check_rdlock(host) (void)0