diff --git a/include/fc/future.hpp b/include/fc/future.hpp index 900b702..70c53b1 100644 --- a/include/fc/future.hpp +++ b/include/fc/future.hpp @@ -186,6 +186,8 @@ namespace fc { /// @pre valid() bool error()const { return m_prom->error(); } + void cancel()const { m_prom->cancel(); } + /** * @pre valid() * @@ -230,6 +232,8 @@ namespace fc { /// @pre valid() bool error()const { return m_prom->error(); } + void cancel()const { m_prom->cancel(); } + template void on_complete( CompletionHandler&& c ) { m_prom->on_complete( fc::forward(c) ); diff --git a/src/log.cpp b/src/log.cpp index 6dfcc30..5342f47 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -5,6 +5,8 @@ #include namespace fc { + const char* thread_name(); + const char* short_name( const char* file_name ) { const char* end = file_name + strlen(file_name); --end; @@ -24,9 +26,9 @@ namespace fc { void log( const char* color, const char* file_name, size_t line_num, const char* method_name, const char* format, ... ) { if(isatty(fileno(stderr))) - fprintf( stderr, "%s", color ); + fprintf( stderr, "\r%s", color ); - fprintf( stderr, "%s:%zd %s ", short_name(file_name), line_num, method_name ); + fprintf( stderr, "%-15s %-15s %-5zd %s ", thread_name(), short_name(file_name), line_num, method_name ); va_list args; va_start(args,format); vfprintf( stderr, format, args ); diff --git a/src/thread.cpp b/src/thread.cpp index 8967c65..b04ad28 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -3,6 +3,9 @@ #include "thread_d.hpp" namespace fc { + const char* thread_name() { + return thread::current().name().c_str(); + } boost::mutex& log_mutex() { static boost::mutex m; return m; } @@ -59,14 +62,15 @@ namespace fc { void thread::debug( const fc::string& d ) { my->debug(d); } void thread::quit() { - wlog( "quit!" ); if( ¤t() != this ) { - async( boost::bind( &thread::quit, this ) ).wait(); + wlog( "async quit %s", my->name.c_str() ); + async( [=](){quit();} ).wait(); if( my->boost_thread ) { my->boost_thread->join(); } return; } + wlog( "%s", my->name.c_str() ); // break all promises, thread quit! fc::context* cur = my->blocked;