mirror of
https://github.com/gabime/spdlog.git
synced 2025-04-01 02:42:41 +08:00
Revert d5468e50f6
This commit is contained in:
parent
d5468e50f6
commit
d409e5367b
@ -10,26 +10,27 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace spdlog {
|
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,
|
log,
|
||||||
flush,
|
flush,
|
||||||
terminate
|
terminate
|
||||||
};
|
};
|
||||||
|
|
||||||
// Async msg to move to/from the queue
|
// Async msg to move to/from the queue
|
||||||
// Movable only. should never be copied
|
// Movable only. should never be copied
|
||||||
struct async_msg
|
struct async_msg
|
||||||
{
|
{
|
||||||
async_msg_type msg_type;
|
async_msg_type msg_type;
|
||||||
level::level_enum level;
|
level::level_enum level;
|
||||||
log_clock::time_point time;
|
log_clock::time_point time;
|
||||||
size_t thread_id;
|
size_t thread_id;
|
||||||
fmt::basic_memory_buffer<char, 176> raw;
|
fmt::basic_memory_buffer<char, 176> raw;
|
||||||
|
|
||||||
size_t msg_id;
|
size_t msg_id;
|
||||||
async_logger_ptr worker_ptr;
|
async_logger_ptr worker_ptr;
|
||||||
|
|
||||||
@ -38,32 +39,32 @@ struct async_msg
|
|||||||
|
|
||||||
// should only be moved in or out of the queue..
|
// should only be moved in or out of the queue..
|
||||||
async_msg(const async_msg &) = delete;
|
async_msg(const async_msg &) = delete;
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER <= 1800 // support for vs2013 move
|
||||||
async_msg(async_msg &&other) SPDLOG_NOEXCEPT : msg_type(other.msg_type),
|
async_msg(async_msg &&other) SPDLOG_NOEXCEPT : msg_type(other.msg_type),
|
||||||
level(other.level),
|
level(other.level),
|
||||||
time(other.time),
|
time(other.time),
|
||||||
thread_id(other.thread_id),
|
thread_id(other.thread_id),
|
||||||
|
raw(move(other.raw)),
|
||||||
msg_id(other.msg_id),
|
msg_id(other.msg_id),
|
||||||
worker_ptr(std::move(other.worker_ptr))
|
worker_ptr(std::move(other.worker_ptr))
|
||||||
{
|
{
|
||||||
fmt_helper::append_buf(other.raw, raw);
|
|
||||||
other.raw.resize(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async_msg &operator=(async_msg &&other) SPDLOG_NOEXCEPT
|
async_msg &operator=(async_msg &&other) SPDLOG_NOEXCEPT
|
||||||
{
|
{
|
||||||
if (this == &other)
|
|
||||||
return *this;
|
|
||||||
msg_type = other.msg_type;
|
msg_type = other.msg_type;
|
||||||
level = other.level;
|
level = other.level;
|
||||||
time = other.time;
|
time = other.time;
|
||||||
thread_id = other.thread_id;
|
thread_id = other.thread_id;
|
||||||
raw.resize(0);
|
raw = std::move(other.raw);
|
||||||
fmt_helper::append_buf(other.raw, raw);
|
|
||||||
msg_id = other.msg_id;
|
msg_id = other.msg_id;
|
||||||
worker_ptr = std::move(other.worker_ptr);
|
worker_ptr = std::move(other.worker_ptr);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
async_msg(async_msg &&other) = default;
|
||||||
|
async_msg &operator=(async_msg &&other) = default;
|
||||||
|
#endif
|
||||||
|
|
||||||
// construct from log_msg with given type
|
// construct from log_msg with given type
|
||||||
async_msg(async_logger_ptr &&worker, async_msg_type the_type, details::log_msg &&m)
|
async_msg(async_logger_ptr &&worker, async_msg_type the_type, details::log_msg &&m)
|
||||||
@ -99,11 +100,11 @@ struct async_msg
|
|||||||
msg.color_range_start = 0;
|
msg.color_range_start = 0;
|
||||||
msg.color_range_end = 0;
|
msg.color_range_end = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class thread_pool
|
class thread_pool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using item_type = async_msg;
|
using item_type = async_msg;
|
||||||
using q_type = details::mpmc_blocking_queue<item_type>;
|
using q_type = details::mpmc_blocking_queue<item_type>;
|
||||||
using clock_type = std::chrono::steady_clock;
|
using clock_type = std::chrono::steady_clock;
|
||||||
@ -153,7 +154,7 @@ public:
|
|||||||
post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy);
|
post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
q_type q_;
|
q_type q_;
|
||||||
|
|
||||||
std::vector<std::thread> threads_;
|
std::vector<std::thread> threads_;
|
||||||
@ -212,7 +213,7 @@ private:
|
|||||||
assert(false);
|
assert(false);
|
||||||
return true; // should not be reached
|
return true; // should not be reached
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
Loading…
Reference in New Issue
Block a user