Commit 2894e8de authored by gabime's avatar gabime

clang format

parent 74c10df1
CXX ?= g++
CXXFLAGS = -march=native -Wall -Wextra -pedantic -std=c++11 -pthread -I../include -fmax-errors=1
CXX_RELEASE_FLAGS = -O3 -flto -Wl,--no-as-needed
CXX_RELEASE_FLAGS = -O3 -flto -Wl,--no-as-needed
binaries=bench latency
......
......@@ -23,6 +23,7 @@ void syslog_example();
int main(int, char *[])
{
try
{
// console logging example
......@@ -52,8 +53,8 @@ int main(int, char *[])
// apply some function on all registered loggers
spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) { l->info("End of example."); });
// Release and close all loggers
spdlog::drop_all();
// release any threads created by spdlog, and drop all loggers in the registry.
spdlog::shutdown();
}
// Exceptions will only be thrown upon failed logger or sink construction (not during logging)
catch (const spdlog::spdlog_ex &ex)
......@@ -69,7 +70,7 @@ void stdout_example()
{
// create color multi threaded logger
auto console = spdlog::stdout_color_mt("console");
console->info("Welcome to spdlog!");
console->info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
console->error("Some error message with arg: {}", 1);
auto err_logger = spdlog::stderr_color_mt("stderr");
......
......@@ -38,11 +38,11 @@ struct async_factory_impl
template<typename Sink, typename... SinkArgs>
static std::shared_ptr<async_logger> create(const std::string &logger_name, SinkArgs &&... args)
{
using details::registry;
using details::registry;
auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
// create default tp if not already exists.
auto tp = registry::instance().create_tp_once(details::default_async_q_size, 1);
// create default tp if not already exists.
auto tp = registry::instance().create_tp_once(details::default_async_q_size, 1);
auto new_logger = std::make_shared<async_logger>(logger_name, std::move(sink), std::move(tp), OverflowPolicy);
registry::instance().register_and_init(new_logger);
return new_logger;
......@@ -66,9 +66,9 @@ inline std::shared_ptr<spdlog::logger> create_async_nb(const std::string &logger
// set global thread pool.
inline void init_thread_pool(size_t q_size, size_t thread_count)
{
{
auto tp = std::make_shared<details::thread_pool>(q_size, thread_count);
details::registry::instance().set_tp(std::move(tp));
details::registry::instance().set_tp(std::move(tp));
}
// get the global thread pool.
......
......@@ -50,15 +50,15 @@ public:
// stop the worker thread and join it
~periodic_worker()
{
if (worker_thread_.joinable())
{
{
std::lock_guard<std::mutex> lock(mutex_);
active_ = false;
}
cv_.notify_one();
worker_thread_.join();
}
if (worker_thread_.joinable())
{
{
std::lock_guard<std::mutex> lock(mutex_);
active_ = false;
}
cv_.notify_one();
worker_thread_.join();
}
}
private:
......
......@@ -72,16 +72,16 @@ public:
tp_ = std::move(tp);
}
// create tp only if not exists already
std::shared_ptr<thread_pool> create_tp_once(size_t queue_size, size_t n_threads)
{
std::lock_guard<std::mutex> lock(tp_mutex_);
if (tp_ == nullptr)
{
tp_ = std::make_shared<details::thread_pool>(queue_size, n_threads);
}
return tp_;
}
// create tp only if not exists already
std::shared_ptr<thread_pool> create_tp_once(size_t queue_size, size_t n_threads)
{
std::lock_guard<std::mutex> lock(tp_mutex_);
if (tp_ == nullptr)
{
tp_ = std::make_shared<details::thread_pool>(queue_size, n_threads);
}
return tp_;
}
std::shared_ptr<thread_pool> get_tp()
{
......@@ -146,14 +146,14 @@ public:
}
}
void flush_all()
{
std::lock_guard<std::mutex> lock(logger_map_mutex_);
for (auto &l : loggers_)
{
l.second->flush();
}
}
void flush_all()
{
std::lock_guard<std::mutex> lock(logger_map_mutex_);
for (auto &l : loggers_)
{
l.second->flush();
}
}
void drop(const std::string &logger_name)
{
......@@ -175,14 +175,14 @@ public:
periodic_flusher_.reset();
}
drop_all();
drop_all();
{
std::lock_guard<std::mutex> lock(tp_mutex_);
tp_.reset();
}
}
static registry &instance()
{
static registry s_instance;
......@@ -208,10 +208,10 @@ private:
throw spdlog_ex("logger with name '" + logger_name + "' already exists");
}
}
std::mutex logger_map_mutex_, flusher_mutex_;
std::mutex tp_mutex_;
std::unordered_map<std::string, std::shared_ptr<logger>> loggers_;
std::unordered_map<std::string, std::shared_ptr<logger>> loggers_;
std::unique_ptr<formatter> formatter_;
level::level_enum level_ = level::info;
level::level_enum flush_level_ = level::off;
......
......@@ -10,6 +10,7 @@
#include "spdlog/common.h"
#include "spdlog/details/registry.h"
#include "spdlog/logger.h"
#include "spdlog/version.h"
#include <chrono>
#include <functional>
......@@ -120,7 +121,7 @@ inline void drop_all()
// stop any running threads started by spdlog and clean registry loggers
inline void shutdown()
{
details::registry::instance().shutdown();
details::registry::instance().shutdown();
}
///////////////////////////////////////////////////////////////////////////////
......
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