https://github.com/halide/Halide
Raw File
Tip revision: 0d001b4ce5be379d315f05c5de768e55d30a9940 authored by Andrew Adams on 24 January 2019, 17:38:15 UTC
Merge branch 'fix-runtime-cuda-init' of https://github.com/jia-kai/Halide into jia-kai-fix-runtime-cuda-init
Tip revision: 0d001b4
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 {
    volatile int *lock;

    ScopedSpinLock(volatile int *l) __attribute__((always_inline)) : lock(l) {
        while (__sync_lock_test_and_set(lock, 1)) { }
    }

    ~ScopedSpinLock() __attribute__((always_inline)) {
        __sync_lock_release(lock);
    }
};

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

#endif
back to top