Skip to content

Commit 091a899

Browse files
committed
dummy protocol: safety fixes
1 parent 61ab45e commit 091a899

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/ossia/audio/dummy_protocol.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ class dummy_engine final : public audio_engine
2727
void setup_thread()
2828
{
2929
m_active = true;
30-
3130
int us_per_buffer
3231
= 1e6 * double(effective_buffer_size) / double(effective_sample_rate);
3332

34-
m_runThread = std::thread{[this, us_per_buffer] {
33+
auto started = std::make_shared<std::atomic_bool>(false);
34+
m_runThread = std::thread{[this, started, us_per_buffer] {
35+
while(!*started)
36+
{
37+
std::this_thread::yield();
38+
}
39+
std::atomic_thread_fence(std::memory_order_seq_cst);
3540
ossia::set_thread_name("ossia audio 0");
3641
ossia::set_thread_pinned(thread_type::Audio, 0);
3742
ossia::set_thread_realtime(m_runThread, 99);
@@ -95,6 +100,10 @@ class dummy_engine final : public audio_engine
95100
tick_end();
96101
}
97102
}};
103+
104+
std::atomic_thread_fence(std::memory_order_seq_cst);
105+
106+
*started = true;
98107
}
99108

100109
void stop() override

0 commit comments

Comments
 (0)