Move from std::stop_token to std::atomic<bool>
clang on macOS doesn't support <stop_token> now
This commit is contained in:
parent
dd8245996c
commit
7324855c6d
@ -1,6 +1,6 @@
|
|||||||
#include <musique/interpreter/starter.hh>
|
|
||||||
#include <ableton/Link.hpp>
|
#include <ableton/Link.hpp>
|
||||||
#include <musique/errors.hh>
|
#include <musique/errors.hh>
|
||||||
|
#include <musique/interpreter/starter.hh>
|
||||||
|
|
||||||
struct Starter::Implementation
|
struct Starter::Implementation
|
||||||
{
|
{
|
||||||
@ -23,7 +23,7 @@ struct State
|
|||||||
ableton::Link *link;
|
ableton::Link *link;
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
std::condition_variable condition;
|
std::condition_variable condition;
|
||||||
std::stop_source source;
|
std::atomic<bool> stop = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
void Starter::start()
|
void Starter::start()
|
||||||
@ -47,21 +47,21 @@ void Starter::start()
|
|||||||
{
|
{
|
||||||
if (is_playing) {
|
if (is_playing) {
|
||||||
state->condition.notify_all();
|
state->condition.notify_all();
|
||||||
state->source.request_stop();
|
state->stop = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
std::thread starter([quantum = quantum, state = state, token = state->source.get_token()]()
|
std::thread starter([quantum = quantum, state = state]
|
||||||
{
|
{
|
||||||
auto counter = 0;
|
auto counter = 0;
|
||||||
while (!token.stop_requested()) {
|
while (!state->stop) {
|
||||||
auto const time = state->link->clock().micros();
|
auto const time = state->link->clock().micros();
|
||||||
auto sessionState = state->link->captureAppSessionState();
|
auto sessionState = state->link->captureAppSessionState();
|
||||||
if (counter == 10) {
|
if (counter == 10) {
|
||||||
sessionState.setIsPlaying(true, time);
|
sessionState.setIsPlaying(true, time);
|
||||||
state->link->commitAppSessionState(sessionState);
|
state->link->commitAppSessionState(sessionState);
|
||||||
state->condition.notify_all();
|
state->condition.notify_all();
|
||||||
state->source.request_stop();
|
state->stop = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto const phase = sessionState.phaseAtTime(time, quantum);
|
auto const phase = sessionState.phaseAtTime(time, quantum);
|
||||||
|
Loading…
Reference in New Issue
Block a user