1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-19 23:32:28 +00:00
CLK/OSBindings/Qt/timer.cpp

24 lines
624 B
C++
Raw Normal View History

#include "timer.h"
#include "../../ClockReceiver/TimeTypes.hpp"
#include <algorithm>
#include <QDebug>
Timer::Timer(QObject *parent) : QObject(parent) {}
2020-06-06 03:06:28 +00:00
void Timer::setMachine(MachineTypes::TimedMachine *machine, std::mutex *machineMutex) {
this->machine = machine;
2020-06-06 03:06:28 +00:00
this->machineMutex = machineMutex;
}
void Timer::tick() {
const auto now = Time::nanos_now();
const auto duration = std::min(now - lastTickNanos, int64_t(500'000'000));
// qDebug() << duration << " [not " << now - lastTickNanos << "]";
lastTickNanos = now;
2020-06-06 03:06:28 +00:00
std::lock_guard lock_guard(*machineMutex);
machine->run_for(double(duration) / 1e9);
}