|
|
|
@ -10,21 +10,21 @@
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace spdlog {
|
|
|
|
|
namespace details {
|
|
|
|
|
namespace details {
|
|
|
|
|
|
|
|
|
|
using async_logger_ptr = std::shared_ptr<spdlog::async_logger>;
|
|
|
|
|
using async_logger_ptr = std::shared_ptr<spdlog::async_logger>;
|
|
|
|
|
|
|
|
|
|
enum class async_msg_type
|
|
|
|
|
{
|
|
|
|
|
enum class async_msg_type
|
|
|
|
|
{
|
|
|
|
|
log,
|
|
|
|
|
flush,
|
|
|
|
|
terminate
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Async msg to move to/from the queue
|
|
|
|
|
// Movable only. should never be copied
|
|
|
|
|
struct async_msg
|
|
|
|
|
{
|
|
|
|
|
struct async_msg
|
|
|
|
|
{
|
|
|
|
|
async_msg_type msg_type;
|
|
|
|
|
level::level_enum level;
|
|
|
|
|
log_clock::time_point time;
|
|
|
|
@ -39,7 +39,9 @@ namespace spdlog {
|
|
|
|
|
|
|
|
|
|
// should only be moved in or out of the queue..
|
|
|
|
|
async_msg(const async_msg &) = delete;
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER <= 1800 // support for vs2013 move
|
|
|
|
|
|
|
|
|
|
// support for vs2013 move
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER <= 1800
|
|
|
|
|
async_msg(async_msg &&other) SPDLOG_NOEXCEPT : msg_type(other.msg_type),
|
|
|
|
|
level(other.level),
|
|
|
|
|
time(other.time),
|
|
|
|
@ -61,7 +63,7 @@ namespace spdlog {
|
|
|
|
|
worker_ptr = std::move(other.worker_ptr);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
#else // (_MSC_VER) && _MSC_VER <= 1800
|
|
|
|
|
async_msg(async_msg &&other) = default;
|
|
|
|
|
async_msg &operator=(async_msg &&other) = default;
|
|
|
|
|
#endif
|
|
|
|
@ -100,11 +102,11 @@ namespace spdlog {
|
|
|
|
|
msg.color_range_start = 0;
|
|
|
|
|
msg.color_range_end = 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class thread_pool
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
class thread_pool
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
using item_type = async_msg;
|
|
|
|
|
using q_type = details::mpmc_blocking_queue<item_type>;
|
|
|
|
|
using clock_type = std::chrono::steady_clock;
|
|
|
|
@ -154,7 +156,7 @@ namespace spdlog {
|
|
|
|
|
post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
private:
|
|
|
|
|
q_type q_;
|
|
|
|
|
|
|
|
|
|
std::vector<std::thread> threads_;
|
|
|
|
@ -173,9 +175,7 @@ namespace spdlog {
|
|
|
|
|
|
|
|
|
|
void worker_loop_()
|
|
|
|
|
{
|
|
|
|
|
while (process_next_msg_())
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
while (process_next_msg_()) {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// process next message in the queue
|
|
|
|
@ -213,7 +213,7 @@ namespace spdlog {
|
|
|
|
|
assert(false);
|
|
|
|
|
return true; // should not be reached
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace details
|
|
|
|
|
} // namespace details
|
|
|
|
|
} // namespace spdlog
|