Halide
scoped_spin_lock.h
Go to the documentation of this file.
1 #ifndef HALIDE_SCOPED_SPIN_LOCK_H
2 #define HALIDE_SCOPED_SPIN_LOCK_H
3 
4 namespace Halide {
5 namespace Runtime {
6 namespace Internal {
7 
8 // An RAII spin lock.
9 struct ScopedSpinLock {
10  // Note that __atomic_test_and_set() requires use of a char (or bool)
11  typedef char AtomicFlag;
12 
13  volatile AtomicFlag *const flag;
14 
16  : flag(flag) {
17  while (__atomic_test_and_set(flag, __ATOMIC_ACQUIRE)) {
18  // nothing
19  }
20  }
21 
23  __atomic_clear(flag, __ATOMIC_RELEASE);
24  }
25 };
26 
27 } // namespace Internal
28 } // namespace Runtime
29 } // namespace Halide
30 
31 #endif
Halide::Runtime::Internal::ScopedSpinLock::flag
volatile AtomicFlag *const flag
Definition: scoped_spin_lock.h:13
Halide::Runtime::Internal::ScopedSpinLock::AtomicFlag
char AtomicFlag
Definition: scoped_spin_lock.h:11
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::Runtime::Internal::ScopedSpinLock
Definition: scoped_spin_lock.h:9
Halide::Runtime::Internal::ScopedSpinLock::ScopedSpinLock
ALWAYS_INLINE ScopedSpinLock(volatile AtomicFlag *flag)
Definition: scoped_spin_lock.h:15
Halide::Runtime::Internal::ScopedSpinLock::~ScopedSpinLock
ALWAYS_INLINE ~ScopedSpinLock()
Definition: scoped_spin_lock.h:22
ALWAYS_INLINE
#define ALWAYS_INLINE
Definition: runtime_internal.h:53