summaryrefslogtreecommitdiffstats
path: root/libnetdata/string
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@netdata.cloud>2022-12-03 16:30:43 +0200
committerGitHub <noreply@github.com>2022-12-03 16:30:43 +0200
commit1ccef511f0cc27cbc0aa46dff2ddc71928e8e304 (patch)
tree5a553da1732ac4165e55bb7dc0d8a5186c2bc2d6 /libnetdata/string
parent5061428c0effa811094190d255b1feb6b05901cc (diff)
Fix __atomic_compare_exchange_n() atomics (#14085)
* proper use for atomic_compare_exchange() * diskspace plugin is multi-threaded but it uses single threaded dictionaries
Diffstat (limited to 'libnetdata/string')
-rw-r--r--libnetdata/string/string.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/libnetdata/string/string.c b/libnetdata/string/string.c
index a3f74b4ef4..d2db8aab43 100644
--- a/libnetdata/string/string.c
+++ b/libnetdata/string/string.c
@@ -71,11 +71,12 @@ void string_statistics(size_t *inserts, size_t *deletes, size_t *searches, size_
static inline bool string_entry_check_and_acquire(STRING *se) {
REFCOUNT expected, desired, count = 0;
+
+ expected = __atomic_load_n(&se->refcount, __ATOMIC_SEQ_CST);
+
do {
count++;
- expected = __atomic_load_n(&se->refcount, __ATOMIC_SEQ_CST);
-
if(expected <= 0) {
// We cannot use this.
// The reference counter reached value zero,
@@ -85,8 +86,8 @@ static inline bool string_entry_check_and_acquire(STRING *se) {
}
desired = expected + 1;
- }
- while(!__atomic_compare_exchange_n(&se->refcount, &expected, desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST));
+
+ } while(!__atomic_compare_exchange_n(&se->refcount, &expected, desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST));
string_internal_stats_add(spins, count - 1);