locks abstraction, error reporting, debugging
Costa Tsaousis (ktsaou) committed
Mar 12, 2017 at 16:54 UTC
68c6d537788b9c11670903bce2e9806933a3322a
23 files changed
+484
-173
CMakeLists.txt
+1
-1
@@ -144,7 +144,7 @@ set(NETDATA_SOURCE_FILES
144
src/web_client.h
145
src/web_server.c
146
src/web_server.h
147
- )
147
+ src/locks.h)
148
149
set(APPS_PLUGIN_SOURCE_FILES
150
src/appconfig.c
src/Makefile.am
+100
-52
@@ -38,74 +38,120 @@ plugins_PROGRAMS += freeipmi.plugin
38
endif
39
40
netdata_SOURCES = \
41
- appconfig.c appconfig.h \
42
- adaptive_resortable_list.c adaptive_resortable_list.h \
43
- avl.c avl.h \
44
- backends.c backends.h \
45
- clocks.c clocks.h \
46
- common.c common.h \
47
- daemon.c daemon.h \
48
- dictionary.c dictionary.h \
49
- eval.c eval.h \
50
- global_statistics.c global_statistics.h \
51
- health.c health.h health_log.c health_config.c health_json.c \
41
+ adaptive_resortable_list.c \
42
+ adaptive_resortable_list.h \
43
+ appconfig.c \
44
+ appconfig.h \
45
+ avl.c \
46
+ avl.h \
47
+ backends.c \
48
+ backends.h \
49
+ clocks.c \
50
+ clocks.h \
51
+ common.c \
52
+ common.h \
53
+ daemon.c \
54
+ daemon.h \
55
+ dictionary.c \
56
+ dictionary.h \
57
+ eval.c \
58
+ eval.h \
59
+ global_statistics.c \
60
+ global_statistics.h \
61
+ health.c \
62
+ health.h \
63
+ health_config.c \
64
+ health_json.c \
65
+ health_log.c \
66
inlined.h \
53
- log.c log.h \
54
- main.c main.h \
55
- plugin_checks.c plugin_checks.h \
56
- plugin_idlejitter.c plugin_idlejitter.h \
57
- plugin_nfacct.c plugin_nfacct.h \
58
- plugin_tc.c plugin_tc.h \
59
- plugins_d.c plugins_d.h \
60
- popen.c popen.h \
61
- socket.c socket.h \
62
- simple_pattern.c simple_pattern.h \
63
- sys_fs_cgroup.c \
64
- sys_devices_system_edac_mc.c \
65
- sys_devices_system_node.c \
66
- procfile.c procfile.h \
67
- proc_self_mountinfo.c proc_self_mountinfo.h \
68
- registry.c registry.h \
69
- registry_internals.c registry_internals.h \
70
- registry_url.c registry_url.h \
71
- registry_person.c registry_person.h \
72
- registry_machine.c registry_machine.h \
73
- registry_init.c \
67
+ locks.h \
68
+ log.c \
69
+ log.h \
70
+ main.c \
71
+ main.h \
72
+ plugin_checks.c \
73
+ plugin_checks.h \
74
+ plugin_idlejitter.c \
75
+ plugin_idlejitter.h \
76
+ plugin_nfacct.c \
77
+ plugin_nfacct.h \
78
+ plugin_tc.c \
79
+ plugin_tc.h \
80
+ plugins_d.c \
81
+ plugins_d.h \
82
+ popen.c \
83
+ popen.h \
84
+ proc_self_mountinfo.c \
85
+ proc_self_mountinfo.h \
86
+ procfile.c \
87
+ procfile.h \
88
+ registry.c \
89
+ registry.h \
90
registry_db.c \
91
+ registry_init.c \
92
+ registry_internals.c \
93
+ registry_internals.h \
94
registry_log.c \
76
- rrd.c rrd.h \
95
+ registry_machine.c \
96
+ registry_machine.h \
97
+ registry_person.c \
98
+ registry_person.h \
99
+ registry_url.c \
100
+ registry_url.h \
101
+ rrd.c \
102
+ rrd.h \
103
+ rrd2json.c \
104
+ rrd2json.h \
105
+ rrd2json_api_old.c \
106
+ rrd2json_api_old.h \
107
+ rrdcalc.c \
108
+ rrdcalctemplate.c \
109
rrddim.c \
110
+ rrddimvar.c \
111
rrdfamily.c \
112
rrdhost.c \
113
+ rrdpush.c \
114
+ rrdpush.h \
115
rrdset.c \
81
- rrdcalc.c \
82
- rrdcalctemplate.c \
83
- rrdvar.c \
84
- rrddimvar.c \
116
rrdsetvar.c \
86
- rrd2json.c rrd2json.h \
87
- rrd2json_api_old.c rrd2json_api_old.h \
88
- rrdpush.c rrdpush.h \
89
- storage_number.c storage_number.h \
90
- unit_test.c unit_test.h \
117
+ rrdvar.c \
118
+ simple_pattern.c \
119
+ simple_pattern.h \
120
+ socket.c \
121
+ socket.h \
122
+ storage_number.c \
123
+ storage_number.h \
124
+ sys_devices_system_edac_mc.c \
125
+ sys_devices_system_node.c \
126
+ sys_fs_cgroup.c \
127
+ unit_test.c \
128
+ unit_test.h \
129
url.c url.h \
92
- web_api_old.c web_api_old.h \
93
- web_api_v1.c web_api_v1.h \
94
- web_buffer.c web_buffer.h \
95
- web_buffer_svg.c web_buffer_svg.h \
96
- web_client.c web_client.h \
97
- web_server.c web_server.h \
130
+ web_api_old.c \
131
+ web_api_old.h \
132
+ web_api_v1.c \
133
+ web_api_v1.h \
134
+ web_buffer.c \
135
+ web_buffer.h \
136
+ web_buffer_svg.c \
137
+ web_buffer_svg.h \
138
+ web_client.c \
139
+ web_client.h \
140
+ web_server.c \
141
+ web_server.h \
142
$(NULL)
143
144
if FREEBSD
145
netdata_SOURCES += \
102
- plugin_freebsd.c plugin_freebsd.h \
146
+ plugin_freebsd.c \
147
+ plugin_freebsd.h \
148
freebsd_sysctl.c \
149
$(NULL)
150
else
151
if MACOS
152
netdata_SOURCES += \
108
- plugin_macos.c plugin_macos.h \
153
+ plugin_macos.c \
154
+ plugin_macos.h \
155
macos_sysctl.c \
156
macos_mach_smi.c \
157
macos_fw.c \
@@ -113,8 +159,10 @@ netdata_SOURCES += \
159
else
160
netdata_SOURCES += \
161
ipc.c ipc.h \
116
- plugin_proc.c plugin_proc.h \
117
- plugin_proc_diskspace.c plugin_proc_diskspace.h \
162
+ plugin_proc.c \
163
+ plugin_proc.h \
164
+ plugin_proc_diskspace.c \
165
+ plugin_proc_diskspace.h \
166
proc_diskstats.c \
167
proc_interrupts.c \
168
proc_softirqs.c \
src/appconfig.c
+7
-7
@@ -36,7 +36,7 @@ struct section {
36
struct config_option *values;
37
avl_tree_lock values_index;
38
39
- pthread_mutex_t mutex; // this locks only the writers, to ensure atomic updates
39
+ netdata_mutex_t mutex; // this locks only the writers, to ensure atomic updates
40
// readers are protected using the rwlock in avl_tree_lock
41
};
42
@@ -44,7 +44,7 @@ static int appconfig_section_compare(void *a, void *b);
44
45
struct config netdata_config = {
46
.sections = NULL,
47
- .mutex = PTHREAD_MUTEX_INITIALIZER,
47
+ .mutex = NETDATA_MUTEX_INITIALIZER,
48
.index = {
49
{ NULL, appconfig_section_compare },
50
AVL_LOCK_INITIALIZER
@@ -53,7 +53,7 @@ struct config netdata_config = {
53
54
struct config stream_config = {
55
.sections = NULL,
56
- .mutex = PTHREAD_MUTEX_INITIALIZER,
56
+ .mutex = NETDATA_MUTEX_INITIALIZER,
57
.index = {
58
{ NULL, appconfig_section_compare },
59
AVL_LOCK_INITIALIZER
@@ -64,19 +64,19 @@ struct config stream_config = {
64
// locking
65
66
static inline void appconfig_wrlock(struct config *root) {
67
- pthread_mutex_lock(&root->mutex);
67
+ netdata_mutex_lock(&root->mutex);
68
}
69
70
static inline void appconfig_unlock(struct config *root) {
71
- pthread_mutex_unlock(&root->mutex);
71
+ netdata_mutex_unlock(&root->mutex);
72
}
73
74
static inline void config_section_wrlock(struct section *co) {
75
- pthread_mutex_lock(&co->mutex);
75
+ netdata_mutex_lock(&co->mutex);
76
}
77
78
static inline void config_section_unlock(struct section *co) {
79
- pthread_mutex_unlock(&co->mutex);
79
+ netdata_mutex_unlock(&co->mutex);
80
}
81
82
src/appconfig.h
+1
-1
@@ -18,7 +18,7 @@
18
19
struct config {
20
struct section *sections;
21
- pthread_mutex_t mutex;
21
+ netdata_mutex_t mutex;
22
avl_tree_lock index;
23
};
24
src/avl.c
+8
-14
@@ -315,11 +315,9 @@ int avl_traverse(avl_tree *t, int (*callback)(void *entry, void *data), void *da
315
void avl_read_lock(avl_tree_lock *t) {
316
#ifndef AVL_WITHOUT_PTHREADS
317
#ifdef AVL_LOCK_WITH_MUTEX
318
- if(unlikely(pthread_mutex_lock(&t->mutex) != 0))
319
- error("Cannot get mutex of an AVL");
318
+ netdata_mutex_lock(&t->mutex);
319
#else
321
- if(unlikely(pthread_rwlock_rdlock(&t->rwlock) != 0))
322
- error("Cannot get read lock of an AVL");
320
+ netdata_rwlock_rdlock(&t->rwlock);
321
#endif
322
#endif /* AVL_WITHOUT_PTHREADS */
323
}
@@ -327,11 +325,9 @@ void avl_read_lock(avl_tree_lock *t) {
325
void avl_write_lock(avl_tree_lock *t) {
326
#ifndef AVL_WITHOUT_PTHREADS
327
#ifdef AVL_LOCK_WITH_MUTEX
330
- if(unlikely(pthread_mutex_lock(&t->mutex) != 0)
331
- error("Cannot get mutex of an AVL");
328
+ netdata_mutex_lock(&t->mutex);
329
#else
333
- if(unlikely(pthread_rwlock_wrlock(&t->rwlock) != 0))
334
- error("Cannot write lock an AVL.");
330
+ netdata_rwlock_wrlock(&t->rwlock);
331
#endif
332
#endif /* AVL_WITHOUT_PTHREADS */
333
}
@@ -339,11 +335,9 @@ void avl_write_lock(avl_tree_lock *t) {
335
void avl_unlock(avl_tree_lock *t) {
336
#ifndef AVL_WITHOUT_PTHREADS
337
#ifdef AVL_LOCK_WITH_MUTEX
342
- if(unlikely(pthread_mutex_unlock(&t->mutex) != 0))
343
- error("Cannot unlock mutex of an AVL");
338
+ netdata_mutex_unlock(&t->mutex);
339
#else
345
- if(unlikely(pthread_rwlock_unlock(&t->rwlock) != 0))
346
- error("Cannot unlock an AVL");
340
+ netdata_rwlock_unlock(&t->rwlock);
341
#endif
342
#endif /* AVL_WITHOUT_PTHREADS */
343
}
@@ -358,9 +352,9 @@ void avl_init_lock(avl_tree_lock *t, int (*compar)(void *a, void *b)) {
352
int lock;
353
354
#ifdef AVL_LOCK_WITH_MUTEX
361
- lock = pthread_mutex_init(&t->mutex, NULL);
355
+ lock = netdata_mutex_init(&t->mutex, NULL);
356
#else
363
- lock = pthread_rwlock_init(&t->rwlock, NULL);
357
+ lock = netdata_rwlock_init(&t->rwlock);
358
#endif
359
360
if(lock != 0)
src/avl.h
+4
-4
@@ -13,9 +13,9 @@
13
// #define AVL_LOCK_WITH_MUTEX 1
14
15
#ifdef AVL_LOCK_WITH_MUTEX
16
-#define AVL_LOCK_INITIALIZER PTHREAD_MUTEX_INITIALIZER
16
+#define AVL_LOCK_INITIALIZER NETDATA_MUTEX_INITIALIZER
17
#else /* AVL_LOCK_WITH_MUTEX */
18
-#define AVL_LOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER
18
+#define AVL_LOCK_INITIALIZER NETDATA_RWLOCK_INITIALIZER
19
#endif /* AVL_LOCK_WITH_MUTEX */
20
21
#else /* AVL_WITHOUT_PTHREADS */
@@ -41,9 +41,9 @@ typedef struct avl_tree_lock {
41
42
#ifndef AVL_WITHOUT_PTHREADS
43
#ifdef AVL_LOCK_WITH_MUTEX
44
- pthread_mutex_t mutex;
44
+ netdata_mutex_t mutex;
45
#else /* AVL_LOCK_WITH_MUTEX */
46
- pthread_rwlock_t rwlock;
46
+ netdata_rwlock_t rwlock;
47
#endif /* AVL_LOCK_WITH_MUTEX */
48
#endif /* AVL_WITHOUT_PTHREADS */
49
} avl_tree_lock;
src/common.h
+3
-2
@@ -168,10 +168,11 @@
168
// ----------------------------------------------------------------------------
169
// netdata include files
170
171
-#include "simple_pattern.h"
172
-#include "avl.h"
171
#include "clocks.h"
172
#include "log.h"
173
+#include "locks.h"
174
+#include "simple_pattern.h"
175
+#include "avl.h"
176
#include "global_statistics.h"
177
#include "storage_number.h"
178
#include "web_buffer.h"
src/dictionary.c
+8
-6
@@ -31,21 +31,21 @@ static inline void NETDATA_DICTIONARY_STATS_ENTRIES_MINUS1(DICTIONARY *dict) {
31
static inline void dictionary_read_lock(DICTIONARY *dict) {
32
if(likely(dict->rwlock)) {
33
// debug(D_DICTIONARY, "Dictionary READ lock");
34
- pthread_rwlock_rdlock(dict->rwlock);
34
+ netdata_rwlock_rdlock(dict->rwlock);
35
}
36
}
37
38
static inline void dictionary_write_lock(DICTIONARY *dict) {
39
if(likely(dict->rwlock)) {
40
// debug(D_DICTIONARY, "Dictionary WRITE lock");
41
- pthread_rwlock_wrlock(dict->rwlock);
41
+ netdata_rwlock_wrlock(dict->rwlock);
42
}
43
}
44
45
static inline void dictionary_unlock(DICTIONARY *dict) {
46
if(likely(dict->rwlock)) {
47
// debug(D_DICTIONARY, "Dictionary UNLOCK lock");
48
- pthread_rwlock_unlock(dict->rwlock);
48
+ netdata_rwlock_unlock(dict->rwlock);
49
}
50
}
51
@@ -135,8 +135,8 @@ DICTIONARY *dictionary_create(uint8_t flags) {
135
dict->stats = callocz(1, sizeof(struct dictionary_stats));
136
137
if(!(flags & DICTIONARY_FLAG_SINGLE_THREADED)) {
138
- dict->rwlock = callocz(1, sizeof(pthread_rwlock_t));
139
- pthread_rwlock_init(dict->rwlock, NULL);
138
+ dict->rwlock = callocz(1, sizeof(netdata_rwlock_t));
139
+ netdata_rwlock_init(dict->rwlock);
140
}
141
142
avl_init(&dict->values_index, name_value_compare);
@@ -158,8 +158,10 @@ void dictionary_destroy(DICTIONARY *dict) {
158
if(dict->stats)
159
freez(dict->stats);
160
161
- if(dict->rwlock)
161
+ if(dict->rwlock) {
162
+ netdata_rwlock_destroy(dict->rwlock);
163
freez(dict->rwlock);
164
+ }
165
166
freez(dict);
167
}
src/dictionary.h
+1
-1
@@ -24,7 +24,7 @@ typedef struct dictionary {
24
uint8_t flags;
25
26
struct dictionary_stats *stats;
27
- pthread_rwlock_t *rwlock;
27
+ netdata_rwlock_t *rwlock;
28
} DICTIONARY;
29
30
#define DICTIONARY_FLAG_DEFAULT 0x00000000
src/global_statistics.c
+3
-3
@@ -10,14 +10,14 @@ volatile struct global_statistics global_statistics = {
10
.compressed_content_size = 0
11
};
12
13
-pthread_mutex_t global_statistics_mutex = PTHREAD_MUTEX_INITIALIZER;
13
+netdata_mutex_t global_statistics_mutex = NETDATA_MUTEX_INITIALIZER;
14
15
inline void global_statistics_lock(void) {
16
- pthread_mutex_lock(&global_statistics_mutex);
16
+ netdata_mutex_lock(&global_statistics_mutex);
17
}
18
19
inline void global_statistics_unlock(void) {
20
- pthread_mutex_unlock(&global_statistics_mutex);
20
+ netdata_mutex_unlock(&global_statistics_mutex);
21
}
22
23
void finished_web_request_statistics(uint64_t dt,
src/health.c
+4
-4
@@ -208,7 +208,7 @@ static inline void health_alarm_log_process(RRDHOST *host) {
208
uint32_t first_waiting = (host->health_log.alarms)?host->health_log.alarms->unique_id:0;
209
time_t now = now_realtime_sec();
210
211
- pthread_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
211
+ netdata_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
212
213
ALARM_ENTRY *ae;
214
for(ae = host->health_log.alarms; ae && ae->unique_id >= stop_at_id ; ae = ae->next) {
@@ -228,13 +228,13 @@ static inline void health_alarm_log_process(RRDHOST *host) {
228
// remember this for the next iteration
229
stop_at_id = first_waiting;
230
231
- pthread_rwlock_unlock(&host->health_log.alarm_log_rwlock);
231
+ netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
232
233
if(host->health_log.count <= host->health_log.max)
234
return;
235
236
// cleanup excess entries in the log
237
- pthread_rwlock_wrlock(&host->health_log.alarm_log_rwlock);
237
+ netdata_rwlock_wrlock(&host->health_log.alarm_log_rwlock);
238
239
ALARM_ENTRY *last = NULL;
240
unsigned int count = host->health_log.max * 2 / 3;
@@ -256,7 +256,7 @@ static inline void health_alarm_log_process(RRDHOST *host) {
256
host->health_log.count--;
257
}
258
259
- pthread_rwlock_unlock(&host->health_log.alarm_log_rwlock);
259
+ netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
260
}
261
262
static inline int rrdcalc_isrunnable(RRDCALC *rc, time_t now, time_t *next_run) {
src/health.h
+1
-1
@@ -334,7 +334,7 @@ typedef struct alarm_log {
334
unsigned int count;
335
unsigned int max;
336
ALARM_ENTRY *alarms;
337
- pthread_rwlock_t alarm_log_rwlock;
337
+ netdata_rwlock_t alarm_log_rwlock;
338
} ALARM_LOG;
339
340
#include "rrd.h"
src/health_json.c
+2
-2
@@ -85,7 +85,7 @@ static inline void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, R
85
}
86
87
void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after) {
88
- pthread_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
88
+ netdata_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
89
90
buffer_strcat(wb, "[");
91
@@ -101,7 +101,7 @@ void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after) {
101
102
buffer_strcat(wb, "\n]\n");
103
104
- pthread_rwlock_unlock(&host->health_log.alarm_log_rwlock);
104
+ netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
105
}
106
107
static inline void health_rrdcalc2json_nolock(RRDHOST *host, BUFFER *wb, RRDCALC *rc) {
src/health_log.c
+8
-8
@@ -129,7 +129,7 @@ inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filena
129
size_t line = 0, len = 0;
130
ssize_t loaded = 0, updated = 0, errored = 0, duplicate = 0;
131
132
- pthread_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
132
+ netdata_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
133
134
while((s = fgets_trim_len(buf, 65536, fp, &len))) {
135
host->health_log_entries_written++;
@@ -297,7 +297,7 @@ inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filena
297
}
298
}
299
300
- pthread_rwlock_unlock(&host->health_log.alarm_log_rwlock);
300
+ netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
301
302
freez(buf);
303
@@ -404,14 +404,14 @@ inline void health_alarm_log(
404
ae->non_clear_duration += ae->duration;
405
406
// link it
407
- pthread_rwlock_wrlock(&host->health_log.alarm_log_rwlock);
407
+ netdata_rwlock_wrlock(&host->health_log.alarm_log_rwlock);
408
ae->next = host->health_log.alarms;
409
host->health_log.alarms = ae;
410
host->health_log.count++;
411
- pthread_rwlock_unlock(&host->health_log.alarm_log_rwlock);
411
+ netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
412
413
// match previous alarms
414
- pthread_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
414
+ netdata_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
415
ALARM_ENTRY *t;
416
for(t = host->health_log.alarms ; t ; t = t->next) {
417
if(t != ae && t->alarm_id == ae->alarm_id) {
@@ -431,7 +431,7 @@ inline void health_alarm_log(
431
break;
432
}
433
}
434
- pthread_rwlock_unlock(&host->health_log.alarm_log_rwlock);
434
+ netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
435
436
health_alarm_log_save(host, ae);
437
}
@@ -453,7 +453,7 @@ inline void health_alarm_log_free_one_nochecks_nounlink(ALARM_ENTRY *ae) {
453
inline void health_alarm_log_free(RRDHOST *host) {
454
rrdhost_check_wrlock(host);
455
456
- pthread_rwlock_wrlock(&host->health_log.alarm_log_rwlock);
456
+ netdata_rwlock_wrlock(&host->health_log.alarm_log_rwlock);
457
458
ALARM_ENTRY *ae;
459
while((ae = host->health_log.alarms)) {
@@ -461,5 +461,5 @@ inline void health_alarm_log_free(RRDHOST *host) {
461
health_alarm_log_free_one_nochecks_nounlink(ae);
462
}
463
464
- pthread_rwlock_unlock(&host->health_log.alarm_log_rwlock);
464
+ netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
465
}
src/locks.h
new
+294
@@ -0,0 +1,294 @@
1
+#ifndef NETDATA_LOCKS_H
2
+#define NETDATA_LOCKS_H
3
+
4
+// ----------------------------------------------------------------------------
5
+// mutex
6
+
7
+typedef pthread_mutex_t netdata_mutex_t;
8
+
9
+#define NETDATA_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
10
+
11
+static inline int __netdata_mutex_init(netdata_mutex_t *mutex) {
12
+ int ret = pthread_mutex_init(mutex, NULL);
13
+ if(unlikely(ret != 0))
14
+ error("MUTEX_LOCK: failed to initialize (code %d).", ret);
15
+ return ret;
16
+}
17
+
18
+static inline int __netdata_mutex_lock(netdata_mutex_t *mutex) {
19
+ int ret = pthread_mutex_lock(mutex);
20
+ if(unlikely(ret != 0))
21
+ error("MUTEX_LOCK: failed to get lock (code %d)", ret);
22
+ return ret;
23
+}
24
+
25
+static inline int __netdata_mutex_trylock(netdata_mutex_t *mutex) {
26
+ int ret = pthread_mutex_trylock(mutex);
27
+ return ret;
28
+}
29
+
30
+static inline int __netdata_mutex_unlock(netdata_mutex_t *mutex) {
31
+ int ret = pthread_mutex_unlock(mutex);
32
+ if(unlikely(ret != 0))
33
+ error("MUTEX_LOCK: failed to unlock (code %d).", ret);
34
+ return ret;
35
+}
36
+
37
+#ifdef NETDATA_INTERNAL_CHECKS
38
+
39
+static inline int netdata_mutex_init_debug( const char *file, const char *function, const unsigned long line, netdata_mutex_t *mutex) {
40
+ usec_t start = 0;
41
+
42
+ if(unlikely(debug_flags & D_LOCKS)) {
43
+ start = now_boottime_usec();
44
+ debug(D_LOCKS, "MUTEX_LOCK: netdata_mutex_init() from %lu@%s, %s()", line, file, function);
45
+ }
46
+
47
+ int ret = __netdata_mutex_init(mutex);
48
+
49
+ debug(D_LOCKS, "MUTEX_LOCK: netdata_mutex_init() = %d in %llu usec, from %lu@%s, %s()", ret, now_boottime_usec() - start, line, file, function);
50
+
51
+ return ret;
52
+}
53
+
54
+static inline int netdata_mutex_lock_debug( const char *file, const char *function, const unsigned long line, netdata_mutex_t *mutex) {
55
+ usec_t start = 0;
56
+
57
+ if(unlikely(debug_flags & D_LOCKS)) {
58
+ start = now_boottime_usec();
59
+ debug(D_LOCKS, "MUTEX_LOCK: netdata_mutex_lock() from %lu@%s, %s()", line, file, function);
60
+ }
61
+
62
+ int ret = __netdata_mutex_lock(mutex);
63
+
64
+ debug(D_LOCKS, "MUTEX_LOCK: netdata_mutex_lock() = %d in %llu usec, from %lu@%s, %s()", ret, now_boottime_usec() - start, line, file, function);
65
+
66
+ return ret;
67
+}
68
+
69
+static inline int netdata_mutex_trylock_debug( const char *file, const char *function, const unsigned long line, netdata_mutex_t *mutex) {
70
+ usec_t start = 0;
71
+
72
+ if(unlikely(debug_flags & D_LOCKS)) {
73
+ start = now_boottime_usec();
74
+ debug(D_LOCKS, "MUTEX_LOCK: netdata_mutex_trylock() from %lu@%s, %s()", line, file, function);
75
+ }
76
+
77
+ int ret = __netdata_mutex_trylock(mutex);
78
+
79
+ debug(D_LOCKS, "MUTEX_LOCK: netdata_mutex_trylock() = %d in %llu usec, from %lu@%s, %s()", ret, now_boottime_usec() - start, line, file, function);
80
+
81
+ return ret;
82
+}
83
+
84
+static inline int netdata_mutex_unlock_debug( const char *file, const char *function, const unsigned long line, netdata_mutex_t *mutex) {
85
+ usec_t start = 0;
86
+
87
+ if(unlikely(debug_flags & D_LOCKS)) {
88
+ start = now_boottime_usec();
89
+ debug(D_LOCKS, "MUTEX_LOCK: netdata_mutex_unlock() from %lu@%s, %s()", line, file, function);
90
+ }
91
+
92
+ int ret = __netdata_mutex_unlock(mutex);
93
+
94
+ debug(D_LOCKS, "MUTEX_LOCK: netdata_mutex_unlock() = %d in %llu usec, from %lu@%s, %s()", ret, now_boottime_usec() - start, line, file, function);
95
+
96
+ return ret;
97
+}
98
+
99
+#define netdata_mutex_init(mutex) netdata_mutex_init_debug(__FILE__, __FUNCTION__, __LINE__, mutex)
100
+#define netdata_mutex_lock(mutex) netdata_mutex_lock_debug(__FILE__, __FUNCTION__, __LINE__, mutex)
101
+#define netdata_mutex_trylock(mutex) netdata_mutex_trylock_debug(__FILE__, __FUNCTION__, __LINE__, mutex)
102
+#define netdata_mutex_unlock(mutex) netdata_mutex_unlock_debug(__FILE__, __FUNCTION__, __LINE__, mutex)
103
+
104
+#else // !NETDATA_INTERNAL_CHECKS
105
+
106
+#define netdata_mutex_init(mutex) __netdata_mutex_init(mutex)
107
+#define netdata_mutex_lock(mutex) __netdata_mutex_lock(mutex)
108
+#define netdata_mutex_trylock(mutex) __netdata_mutex_trylock(mutex)
109
+#define netdata_mutex_unlock(mutex) __netdata_mutex_unlock(mutex)
110
+
111
+#endif // NETDATA_INTERNAL_CHECKS
112
+
113
+
114
+// ----------------------------------------------------------------------------
115
+// r/w lock
116
+
117
+typedef pthread_rwlock_t netdata_rwlock_t;
118
+
119
+#define NETDATA_RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER
120
+
121
+static inline int __netdata_rwlock_destroy(netdata_rwlock_t *rwlock) {
122
+ int ret = pthread_rwlock_destroy(rwlock);
123
+ if(unlikely(ret != 0))
124
+ error("RW_LOCK: failed to destroy lock (code %d)", ret);
125
+ return ret;
126
+}
127
+
128
+static inline int __netdata_rwlock_init(netdata_rwlock_t *rwlock) {
129
+ int ret = pthread_rwlock_init(rwlock, NULL);
130
+ if(unlikely(ret != 0))
131
+ error("RW_LOCK: failed to initialize lock (code %d)", ret);
132
+ return ret;
133
+}
134
+
135
+static inline int __netdata_rwlock_rdlock(netdata_rwlock_t *rwlock) {
136
+ int ret = pthread_rwlock_rdlock(rwlock);
137
+ if(unlikely(ret != 0))
138
+ error("RW_LOCK: failed to obtain read lock (code %d)", ret);
139
+ return ret;
140
+}
141
+
142
+static inline int __netdata_rwlock_wrlock(netdata_rwlock_t *rwlock) {
143
+ int ret = pthread_rwlock_wrlock(rwlock);
144
+ if(unlikely(ret != 0))
145
+ error("RW_LOCK: failed to obtain write lock (code %d)", ret);
146
+ return ret;
147
+}
148
+
149
+static inline int __netdata_rwlock_unlock(netdata_rwlock_t *rwlock) {
150
+ int ret = pthread_rwlock_unlock(rwlock);
151
+ if(unlikely(ret != 0))
152
+ error("RW_LOCK: failed to release lock (code %d)", ret);
153
+ return ret;
154
+}
155
+
156
+static inline int __netdata_rwlock_tryrdlock(netdata_rwlock_t *rwlock) {
157
+ int ret = pthread_rwlock_tryrdlock(rwlock);
158
+ return ret;
159
+}
160
+
161
+static inline int __netdata_rwlock_trywrlock(netdata_rwlock_t *rwlock) {
162
+ int ret = pthread_rwlock_trywrlock(rwlock);
163
+ return ret;
164
+}
165
+
166
+
167
+#ifdef NETDATA_INTERNAL_CHECKS
168
+
169
+static inline int netdata_rwlock_destroy_debug( const char *file, const char *function, const unsigned long line, netdata_rwlock_t *rwlock) {
170
+ usec_t start = 0;
171
+
172
+ if(unlikely(debug_flags & D_LOCKS)) {
173
+ start = now_boottime_usec();
174
+ debug(D_LOCKS, "RW_LOCK: netdata_rwlock_destroy() from %lu@%s, %s()", line, file, function);
175
+ }
176
+
177
+ int ret = __netdata_rwlock_destroy(rwlock);
178
+
179
+ debug(D_LOCKS, "RW_LOCK: netdata_rwlock_destroy() = %d in %llu usec, from %lu@%s, %s()", ret, now_boottime_usec() - start, line, file, function);
180
+
181
+ return ret;
182
+}
183
+
184
+static inline int netdata_rwlock_init_debug( const char *file, const char *function, const unsigned long line, netdata_rwlock_t *rwlock) {
185
+ usec_t start = 0;
186
+
187
+ if(unlikely(debug_flags & D_LOCKS)) {
188
+ start = now_boottime_usec();
189
+ debug(D_LOCKS, "RW_LOCK: netdata_rwlock_init() from %lu@%s, %s()", line, file, function);
190
+ }
191
+
192
+ int ret = __netdata_rwlock_init(rwlock);
193
+
194
+ debug(D_LOCKS, "RW_LOCK: netdata_rwlock_init() = %d in %llu usec, from %lu@%s, %s()", ret, now_boottime_usec() - start, line, file, function);
195
+
196
+ return ret;
197
+}
198
+
199
+static inline int netdata_rwlock_rdlock_debug( const char *file, const char *function, const unsigned long line, netdata_rwlock_t *rwlock) {
200
+ usec_t start = 0;
201
+
202
+ if(unlikely(debug_flags & D_LOCKS)) {
203
+ start = now_boottime_usec();
204
+ debug(D_LOCKS, "RW_LOCK: netdata_rwlock_rdlock() from %lu@%s, %s()", line, file, function);
205
+ }
206
+
207
+ int ret = __netdata_rwlock_rdlock(rwlock);
208
+
209
+ debug(D_LOCKS, "RW_LOCK: netdata_rwlock_rdlock() = %d in %llu usec, from %lu@%s, %s()", ret, now_boottime_usec() - start, line, file, function);
210
+
211
+ return ret;
212
+}
213
+
214
+static inline int netdata_rwlock_wrlock_debug( const char *file, const char *function, const unsigned long line, netdata_rwlock_t *rwlock) {
215
+ usec_t start = 0;
216
+
217
+ if(unlikely(debug_flags & D_LOCKS)) {
218
+ start = now_boottime_usec();
219
+ debug(D_LOCKS, "RW_LOCK: netdata_rwlock_wrlock() from %lu@%s, %s()", line, file, function);
220
+ }
221
+
222
+ int ret = __netdata_rwlock_wrlock(rwlock);
223
+
224
+ debug(D_LOCKS, "RW_LOCK: netdata_rwlock_wrlock() = %d in %llu usec, from %lu@%s, %s()", ret, now_boottime_usec() - start, line, file, function);
225
+
226
+ return ret;
227
+}
228
+
229
+static inline int netdata_rwlock_unlock_debug( const char *file, const char *function, const unsigned long line, netdata_rwlock_t *rwlock) {
230
+ usec_t start = 0;
231
+
232
+ if(unlikely(debug_flags & D_LOCKS)) {
233
+ start = now_boottime_usec();
234
+ debug(D_LOCKS, "RW_LOCK: netdata_rwlock_unlock() from %lu@%s, %s()", line, file, function);
235
+ }
236
+
237
+ int ret = __netdata_rwlock_unlock(rwlock);
238
+
239
+ debug(D_LOCKS, "RW_LOCK: netdata_rwlock_unlock() = %d in %llu usec, from %lu@%s, %s()", ret, now_boottime_usec() - start, line, file, function);
240
+
241
+ return ret;
242
+}
243
+
244
+static inline int netdata_rwlock_tryrdlock_debug( const char *file, const char *function, const unsigned long line, netdata_rwlock_t *rwlock) {
245
+ usec_t start = 0;
246
+
247
+ if(unlikely(debug_flags & D_LOCKS)) {
248
+ start = now_boottime_usec();
249
+ debug(D_LOCKS, "RW_LOCK: netdata_rwlock_tryrdlock() from %lu@%s, %s()", line, file, function);
250
+ }
251
+
252
+ int ret = __netdata_rwlock_tryrdlock(rwlock);
253
+
254
+ debug(D_LOCKS, "RW_LOCK: netdata_rwlock_tryrdlock() = %d in %llu usec, from %lu@%s, %s()", ret, now_boottime_usec() - start, line, file, function);
255
+
256
+ return ret;
257
+}
258
+
259
+static inline int netdata_rwlock_trywrlock_debug( const char *file, const char *function, const unsigned long line, netdata_rwlock_t *rwlock) {
260
+ usec_t start = 0;
261
+
262
+ if(unlikely(debug_flags & D_LOCKS)) {
263
+ start = now_boottime_usec();
264
+ debug(D_LOCKS, "RW_LOCK: netdata_rwlock_trywrlock() from %lu@%s, %s()", line, file, function);
265
+ }
266
+
267
+ int ret = __netdata_rwlock_trywrlock(rwlock);
268
+
269
+ debug(D_LOCKS, "RW_LOCK: netdata_rwlock_trywrlock() = %d in %llu usec, from %lu@%s, %s()", ret, now_boottime_usec() - start, line, file, function);
270
+
271
+ return ret;
272
+}
273
+
274
+#define netdata_rwlock_destroy(rwlock) netdata_rwlock_destroy_debug(__FILE__, __FUNCTION__, __LINE__, rwlock)
275
+#define netdata_rwlock_init(rwlock) netdata_rwlock_init_debug(__FILE__, __FUNCTION__, __LINE__, rwlock)
276
+#define netdata_rwlock_rdlock(rwlock) netdata_rwlock_rdlock_debug(__FILE__, __FUNCTION__, __LINE__, rwlock)
277
+#define netdata_rwlock_wrlock(rwlock) netdata_rwlock_wrlock_debug(__FILE__, __FUNCTION__, __LINE__, rwlock)
278
+#define netdata_rwlock_unlock(rwlock) netdata_rwlock_unlock_debug(__FILE__, __FUNCTION__, __LINE__, rwlock)
279
+#define netdata_rwlock_tryrdlock(rwlock) netdata_rwlock_tryrdlock_debug(__FILE__, __FUNCTION__, __LINE__, rwlock)
280
+#define netdata_rwlock_trywrlock(rwlock) netdata_rwlock_trywrlock_debug(__FILE__, __FUNCTION__, __LINE__, rwlock)
281
+
282
+#else // !NETDATA_INTERNAL_CHECKS
283
+
284
+#define netdata_rwlock_destroy(rwlock) __netdata_rwlock_destroy(rwlock)
285
+#define netdata_rwlock_init(rwlock) __netdata_rwlock_init(rwlock)
286
+#define netdata_rwlock_rdlock(rwlock) __netdata_rwlock_rdlock(rwlock)
287
+#define netdata_rwlock_wrlock(rwlock) __netdata_rwlock_wrlock(rwlock)
288
+#define netdata_rwlock_unlock(rwlock) __netdata_rwlock_unlock(rwlock)
289
+#define netdata_rwlock_tryrdlock(rwlock) __netdata_rwlock_tryrdlock(rwlock)
290
+#define netdata_rwlock_trywrlock(rwlock) __netdata_rwlock_trywrlock(rwlock)
291
+
292
+#endif // NETDATA_INTERNAL_CHECKS
293
+
294
+#endif //NETDATA_LOCKS_H
src/log.h
+1
@@ -27,6 +27,7 @@
27
#define D_HEALTH 0x0000000000800000
28
#define D_CONNECT_TO 0x0000000001000000
29
#define D_RRDHOST 0x0000000002000000
30
+#define D_LOCKS 0x0000000004000000
31
#define D_SYSTEM 0x8000000000000000
32
33
//#define DEBUG (D_WEB_CLIENT_ACCESS|D_LISTENER|D_RRD_STATS)
src/registry.c
+2
-2
@@ -10,11 +10,11 @@
10
// REGISTRY concurrency locking
11
12
static inline void registry_lock(void) {
13
- pthread_mutex_lock(®istry.lock);
13
+ netdata_mutex_lock(®istry.lock);
14
}
15
16
static inline void registry_unlock(void) {
17
- pthread_mutex_unlock(®istry.lock);
17
+ netdata_mutex_unlock(®istry.lock);
18
}
19
20
src/registry_init.c
+1
-1
@@ -68,7 +68,7 @@ int registry_init(void) {
68
registry.machines_urls_memory = 0;
69
70
// initialize locks
71
- pthread_mutex_init(®istry.lock, NULL);
71
+ netdata_mutex_init(®istry.lock);
72
73
// create dictionaries
74
registry.persons = dictionary_create(DICTIONARY_FLAGS);
src/registry_internals.h
+1
-1
@@ -56,7 +56,7 @@ struct registry {
56
57
avl_tree registry_urls_root_index;
58
59
- pthread_mutex_t lock;
59
+ netdata_mutex_t lock;
60
};
61
62
extern int regenerate_guid(const char *guid, char *result);
src/rrd.h
+16
-49
@@ -273,7 +273,7 @@ struct rrdset {
273
char *cache_dir; // the directory to store dimensions
274
char cache_filename[FILENAME_MAX+1]; // the filename to store this set
275
276
- pthread_rwlock_t rrdset_rwlock; // protects dimensions linked list
276
+ netdata_rwlock_t rrdset_rwlock; // protects dimensions linked list
277
278
size_t counter; // the number of times we added values to this database
279
size_t counter_done; // the number of times rrdset_done() has been called
@@ -325,6 +325,11 @@ struct rrdset {
325
};
326
typedef struct rrdset RRDSET;
327
328
+#define rrdset_rdlock(st) netdata_rwlock_rdlock(&((st)->rrdset_rwlock))
329
+#define rrdset_wrlock(st) netdata_rwlock_wrlock(&((st)->rrdset_rwlock))
330
+#define rrdset_unlock(st) netdata_rwlock_unlock(&((st)->rrdset_rwlock))
331
+
332
+
333
// ----------------------------------------------------------------------------
334
// these loop macros make sure the linked list is accessed with the right lock
335
@@ -389,7 +394,7 @@ struct rrdhost {
394
volatile int rrdpush_error_shown:1; // 1 when we have logged a communication error
395
int rrdpush_socket; // the fd of the socket to the remote host, or -1
396
pthread_t rrdpush_thread; // the sender thread
392
- pthread_mutex_t rrdpush_mutex; // exclusive access to rrdpush_buffer
397
+ netdata_mutex_t rrdpush_mutex; // exclusive access to rrdpush_buffer
398
int rrdpush_pipe[2]; // collector to sender thread communication
399
BUFFER *rrdpush_buffer; // collector fills it, sender sends them
400
@@ -435,7 +440,7 @@ struct rrdhost {
440
// ------------------------------------------------------------------------
441
// locks
442
438
- pthread_rwlock_t rrdhost_rwlock; // lock for this RRDHOST (protects rrdset_root linked list)
443
+ netdata_rwlock_t rrdhost_rwlock; // lock for this RRDHOST (protects rrdset_root linked list)
444
445
avl_tree_lock rrdset_root_index; // the host's charts index (by id)
446
avl_tree_lock rrdset_root_index_name; // the host's charts index (by name)
@@ -448,21 +453,9 @@ struct rrdhost {
453
typedef struct rrdhost RRDHOST;
454
extern RRDHOST *localhost;
455
451
-static inline void rrdhost_rdlock(RRDHOST *host) {
452
- if(unlikely(pthread_rwlock_rdlock(&host->rrdhost_rwlock) != 0))
453
- error("Cannot obtain read lock on host '%s'", host->hostname);
454
-}
455
-
456
-static inline void rrdhost_wrlock(RRDHOST *host) {
457
- if(unlikely(pthread_rwlock_wrlock(&host->rrdhost_rwlock) != 0))
458
- error("Cannot obtain write lock on host '%s'", host->hostname);
459
-}
460
-
461
-static inline void rrdhost_unlock(RRDHOST *host) {
462
- if(unlikely(pthread_rwlock_unlock(&host->rrdhost_rwlock) != 0))
463
- error("Cannot unlock host '%s'", host->hostname);
464
-}
465
-
456
+#define rrdhost_rdlock(host) netdata_rwlock_rdlock(&((host)->rrdhost_rwlock))
457
+#define rrdhost_wrlock(host) netdata_rwlock_wrlock(&((host)->rrdhost_rwlock))
458
+#define rrdhost_unlock(host) netdata_rwlock_unlock(&((host)->rrdhost_rwlock))
459
460
// ----------------------------------------------------------------------------
461
// these loop macros make sure the linked list is accessed with the right lock
@@ -477,37 +470,11 @@ static inline void rrdhost_unlock(RRDHOST *host) {
470
// ----------------------------------------------------------------------------
471
// global lock for all RRDHOSTs
472
480
-extern pthread_rwlock_t rrd_rwlock;
481
-
482
-static inline void rrd_rdlock() {
483
- if(unlikely(pthread_rwlock_rdlock(&rrd_rwlock) != 0))
484
- error("Cannot read lock the RRD database.");
485
-}
486
-
487
-static inline void rrd_wrlock() {
488
- if(unlikely(pthread_rwlock_wrlock(&rrd_rwlock) != 0))
489
- error("Cannot write lock the RRD database.");
490
-}
491
-
492
-static inline void rrd_unlock() {
493
- if(unlikely(pthread_rwlock_unlock(&rrd_rwlock) != 0))
494
- error("Cannot unlock the RRD database.");
495
-}
496
-
497
-static inline void rrdset_rdlock(RRDSET *st) {
498
- if(unlikely(pthread_rwlock_rdlock(&st->rrdset_rwlock) != 0))
499
- error("Cannot read lock RRDSET '%s' of host '%s'", st->id, st->rrdhost->hostname);
500
-}
501
-
502
-static inline void rrdset_wrlock(RRDSET *st) {
503
- if(unlikely(pthread_rwlock_wrlock(&st->rrdset_rwlock) != 0))
504
- error("Cannot write lock RRDSET '%s' of host '%s'", st->id, st->rrdhost->hostname);
505
-}
506
-
507
-static inline void rrdset_unlock(RRDSET *st) {
508
- if(unlikely(pthread_rwlock_unlock(&st->rrdset_rwlock) != 0))
509
- error("Cannot unlock RRDSET '%s' of host '%s'", st->id, st->rrdhost->hostname);
510
-}
473
+extern netdata_rwlock_t rrd_rwlock;
474
+
475
+#define rrd_rdlock() netdata_rwlock_rdlock(&rrd_rwlock)
476
+#define rrd_wrlock() netdata_rwlock_wrlock(&rrd_rwlock)
477
+#define rrd_unlock() netdata_rwlock_unlock(&rrd_rwlock)
478
479
// ----------------------------------------------------------------------------
480
src/rrdhost.c
+10
-8
@@ -3,7 +3,7 @@
3
4
RRDHOST *localhost = NULL;
5
size_t rrd_hosts_available = 0;
6
-pthread_rwlock_t rrd_rwlock = PTHREAD_RWLOCK_INITIALIZER;
6
+netdata_rwlock_t rrd_rwlock = NETDATA_RWLOCK_INITIALIZER;
7
8
time_t rrdset_free_obsolete_time = 3600;
9
time_t rrdhost_free_orphan_time = 3600;
@@ -108,8 +108,8 @@ RRDHOST *rrdhost_create(const char *hostname,
108
host->rrdpush_pipe[1] = -1;
109
host->rrdpush_socket = -1;
110
111
- pthread_mutex_init(&host->rrdpush_mutex, NULL);
112
- pthread_rwlock_init(&host->rrdhost_rwlock, NULL);
111
+ netdata_mutex_init(&host->rrdpush_mutex);
112
+ netdata_rwlock_init(&host->rrdhost_rwlock);
113
114
rrdhost_init_hostname(host, hostname);
115
rrdhost_init_machine_guid(host, guid);
@@ -144,7 +144,7 @@ RRDHOST *rrdhost_create(const char *hostname,
144
else
145
host->health_log.max = (unsigned int)n;
146
147
- pthread_rwlock_init(&(host->health_log.alarm_log_rwlock), NULL);
147
+ netdata_rwlock_init(&host->health_log.alarm_log_rwlock);
148
149
char filename[FILENAME_MAX + 1];
150
@@ -383,7 +383,7 @@ void rrd_init(char *hostname) {
383
void rrdhost_check_rdlock_int(RRDHOST *host, const char *file, const char *function, const unsigned long line) {
384
debug(D_RRDHOST, "Checking read lock on host '%s'", host->hostname);
385
386
- int ret = pthread_rwlock_trywrlock(&host->rrdhost_rwlock);
386
+ int ret = netdata_rwlock_trywrlock(&host->rrdhost_rwlock);
387
if(ret == 0)
388
fatal("RRDHOST '%s' should be read-locked, but it is not, at function %s() at line %lu of file '%s'", host->hostname, function, line, file);
389
}
@@ -391,7 +391,7 @@ void rrdhost_check_rdlock_int(RRDHOST *host, const char *file, const char *funct
391
void rrdhost_check_wrlock_int(RRDHOST *host, const char *file, const char *function, const unsigned long line) {
392
debug(D_RRDHOST, "Checking write lock on host '%s'", host->hostname);
393
394
- int ret = pthread_rwlock_tryrdlock(&host->rrdhost_rwlock);
394
+ int ret = netdata_rwlock_tryrdlock(&host->rrdhost_rwlock);
395
if(ret == 0)
396
fatal("RRDHOST '%s' should be write-locked, but it is not, at function %s() at line %lu of file '%s'", host->hostname, function, line, file);
397
}
@@ -399,7 +399,7 @@ void rrdhost_check_wrlock_int(RRDHOST *host, const char *file, const char *funct
399
void rrd_check_rdlock_int(const char *file, const char *function, const unsigned long line) {
400
debug(D_RRDHOST, "Checking read lock on all RRDs");
401
402
- int ret = pthread_rwlock_trywrlock(&rrd_rwlock);
402
+ int ret = netdata_rwlock_trywrlock(&rrd_rwlock);
403
if(ret == 0)
404
fatal("RRDs should be read-locked, but it are not, at function %s() at line %lu of file '%s'", function, line, file);
405
}
@@ -407,7 +407,7 @@ void rrd_check_rdlock_int(const char *file, const char *function, const unsigned
407
void rrd_check_wrlock_int(const char *file, const char *function, const unsigned long line) {
408
debug(D_RRDHOST, "Checking write lock on all RRDs");
409
410
- int ret = pthread_rwlock_tryrdlock(&rrd_rwlock);
410
+ int ret = netdata_rwlock_tryrdlock(&rrd_rwlock);
411
if(ret == 0)
412
fatal("RRDs should be write-locked, but it are not, at function %s() at line %lu of file '%s'", function, line, file);
413
}
@@ -473,6 +473,8 @@ void rrdhost_free(RRDHOST *host) {
473
freez(host->health_log_filename);
474
freez(host->hostname);
475
rrdhost_unlock(host);
476
+ netdata_rwlock_destroy(&host->health_log.alarm_log_rwlock);
477
+ netdata_rwlock_destroy(&host->rrdhost_rwlock);
478
freez(host);
479
480
rrd_hosts_available--;
src/rrdpush.c
+2
-2
@@ -59,8 +59,8 @@ int rrdpush_init() {
59
// this is for the first iterations of each chart
60
static unsigned int remote_clock_resync_iterations = 60;
61
62
-#define rrdpush_lock(host) pthread_mutex_lock(&((host)->rrdpush_mutex))
63
-#define rrdpush_unlock(host) pthread_mutex_unlock(&((host)->rrdpush_mutex))
62
+#define rrdpush_lock(host) netdata_mutex_lock(&((host)->rrdpush_mutex))
63
+#define rrdpush_unlock(host) netdata_mutex_unlock(&((host)->rrdpush_mutex))
64
65
// checks if the current chart definition has been sent
66
static inline int need_to_send_chart_definition(RRDSET *st) {
src/rrdset.c
+6
-4
@@ -6,7 +6,7 @@
6
void rrdset_check_rdlock_int(RRDSET *st, const char *file, const char *function, const unsigned long line) {
7
debug(D_RRD_CALLS, "Checking read lock on chart '%s'", st->id);
8
9
- int ret = pthread_rwlock_trywrlock(&st->rrdset_rwlock);
9
+ int ret = netdata_rwlock_trywrlock(&st->rrdset_rwlock);
10
if(ret == 0)
11
fatal("RRDSET '%s' should be read-locked, but it is not, at function %s() at line %lu of file '%s'", st->id, function, line, file);
12
}
@@ -14,7 +14,7 @@ void rrdset_check_rdlock_int(RRDSET *st, const char *file, const char *function,
14
void rrdset_check_wrlock_int(RRDSET *st, const char *file, const char *function, const unsigned long line) {
15
debug(D_RRD_CALLS, "Checking write lock on chart '%s'", st->id);
16
17
- int ret = pthread_rwlock_tryrdlock(&st->rrdset_rwlock);
17
+ int ret = netdata_rwlock_tryrdlock(&st->rrdset_rwlock);
18
if(ret == 0)
19
fatal("RRDSET '%s' should be write-locked, but it is not, at function %s() at line %lu of file '%s'", st->id, function, line, file);
20
}
@@ -274,6 +274,8 @@ void rrdset_free(RRDSET *st) {
274
// ------------------------------------------------------------------------
275
// free it
276
277
+ netdata_rwlock_destroy(&st->rrdset_rwlock);
278
+
279
// free directly allocated members
280
freez(st->config_section);
281
@@ -421,7 +423,7 @@ RRDSET *rrdset_create(
423
memset(&st->avlname, 0, sizeof(avl));
424
memset(&st->variables_root_index, 0, sizeof(avl_tree_lock));
425
memset(&st->dimensions_index, 0, sizeof(avl_tree_lock));
424
- memset(&st->rrdset_rwlock, 0, sizeof(pthread_rwlock_t));
426
+ memset(&st->rrdset_rwlock, 0, sizeof(netdata_rwlock_t));
427
428
st->name = NULL;
429
st->type = NULL;
@@ -537,7 +539,7 @@ RRDSET *rrdset_create(
539
avl_init_lock(&st->dimensions_index, rrddim_compare);
540
avl_init_lock(&st->variables_root_index, rrdvar_compare);
541
540
- pthread_rwlock_init(&st->rrdset_rwlock, NULL);
542
+ netdata_rwlock_init(&st->rrdset_rwlock);
543
544
if(name && *name) rrdset_set_name(st, name);
545
else rrdset_set_name(st, id);