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

Method thread_function

include/fplus/side_effects.hpp:101–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99
100private:
101 void thread_function()
102 {
103 auto last_wake_up_time = std::chrono::steady_clock::now();
104 auto last_time = last_wake_up_time;
105 bool quit = false;
106 while (!quit) {
107 const auto wake_up_time = last_wake_up_time + std::chrono::microseconds { interval_us_ };
108 const auto sleep_time = wake_up_time - std::chrono::steady_clock::now();
109 if (stop_mutex_.try_lock_for(sleep_time)) {
110 stop_mutex_.unlock();
111 quit = true;
112 }
113 const auto current_time = std::chrono::steady_clock::now();
114 const auto elapsed = current_time - last_time;
115 last_wake_up_time = wake_up_time;
116 last_time = current_time;
117 const auto elapsed_us = std::chrono::duration_cast<std::chrono::microseconds>(
118 elapsed)
119 .count();
120 try {
121 f_(elapsed_us);
122 } catch (...) {
123 }
124 }
125 }
126 const function f_;
127 const std::int64_t interval_us_;
128 std::mutex control_mutex_;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected