added thread name + formating to log
This commit is contained in:
parent
297b073c94
commit
bebe2d9146
3 changed files with 14 additions and 4 deletions
|
|
@ -186,6 +186,8 @@ namespace fc {
|
||||||
/// @pre valid()
|
/// @pre valid()
|
||||||
bool error()const { return m_prom->error(); }
|
bool error()const { return m_prom->error(); }
|
||||||
|
|
||||||
|
void cancel()const { m_prom->cancel(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pre valid()
|
* @pre valid()
|
||||||
*
|
*
|
||||||
|
|
@ -230,6 +232,8 @@ namespace fc {
|
||||||
/// @pre valid()
|
/// @pre valid()
|
||||||
bool error()const { return m_prom->error(); }
|
bool error()const { return m_prom->error(); }
|
||||||
|
|
||||||
|
void cancel()const { m_prom->cancel(); }
|
||||||
|
|
||||||
template<typename CompletionHandler>
|
template<typename CompletionHandler>
|
||||||
void on_complete( CompletionHandler&& c ) {
|
void on_complete( CompletionHandler&& c ) {
|
||||||
m_prom->on_complete( fc::forward<CompletionHandler>(c) );
|
m_prom->on_complete( fc::forward<CompletionHandler>(c) );
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
|
const char* thread_name();
|
||||||
|
|
||||||
const char* short_name( const char* file_name ) {
|
const char* short_name( const char* file_name ) {
|
||||||
const char* end = file_name + strlen(file_name);
|
const char* end = file_name + strlen(file_name);
|
||||||
--end;
|
--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, ... ) {
|
void log( const char* color, const char* file_name, size_t line_num, const char* method_name, const char* format, ... ) {
|
||||||
if(isatty(fileno(stderr)))
|
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_list args;
|
||||||
va_start(args,format);
|
va_start(args,format);
|
||||||
vfprintf( stderr, format, args );
|
vfprintf( stderr, format, args );
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@
|
||||||
#include "thread_d.hpp"
|
#include "thread_d.hpp"
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
|
const char* thread_name() {
|
||||||
|
return thread::current().name().c_str();
|
||||||
|
}
|
||||||
boost::mutex& log_mutex() {
|
boost::mutex& log_mutex() {
|
||||||
static boost::mutex m; return m;
|
static boost::mutex m; return m;
|
||||||
}
|
}
|
||||||
|
|
@ -59,14 +62,15 @@ namespace fc {
|
||||||
void thread::debug( const fc::string& d ) { my->debug(d); }
|
void thread::debug( const fc::string& d ) { my->debug(d); }
|
||||||
|
|
||||||
void thread::quit() {
|
void thread::quit() {
|
||||||
wlog( "quit!" );
|
|
||||||
if( ¤t() != this ) {
|
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 ) {
|
if( my->boost_thread ) {
|
||||||
my->boost_thread->join();
|
my->boost_thread->join();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
wlog( "%s", my->name.c_str() );
|
||||||
|
|
||||||
// break all promises, thread quit!
|
// break all promises, thread quit!
|
||||||
fc::context* cur = my->blocked;
|
fc::context* cur = my->blocked;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue