Skip to content

[MODERNIZE] Use __atomic "modern" builtins in spinlock functions instead of __sync ones #387

@notorand-it

Description

@notorand-it

__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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions