diff --git a/bench/spdlog-bench-async.cpp b/bench/spdlog-bench-async.cpp index c9fea752..d30e8677 100644 --- a/bench/spdlog-bench-async.cpp +++ b/bench/spdlog-bench-async.cpp @@ -14,9 +14,9 @@ int main(int, char* []) for(int i = 0 ; i < howmany; ++i) logger->info() << "spdlog message #" << i << ": This is some text for your pleasure"; - - //because spdlog async logger waits for the back thread logger to finish all messages upon destrcuting, - //and we want to measure only the time it took to push those messages to the backthread.. - abort(); + + //because spdlog async logger waits for the back thread logger to finish all messages upon destrcuting, + //and we want to measure only the time it took to push those messages to the backthread.. + abort(); return 0; } diff --git a/bench/spdlog-bench-mt-async.cpp b/bench/spdlog-bench-mt-async.cpp index a0949b7f..f7d424a1 100644 --- a/bench/spdlog-bench-mt-async.cpp +++ b/bench/spdlog-bench-mt-async.cpp @@ -45,7 +45,7 @@ int main(int argc, char* argv[]) t.join(); }; - //because spdlog async logger waits for the back thread logger to finish all messages upon destrcuting, - //and we want to measure only the time it took to push those messages to the backthread.. - abort(); + //because spdlog async logger waits for the back thread logger to finish all messages upon destrcuting, + //and we want to measure only the time it took to push those messages to the backthread.. + abort(); } diff --git a/example/bench.cpp b/example/bench.cpp index 9b6f41f0..be9a0c27 100644 --- a/example/bench.cpp +++ b/example/bench.cpp @@ -69,8 +69,8 @@ int main(int argc, char* argv[]) cout << "Single thread, " << format(howmany) << " iterations, auto flush=" << auto_flush << endl; cout << "*******************************************************************************\n"; - auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st", file_size, rotating_files, auto_flush); - bench(howmany, rotating_st); + auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st", file_size, rotating_files, auto_flush); + bench(howmany, rotating_st); auto daily_st = spdlog::daily_logger_st("daily_st", "logs/daily_st", auto_flush); bench(howmany, daily_st); bench(howmany, spdlog::create("null_st")); @@ -79,8 +79,8 @@ int main(int argc, char* argv[]) cout << threads << " threads sharing same logger, " << format(howmany) << " iterations, auto_flush=" << auto_flush << endl; cout << "*******************************************************************************\n"; - auto rotating_mt = spdlog::rotating_logger_mt("rotating_mt", "logs/rotating_mt", file_size, rotating_files, auto_flush); - bench_mt(howmany, rotating_mt, threads); + auto rotating_mt = spdlog::rotating_logger_mt("rotating_mt", "logs/rotating_mt", file_size, rotating_files, auto_flush); + bench_mt(howmany, rotating_mt, threads); auto daily_mt = spdlog::daily_logger_mt("daily_mt", "logs/daily_mt", auto_flush); @@ -94,12 +94,12 @@ int main(int argc, char* argv[]) spdlog::set_async_mode(howmany); - for(int i = 0; i < 5; ++i) - { - auto as = spdlog::daily_logger_st("as", "logs/daily_async", auto_flush); - bench_mt(howmany, as, threads); - spdlog::drop("as"); - } + for(int i = 0; i < 5; ++i) + { + auto as = spdlog::daily_logger_st("as", "logs/daily_async", auto_flush); + bench_mt(howmany, as, threads); + spdlog::drop("as"); + } } catch (std::exception &ex) { diff --git a/example/example.cpp b/example/example.cpp index 9efa07ee..d07cf801 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -47,7 +47,7 @@ int main(int, char* []) console->info("An info message example {}..", 1); console->info() << "Streams are supported too " << 1; - + console->info("Easy padding in numbers like {:08d}", 12); console->info("Support for int: {0:d}; hex: {0:08x}; oct: {0:o}; bin: {0:b}", 42); console->info("Support for floats {:03.2f}", 1.23456); @@ -56,13 +56,13 @@ int main(int, char* []) console->info("{:<30}", "left aligned"); console->info("{:>30}", "right aligned"); console->info("{:^30}", "centered"); - + //Create a file rotating logger with 5mb size max and 3 rotated files auto file_logger = spd::rotating_logger_mt("file_logger", filename, 1024 * 1024 * 5, 3); - - file_logger->info("Log file message number", 1); - for(int i = 0; i < 10; ++i) - file_logger->info("{} * {} equals {:>10}", i, i, i*i); + + file_logger->info("Log file message number", 1); + for(int i = 0; i < 10; ++i) + file_logger->info("{} * {} equals {:>10}", i, i, i*i); spd::set_pattern("*** [%H:%M:%S %z] [thread %t] %v ***"); file_logger->info("This is another message with custom format"); diff --git a/include/spdlog/details/mpmc_bounded_q.h b/include/spdlog/details/mpmc_bounded_q.h index 53dfd108..7cbcfd70 100644 --- a/include/spdlog/details/mpmc_bounded_q.h +++ b/include/spdlog/details/mpmc_bounded_q.h @@ -74,101 +74,101 @@ class mpmc_bounded_queue { public: - using item_type = T; - mpmc_bounded_queue(size_t buffer_size) - : buffer_(new cell_t [buffer_size]), - buffer_mask_(buffer_size - 1) - { - //queue size must be power of two - if(!((buffer_size >= 2) && ((buffer_size & (buffer_size - 1)) == 0))) - throw spdlog_ex("async logger queue size must be power of two"); + using item_type = T; + mpmc_bounded_queue(size_t buffer_size) + : buffer_(new cell_t [buffer_size]), + buffer_mask_(buffer_size - 1) + { + //queue size must be power of two + if(!((buffer_size >= 2) && ((buffer_size & (buffer_size - 1)) == 0))) + throw spdlog_ex("async logger queue size must be power of two"); - for (size_t i = 0; i != buffer_size; i += 1) - buffer_[i].sequence_.store(i, std::memory_order_relaxed); - enqueue_pos_.store(0, std::memory_order_relaxed); - dequeue_pos_.store(0, std::memory_order_relaxed); - } + for (size_t i = 0; i != buffer_size; i += 1) + buffer_[i].sequence_.store(i, std::memory_order_relaxed); + enqueue_pos_.store(0, std::memory_order_relaxed); + dequeue_pos_.store(0, std::memory_order_relaxed); + } - ~mpmc_bounded_queue() - { - delete [] buffer_; - } + ~mpmc_bounded_queue() + { + delete [] buffer_; + } - bool enqueue(T&& data) - { - cell_t* cell; - size_t pos = enqueue_pos_.load(std::memory_order_relaxed); - for (;;) - { - cell = &buffer_[pos & buffer_mask_]; - size_t seq = cell->sequence_.load(std::memory_order_acquire); - intptr_t dif = (intptr_t)seq - (intptr_t)pos; - if (dif == 0) - { - if (enqueue_pos_.compare_exchange_weak(pos, pos + 1, std::memory_order_relaxed)) - break; - } - else if (dif < 0) - { - return false; - } - else - { - pos = enqueue_pos_.load(std::memory_order_relaxed); - } - } - cell->data_ = std::move(data); - cell->sequence_.store(pos + 1, std::memory_order_release); - return true; - } + bool enqueue(T&& data) + { + cell_t* cell; + size_t pos = enqueue_pos_.load(std::memory_order_relaxed); + for (;;) + { + cell = &buffer_[pos & buffer_mask_]; + size_t seq = cell->sequence_.load(std::memory_order_acquire); + intptr_t dif = (intptr_t)seq - (intptr_t)pos; + if (dif == 0) + { + if (enqueue_pos_.compare_exchange_weak(pos, pos + 1, std::memory_order_relaxed)) + break; + } + else if (dif < 0) + { + return false; + } + else + { + pos = enqueue_pos_.load(std::memory_order_relaxed); + } + } + cell->data_ = std::move(data); + cell->sequence_.store(pos + 1, std::memory_order_release); + return true; + } - bool dequeue(T& data) - { - cell_t* cell; - size_t pos = dequeue_pos_.load(std::memory_order_relaxed); - for (;;) - { - cell = &buffer_[pos & buffer_mask_]; - size_t seq = - cell->sequence_.load(std::memory_order_acquire); - intptr_t dif = (intptr_t)seq - (intptr_t)(pos + 1); - if (dif == 0) - { - if (dequeue_pos_.compare_exchange_weak(pos, pos + 1, std::memory_order_relaxed)) - break; - } - else if (dif < 0) - return false; - else - pos = dequeue_pos_.load(std::memory_order_relaxed); - } - data = std::move(cell->data_); - cell->sequence_.store(pos + buffer_mask_ + 1, std::memory_order_release); - return true; - } + bool dequeue(T& data) + { + cell_t* cell; + size_t pos = dequeue_pos_.load(std::memory_order_relaxed); + for (;;) + { + cell = &buffer_[pos & buffer_mask_]; + size_t seq = + cell->sequence_.load(std::memory_order_acquire); + intptr_t dif = (intptr_t)seq - (intptr_t)(pos + 1); + if (dif == 0) + { + if (dequeue_pos_.compare_exchange_weak(pos, pos + 1, std::memory_order_relaxed)) + break; + } + else if (dif < 0) + return false; + else + pos = dequeue_pos_.load(std::memory_order_relaxed); + } + data = std::move(cell->data_); + cell->sequence_.store(pos + buffer_mask_ + 1, std::memory_order_release); + return true; + } private: - struct cell_t - { - std::atomic sequence_; - T data_; - }; + struct cell_t + { + std::atomic sequence_; + T data_; + }; - static size_t const cacheline_size = 64; - typedef char cacheline_pad_t [cacheline_size]; + static size_t const cacheline_size = 64; + typedef char cacheline_pad_t [cacheline_size]; - cacheline_pad_t pad0_; - cell_t* const buffer_; - size_t const buffer_mask_; - cacheline_pad_t pad1_; - std::atomic enqueue_pos_; - cacheline_pad_t pad2_; - std::atomic dequeue_pos_; - cacheline_pad_t pad3_; + cacheline_pad_t pad0_; + cell_t* const buffer_; + size_t const buffer_mask_; + cacheline_pad_t pad1_; + std::atomic enqueue_pos_; + cacheline_pad_t pad2_; + std::atomic dequeue_pos_; + cacheline_pad_t pad3_; - mpmc_bounded_queue(mpmc_bounded_queue const&); - void operator = (mpmc_bounded_queue const&); + mpmc_bounded_queue(mpmc_bounded_queue const&); + void operator = (mpmc_bounded_queue const&); }; } // ns details