Rate This Document
Findability
Accuracy
Completeness
Readability

TAS & Clear

TAS performs test_and_set operation on a bit.

  • x86 platform
    static inline bool
    pg_atomic_test_set_flag_impl(volatile pg_atomic_flag *ptr)
    {
            register char _res = 1;
            __asm__ __volatile__(
                    "       lock                    \n"
                    "       xchgb   %0,%1   \n"
    :               "+q"(_res), "+m"(ptr->value)
    :
    :               "memory");
            return _res == 0;
    }
    static inline void
    pg_atomic_clear_flag_impl(volatile pg_atomic_flag *ptr)
    {
            /*
             * On a TSO architecture like x86 it's sufficient to use a compiler
             * barrier to achieve release semantics.
             */
            __asm__ __volatile__("" ::: "memory");
            ptr->value = 0;
    }
  • AArch64 platform
    static inline bool
    pg_atomic_test_set_flag_impl(volatile pg_atomic_flag *ptr)
    {
            return __sync_lock_test_and_set(&ptr->value, 1) == 0;
    }
    static inline void
    pg_atomic_clear_flag_impl(volatile pg_atomic_flag *ptr)
    {
            __sync_lock_release(&ptr->value);
    }