MCPcopy Create free account
hub / github.com/Dobiasd/FunctionalPlus / thread_function

Method thread_function

include_all_in_one/include/fplus/fplus.hpp:13623–13647  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13621
13622private:
13623 void thread_function()
13624 {
13625 auto last_wake_up_time = std::chrono::steady_clock::now();
13626 auto last_time = last_wake_up_time;
13627 bool quit = false;
13628 while (!quit) {
13629 const auto wake_up_time = last_wake_up_time + std::chrono::microseconds { interval_us_ };
13630 const auto sleep_time = wake_up_time - std::chrono::steady_clock::now();
13631 if (stop_mutex_.try_lock_for(sleep_time)) {
13632 stop_mutex_.unlock();
13633 quit = true;
13634 }
13635 const auto current_time = std::chrono::steady_clock::now();
13636 const auto elapsed = current_time - last_time;
13637 last_wake_up_time = wake_up_time;
13638 last_time = current_time;
13639 const auto elapsed_us = std::chrono::duration_cast<std::chrono::microseconds>(
13640 elapsed)
13641 .count();
13642 try {
13643 f_(elapsed_us);
13644 } catch (...) {
13645 }
13646 }
13647 }
13648 const function f_;
13649 const std::int64_t interval_us_;
13650 std::mutex control_mutex_;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected