__sync_lock_test_and_set() and __sync_synchronize() have been made obsolete and can/should be replaced by their updated __atomic versions.
For example, __sync_lock_test_and_set(&lk->locked, 1) could/would become __atomic_exchange_n(&lk->locked, 1, __ATOMIC_ACQUIRE) within the acquire() function body and __atomic_exchange_n(&lk->locked, 0, __ATOMIC_RELEASE) within the release() function body.
Similarly, __sync_synchronize() in both function could/would become __atomic_thread_fence(__ATOMIC_SEQ_CST).
GCC-generated code (as well as clang-generated one) can be checked with godbolt.org tool.
Reference: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html