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

Lock and remove on idle job

parent 3c02a51a
No related branches found
No related tags found
1 merge request!97Resolves #160 by resync of clock
Pipeline #13004 passed
This commit is part of merge request !97. Comments created here will be created in the context of that merge request.
...@@ -61,12 +61,15 @@ static void waitTimePoint() { ...@@ -61,12 +61,15 @@ static void waitTimePoint() {
} }
// Still lots of time so do some idle jobs // Still lots of time so do some idle jobs
{
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++).job(now);
now = get_time(); now = get_time();
msdelay = mspf - (now % mspf); msdelay = mspf - (now % mspf);
} }
}
// Spin loop until exact grab time // Spin loop until exact grab time
//LOG(INFO) << "Spin Delay: " << (now / 40) << " = " << (40 - (now%40)); //LOG(INFO) << "Spin Delay: " << (now / 40) << " = " << (40 - (now%40));
......
...@@ -130,6 +130,8 @@ class Streamer : public ftl::Configurable { ...@@ -130,6 +130,8 @@ class Streamer : public ftl::Configurable {
//int64_t last_dropped_; //int64_t last_dropped_;
//int drop_count_; //int drop_count_;
ftl::timer::TimerHandle timer_job_;
void _transmit(ftl::rgbd::FrameSet &); void _transmit(ftl::rgbd::FrameSet &);
void _cleanUp(); void _cleanUp();
void _addClient(const std::string &source, int N, int rate, const ftl::UUID &peer, const std::string &dest); void _addClient(const std::string &source, int N, int rate, const ftl::UUID &peer, const std::string &dest);
......
...@@ -125,6 +125,7 @@ Streamer::Streamer(nlohmann::json &config, Universe *net) ...@@ -125,6 +125,7 @@ Streamer::Streamer(nlohmann::json &config, Universe *net)
} }
Streamer::~Streamer() { Streamer::~Streamer() {
timer_job_.cancel();
net_->unbind("find_stream"); net_->unbind("find_stream");
net_->unbind("list_streams"); net_->unbind("list_streams");
net_->unbind("source_calibration"); net_->unbind("source_calibration");
...@@ -172,7 +173,7 @@ void Streamer::_addClient(const string &source, int N, int rate, const ftl::UUID ...@@ -172,7 +173,7 @@ 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;
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) // 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 = net_->call<int64_t>(peer, "__ping__");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment