mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-16 18:30:32 +00:00
FunctionThreads no longer automatically start.
Improvements as a result: audio works in a second machine started in an existing window; there is no audio thread footprint if there is no audio.
This commit is contained in:
parent
55cc3089f9
commit
f7e13356c4
@ -17,14 +17,6 @@
|
||||
*/
|
||||
class FunctionThread: public QThread {
|
||||
public:
|
||||
FunctionThread() : QThread() {
|
||||
// TODO: I've assumed a race condition here with the creation of performer; if QThread
|
||||
// blocks on completion of `run` when starting then this is redundant.
|
||||
performerFlag.test_and_set();
|
||||
start();
|
||||
while(performerFlag.test_and_set());
|
||||
}
|
||||
|
||||
~FunctionThread() {
|
||||
stop();
|
||||
}
|
||||
@ -33,7 +25,7 @@ class FunctionThread: public QThread {
|
||||
// Gymnastics here: events posted directly to the QThread will occur on the thread
|
||||
// that created the QThread. To have events occur within a QThread, they have to be
|
||||
// posted to an object created on that thread. FunctionPerformer fills that role.
|
||||
performer = std::make_unique<FunctionPerformer>();
|
||||
if(!performer) performer = std::make_unique<FunctionPerformer>();
|
||||
performerFlag.clear();
|
||||
exec();
|
||||
}
|
||||
@ -47,6 +39,18 @@ class FunctionThread: public QThread {
|
||||
wait();
|
||||
}
|
||||
|
||||
void start() {
|
||||
if(isRunning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: I've assumed a race condition here with the creation of performer; if QThread
|
||||
// blocks on completion of `run` when starting then this is redundant.
|
||||
performerFlag.test_and_set();
|
||||
QThread::start();
|
||||
while(performerFlag.test_and_set());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Schedules a function to be performed on this thread. Control
|
||||
* must return to the main event loop for the function to be performed;
|
||||
|
@ -315,6 +315,7 @@ void MainWindow::launchMachine() {
|
||||
speaker->set_output_rate(idealFormat.sampleRate(), samplesPerBuffer, audioIsStereo);
|
||||
speaker->set_delegate(this);
|
||||
|
||||
audioThread.start();
|
||||
audioThread.performAsync([this, idealFormat] {
|
||||
// Create an audio output.
|
||||
audioOutput = std::make_unique<QAudioOutput>(idealFormat);
|
||||
|
@ -11,6 +11,7 @@ void Timer::startWithMachine(MachineTypes::TimedMachine *machine, std::mutex *ma
|
||||
this->machine = machine;
|
||||
this->machineMutex = machineMutex;
|
||||
|
||||
thread.start();
|
||||
thread.performAsync([this] {
|
||||
// Set up the emulation timer. Bluffer's guide: the QTimer will post an
|
||||
// event to an event loop. QThread is a thread with an event loop.
|
||||
|
Loading…
x
Reference in New Issue
Block a user