Skip to content
Snippets Groups Projects
Commit 0130bfb8 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

WIP attempt to fix error on disconnect

parent 0e2a21ed
No related branches found
No related tags found
1 merge request!97Resolves #160 by resync of clock
Pipeline #13005 passed
...@@ -61,11 +61,13 @@ static void waitTimePoint() { ...@@ -61,11 +61,13 @@ static void waitTimePoint() {
} }
// Still lots of time so do some idle jobs // Still lots of time so do some idle jobs
{ if (msdelay >= 10 && sincelast != mspf) {
UNIQUE_LOCK(mtx, lk); UNIQUE_LOCK(mtx, lk);
auto idle_job = jobs[kTimerIdle10].begin(); auto idle_job = jobs[kTimerIdle10].begin();
while (idle_job != jobs[kTimerIdle10].end() && msdelay >= 10 && sincelast != mspf) { while (idle_job != jobs[kTimerIdle10].end() && msdelay >= 10 && sincelast != mspf) {
(*idle_job++).job(now); (*idle_job).active = true;
(*idle_job).job(now);
(*idle_job++).active = false;
now = get_time(); now = get_time();
msdelay = mspf - (now % mspf); msdelay = mspf - (now % mspf);
} }
......
...@@ -173,10 +173,18 @@ void Streamer::_addClient(const string &source, int N, int rate, const ftl::UUID ...@@ -173,10 +173,18 @@ void Streamer::_addClient(const string &source, int N, int rate, const ftl::UUID
if (time_peer_ == ftl::UUID(0)) { if (time_peer_ == ftl::UUID(0)) {
time_peer_ = peer; time_peer_ = peer;
// Do a time sync whenever the CPU is idle for 10ms or more.
// FIXME: Could be starved
timer_job_ = ftl::timer::add(ftl::timer::kTimerIdle10, [peer,this](int id) { timer_job_ = ftl::timer::add(ftl::timer::kTimerIdle10, [peer,this](int id) {
// Also do a time sync (but should be repeated periodically)
auto start = std::chrono::high_resolution_clock::now(); auto start = std::chrono::high_resolution_clock::now();
int64_t mastertime = net_->call<int64_t>(peer, "__ping__"); int64_t mastertime;
try {
mastertime = net_->call<int64_t>(peer, "__ping__");
} catch (...) {
//timer_job_.cancel();
}
auto elapsed = std::chrono::high_resolution_clock::now() - start; auto elapsed = std::chrono::high_resolution_clock::now() - start;
int64_t latency = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count(); int64_t latency = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();
auto clock_adjust = mastertime - (ftl::timer::get_time() + (latency/2)); auto clock_adjust = mastertime - (ftl::timer::get_time() + (latency/2));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment