diff options
-rw-r--r-- | libnetdata/locks/locks.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/libnetdata/locks/locks.c b/libnetdata/locks/locks.c index 9bf56e9f58..f7191be52c 100644 --- a/libnetdata/locks/locks.c +++ b/libnetdata/locks/locks.c @@ -287,17 +287,15 @@ void netdata_spinlock_init(SPINLOCK *spinlock) { } void netdata_spinlock_lock(SPINLOCK *spinlock) { - netdata_thread_disable_cancelability(); - static const struct timespec ns = { .tv_sec = 0, .tv_nsec = 1 }; - bool expected = false, desired = true; + + netdata_thread_disable_cancelability(); for(int i = 1; __atomic_load_n(&spinlock->locked, __ATOMIC_RELAXED) || - !__atomic_compare_exchange_n(&spinlock->locked, &expected, desired, false, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE) + __atomic_test_and_set(&spinlock->locked, __ATOMIC_ACQUIRE) ; i++ ) { - if(unlikely(i == 8)) { i = 0; nanosleep(&ns, NULL); @@ -307,8 +305,7 @@ void netdata_spinlock_lock(SPINLOCK *spinlock) { } void netdata_spinlock_unlock(SPINLOCK *spinlock) { - __atomic_store_n(&spinlock->locked, false, __ATOMIC_RELEASE); - + __atomic_clear(&spinlock->locked, __ATOMIC_RELEASE); netdata_thread_enable_cancelability(); } |