mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 10:01:33 +08:00
reduced spinning duation in async_log_helper
This commit is contained in:
parent
9b984ddbed
commit
ea611f2d79
@ -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)
|
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);
|
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;
|
_flush_requested = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void spdlog::details::async_log_helper::set_formatter(formatter_ptr msg_formatter)
|
inline void spdlog::details::async_log_helper::set_formatter(formatter_ptr msg_formatter)
|
||||||
{
|
{
|
||||||
_formatter = 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)
|
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 namespace std::this_thread;
|
||||||
|
using std::chrono::milliseconds;
|
||||||
|
using std::chrono::microseconds;
|
||||||
|
|
||||||
auto time_since_op = now - last_op_time;
|
auto time_since_op = now - last_op_time;
|
||||||
|
|
||||||
// spin upto 1 ms
|
// spin upto 50 micros
|
||||||
if (time_since_op <= milliseconds(1))
|
if (time_since_op <= microseconds(50))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// yield upto 10ms
|
// yield upto 150 micros
|
||||||
if (time_since_op <= milliseconds(10))
|
if (time_since_op <= microseconds(100))
|
||||||
return yield();
|
return yield();
|
||||||
|
|
||||||
|
|
||||||
// sleep for half of duration since last op
|
// sleep for 20 ms upto 200 ms
|
||||||
if (time_since_op <= milliseconds(100))
|
if (time_since_op <= milliseconds(200))
|
||||||
return sleep_for(time_since_op / 2);
|
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
|
// throw if the worker thread threw an exception or not active
|
||||||
|
Loading…
Reference in New Issue
Block a user