void pcl::TimeTrigger::thread_function () { double time = 0; while (true) { time = getTime (); boost::unique_lock<boost::mutex> lock (condition_mutex_); if(quit_) break; if (!running_) condition_.wait (lock); // wait util start is called or destructor is called else { callbacks_(); double rest = interval_ + time - getTime (); #if defined(BOOST_HAS_WINTHREADS) && (BOOST_VERSION < 105500) //infinite timed_wait bug: https://svn.boost.org/trac/boost/ticket/9079 if (rest > 0.0) // without a deadlock is possible, until notify() is called condition_.timed_wait (lock, boost::posix_time::microseconds (static_cast<int64_t> ((rest * 1000000)))); #else condition_.timed_wait (lock, boost::posix_time::microseconds (static_cast<int64_t> ((rest * 1000000)))); #endif } } }
void pcl::TimeTrigger::thread_function () { static double time = 0; while (!quit_) { time = getTime (); boost::unique_lock<boost::mutex> lock (condition_mutex_); if (!running_) condition_.wait (lock); // wait util start is called or destructor is called else { callbacks_(); double rest = interval_ + time - getTime (); condition_.timed_wait (lock, boost::posix_time::microseconds ((int64_t) (rest * 1000000))); } } }
void Metrics::calculate_metrics() { std::lock_guard<std::mutex> lock(counters_lock_); MetricVector metrics; for (const auto& counter : counters_) { auto values = counter.second(); if (not values.empty()) { metrics.emplace_back(std::cref(counter.first), std::move(values)); } } if (!metrics.empty()) { callbacks_(metrics); } }