From 0d5afe86d9e18eb1f67ae9657acc6f79acf681a4 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Sat, 22 Sep 2012 21:26:13 -0400 Subject: [PATCH] fixed thread::schedule --- include/fc/exception.hpp | 8 ++++++-- include/fc/string.hpp | 2 ++ src/exception.cpp | 4 ++-- src/string.cpp | 3 +++ src/thread.cpp | 5 ++++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/fc/exception.hpp b/include/fc/exception.hpp index 6f76d90..77514bf 100644 --- a/include/fc/exception.hpp +++ b/include/fc/exception.hpp @@ -55,9 +55,9 @@ namespace fc { const fc::string& a1 ); void throw_exception_( const char* func, const char* file, int line, const char* msg, const fc::string& a1, const fc::string& a2 ); - void throw_exception( const char* func, const char* file, int line, const char* msg, + void throw_exception_( const char* func, const char* file, int line, const char* msg, const fc::string& a1, const fc::string& a2, const fc::string& a3 ); - void throw_exception( const char* func, const char* file, int line, const char* msg, + void throw_exception_( const char* func, const char* file, int line, const char* msg, const fc::string& a1, const fc::string& a2, const fc::string& a3, const fc::string& a4 ); template @@ -83,6 +83,10 @@ namespace fc { void throw_exception( const char* func, const char* file, int line, const char* msg, T1&& a1, T2&& a2 ) { throw_exception_( func, file, line, msg, to_string(fc::forward(a1) ), to_string( fc::forward(a2) ) ); } + template + void throw_exception( const char* func, const char* file, int line, const char* msg, T1&& a1, T2&& a2, T3&& a3 ) { + throw_exception_( func, file, line, msg, to_string(fc::forward(a1) ), to_string( fc::forward(a2) ), to_string( fc::forward(a3) ) ); + } } // namespace fc diff --git a/include/fc/string.hpp b/include/fc/string.hpp index 9753ad1..d9e214c 100644 --- a/include/fc/string.hpp +++ b/include/fc/string.hpp @@ -49,6 +49,8 @@ namespace fc { bool operator == ( const string& s )const; bool operator != ( const string& s )const; + friend bool operator < ( const string& a, const string& b ); + string& operator+=( const string& s ); string& operator+=( char c ); diff --git a/src/exception.cpp b/src/exception.cpp index 3e931ed..59fb3b8 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -94,11 +94,11 @@ namespace fc { const fc::string& a1, const fc::string& a2 ) { ::boost::exception_detail::throw_exception_(fc::generic_exception( (boost::format(msg) % a1.c_str() %a2.c_str()).str().c_str()),func, file, line ); } - void throw_exception( const char* func, const char* file, int line, const char* msg, + void throw_exception_( const char* func, const char* file, int line, const char* msg, const fc::string& a1, const fc::string& a2, const fc::string& a3 ) { ::boost::exception_detail::throw_exception_(fc::generic_exception(msg),func, file, line ); } - void throw_exception( const char* func, const char* file, int line, const char* msg, + void throw_exception_( const char* func, const char* file, int line, const char* msg, const fc::string& a1, const fc::string& a2, const fc::string& a3, const fc::string& a4 ) { ::boost::exception_detail::throw_exception_(fc::generic_exception(msg),func, file, line ); } diff --git a/src/string.cpp b/src/string.cpp index 0e2d6f5..c5bbaf5 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -94,6 +94,9 @@ namespace fc { return *this; } + bool operator < ( const string& a, const string& b ) { + return reinterpret_cast(a) < reinterpret_cast(b); + } string operator + ( const string& s, const string& c ) { return string(s) += c; } diff --git a/src/thread.cpp b/src/thread.cpp index da70735..aa106b1 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -211,7 +211,7 @@ namespace fc { } void thread::async_task( task_base* t, const priority& p, const char* desc ) { - async_task( t, p, time_point::max(), desc ); + async_task( t, p, time_point::min(), desc ); } void thread::poke() { @@ -220,6 +220,9 @@ namespace fc { } void thread::async_task( task_base* t, const priority& p, const time_point& tp, const char* desc ) { + t->_when = tp; + // slog( "when %lld", t->_when.time_since_epoch().count() ); + // slog( "delay %lld", (tp - fc::time_point::now()).count() ); task_base* stale_head = my->task_in_queue.load(boost::memory_order_relaxed); do { t->_next = stale_head; }while( !my->task_in_queue.compare_exchange_weak( stale_head, t, boost::memory_order_release ) );