astyle+comments

This commit is contained in:
gabime 2015-02-10 01:56:09 +02:00
parent 9f993da472
commit fde3d2db99
5 changed files with 21 additions and 17 deletions

View File

@ -19,9 +19,9 @@ int main(int argc, char* argv[])
int thread_count = 10; int thread_count = 10;
if(argc > 1) if(argc > 1)
thread_count = atoi(argv[1]); thread_count = atoi(argv[1]);
int howmany = 1000000; int howmany = 10000001;
spd::set_async_mode(1048576); spd::set_async_mode(1048576*16, spd::async_overflow_policy::discard_log_msg);
auto logger = spdlog::create<spd::sinks::simple_file_sink_mt>("file_logger", "logs/spd-bench-async.txt", false); auto logger = spdlog::create<spd::sinks::simple_file_sink_mt>("file_logger", "logs/spd-bench-async.txt", false);
logger->set_pattern("[%Y-%b-%d %T.%e]: %v"); logger->set_pattern("[%Y-%b-%d %T.%e]: %v");

View File

@ -94,7 +94,10 @@ int main(int, char* [])
// Example of user defined class with operator<< // Example of user defined class with operator<<
// //
class some_class {}; class some_class {};
std::ostream& operator<<(std::ostream& os, const some_class&) { return os << "some_class"; } std::ostream& operator<<(std::ostream& os, const some_class&)
{
return os << "some_class";
}
void custom_class_example() void custom_class_example()
{ {

View File

@ -107,8 +107,9 @@ public:
void log(const details::log_msg& msg); void log(const details::log_msg& msg);
//Stop logging and join the back thread // stop logging and join the back thread
~async_log_helper(); ~async_log_helper();
void set_formatter(formatter_ptr); void set_formatter(formatter_ptr);
@ -137,11 +138,11 @@ private:
// worker thread main loop // worker thread main loop
void worker_loop(); void worker_loop();
//pop next message from the queue and process it // pop next message from the queue and process it
//return true if a message was available (queue was not empty), will set the last_pop to the pop time // return true if a message was available (queue was not empty), will set the last_pop to the pop time
bool process_next_msg(clock::time_point& last_pop); bool process_next_msg(clock::time_point& last_pop);
// guess how much to sleep if queue is empty/full using last successful op time as hint // sleep,yield or return immediatly using the time passed since last message as a hint
static void sleep_or_yield(const clock::time_point& last_op_time); static void sleep_or_yield(const clock::time_point& last_op_time);
}; };
@ -210,8 +211,8 @@ inline void spdlog::details::async_log_helper::worker_loop()
} }
} }
// Process next message in the queue // process next message in the queue
// Return true if this thread should still be active (no msg with level::off was received) // return true if this thread should still be active (no msg with level::off was received)
inline bool spdlog::details::async_log_helper::process_next_msg(clock::time_point& last_pop) inline bool spdlog::details::async_log_helper::process_next_msg(clock::time_point& last_pop)
{ {
@ -243,7 +244,7 @@ inline void spdlog::details::async_log_helper::set_formatter(formatter_ptr msg_f
} }
// Sleep,yield or return immediatly using the time passed since last message as a hint // sleep,yield or return immediatly using the time passed since last message as a hint
inline void spdlog::details::async_log_helper::sleep_or_yield(const clock::time_point& last_op_time) inline void spdlog::details::async_log_helper::sleep_or_yield(const clock::time_point& last_op_time)
{ {
using std::chrono::milliseconds; using std::chrono::milliseconds;
@ -251,7 +252,7 @@ inline void spdlog::details::async_log_helper::sleep_or_yield(const clock::time_
auto time_since_op = clock::now() - last_op_time; auto time_since_op = clock::now() - last_op_time;
//spin upto 1 ms // spin upto 1 ms
if (time_since_op <= milliseconds(1)) if (time_since_op <= milliseconds(1))
return; return;
@ -267,7 +268,7 @@ inline void spdlog::details::async_log_helper::sleep_or_yield(const clock::time_
return sleep_for(milliseconds(100)); return sleep_for(milliseconds(100));
} }
//throw if the worker thread threw an exception or not active // throw if the worker thread threw an exception or not active
inline void spdlog::details::async_log_helper::throw_if_bad_worker() inline void spdlog::details::async_log_helper::throw_if_bad_worker()
{ {
if (_last_workerthread_ex) if (_last_workerthread_ex)