https://github.com/halide/Halide
Raw File
Tip revision: 987f53163ce014cb5df3f7d7b498b8cd77e93073 authored by Andrew Adams on 24 March 2021, 00:08:17 UTC
Remove buggy deinterleave misfeature
Tip revision: 987f531
scoped_spin_lock.h
#ifndef HALIDE_SCOPED_SPIN_LOCK_H
#define HALIDE_SCOPED_SPIN_LOCK_H

namespace Halide {
namespace Runtime {
namespace Internal {

// An RAII spin lock.
struct ScopedSpinLock {
    // Note that __atomic_test_and_set() requires use of a char (or bool)
    typedef char AtomicFlag;

    volatile AtomicFlag *const flag;

    ALWAYS_INLINE ScopedSpinLock(volatile AtomicFlag *flag)
        : flag(flag) {
        while (__atomic_test_and_set(flag, __ATOMIC_ACQUIRE)) {
            // nothing
        }
    }

    ALWAYS_INLINE ~ScopedSpinLock() {
        __atomic_clear(flag, __ATOMIC_RELEASE);
    }
};

}  // namespace Internal
}  // namespace Runtime
}  // namespace Halide

#endif
back to top