Halide 22.0.0 Halide compiler and libraries

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
15 ALWAYS_INLINE explicit ScopedSpinLock(volatile AtomicFlag *flag)
16 : flag(flag) {
17 while (__atomic_test_and_set(flag, __ATOMIC_ACQUIRE)) {
18 // nothing
19 }
20 }
21
22 ALWAYS_INLINE ~ScopedSpinLock() {
23 __atomic_clear(flag, __ATOMIC_RELEASE);
24 }
25};
26
27} // namespace Internal
28} // namespace Runtime
29} // namespace Halide
30
31#endif
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
ALWAYS_INLINE
#define ALWAYS_INLINE
Definition: runtime_internal.h:57
Halide::Runtime::Internal::ScopedSpinLock
Definition: scoped_spin_lock.h:9
Halide::Runtime::Internal::ScopedSpinLock::~ScopedSpinLock
ALWAYS_INLINE ~ScopedSpinLock()
Definition: scoped_spin_lock.h:22
Halide::Runtime::Internal::ScopedSpinLock::AtomicFlag
char AtomicFlag
Definition: scoped_spin_lock.h:11
Halide::Runtime::Internal::ScopedSpinLock::ScopedSpinLock
ALWAYS_INLINE ScopedSpinLock(volatile AtomicFlag *flag)
Definition: scoped_spin_lock.h:15
Halide::Runtime::Internal::ScopedSpinLock::flag
volatile AtomicFlag *const flag
Definition: scoped_spin_lock.h:13