tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_RealTimeSpinLock.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11#pragma once
12
13#if JUCE_INTEL
14 #include <emmintrin.h>
15#endif
16
17namespace tracktion { inline namespace graph
18{
19
24{
25public:
27 void lock() noexcept
28 {
29 for (;;)
30 {
31 for (int i = 0; i < 5; ++i)
32 if (try_lock())
33 return;
34
35 for (int i = 0; i < 10; ++i)
36 {
37 #if JUCE_INTEL
38 _mm_pause();
39 #else
40 __asm__ __volatile__ ("yield");
41 #endif
42
43 if (try_lock())
44 return;
45 }
46 }
47 }
48
50 void unlock() noexcept
51 {
53 }
54
56 bool try_lock() noexcept
57 {
59 }
60
61private:
62 std::atomic_flag flag = ATOMIC_FLAG_INIT;
63};
64
65}}
A basic spin lock that uses an atomic_flag to store the locked state so should never result in a syst...
void unlock() noexcept
Releases the lock, this should only be called after a successful call to try_lock or lock.
bool try_lock() noexcept
Attempts to take the lock once, returning true if successful.
void lock() noexcept
Takes the lock, blocking if necessary.
T clear(T... args)
T is_pointer_v
T test_and_set(T... args)