Commit ea611f2d authored by gabime's avatar gabime

reduced spinning duation in async_log_helper

parent 9b984ddb
......@@ -315,6 +315,7 @@ inline bool spdlog::details::async_log_helper::process_next_msg(log_clock::time_
}
}
// flush all sinks if _flush_interval_ms has expired
inline void spdlog::details::async_log_helper::handle_flush_interval(log_clock::time_point& now, log_clock::time_point& last_flush)
{
auto should_flush = _flush_requested || (_flush_interval_ms != std::chrono::milliseconds::zero() && now - last_flush >= _flush_interval_ms);
......@@ -326,34 +327,37 @@ inline void spdlog::details::async_log_helper::handle_flush_interval(log_clock::
_flush_requested = false;
}
}
inline void spdlog::details::async_log_helper::set_formatter(formatter_ptr msg_formatter)
{
_formatter = msg_formatter;
}
// sleep,yield or return immediatly using the time passed since last message as a hint
// spin, yield or sleep. use the time passed since last message as a hint
inline void spdlog::details::async_log_helper::sleep_or_yield(const spdlog::log_clock::time_point& now, const spdlog::log_clock::time_point& last_op_time)
{
using std::chrono::milliseconds;
using namespace std::this_thread;
using std::chrono::milliseconds;
using std::chrono::microseconds;
auto time_since_op = now - last_op_time;
// spin upto 1 ms
if (time_since_op <= milliseconds(1))
// spin upto 50 micros
if (time_since_op <= microseconds(50))
return;
// yield upto 10ms
if (time_since_op <= milliseconds(10))
// yield upto 150 micros
if (time_since_op <= microseconds(100))
return yield();
// sleep for half of duration since last op
if (time_since_op <= milliseconds(100))
return sleep_for(time_since_op / 2);
// sleep for 20 ms upto 200 ms
if (time_since_op <= milliseconds(200))
return sleep_for(milliseconds(20));
return sleep_for(milliseconds(100));
// sleep for 200 ms
return sleep_for(milliseconds(200));
}
// throw if the worker thread threw an exception or not active
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment