move potential yields outside of catch

This commit is contained in:
Daniel Larimer 2015-10-09 17:08:03 -04:00
parent 2b2dfc62fc
commit 6495004302
6 changed files with 34 additions and 30 deletions

View file

@ -47,9 +47,9 @@
namespace fc { namespace fc {
class uint128;
template<typename T, size_t N> template<typename T, size_t N>
class array; class array;
class uint128;
// Hash function for a byte array. // Hash function for a byte array.
uint64_t city_hash64(const char *buf, size_t len); uint64_t city_hash64(const char *buf, size_t len);
@ -72,4 +72,5 @@ uint64_t city_hash_crc_64(const char *buf, size_t len);
uint128 city_hash_crc_128(const char *s, size_t len); uint128 city_hash_crc_128(const char *s, size_t len);
array<uint64_t,4> city_hash_crc_256(const char *s, size_t len); array<uint64_t,4> city_hash_crc_256(const char *s, size_t len);
} // namespace fc } // namespace fc

View file

@ -68,6 +68,7 @@ namespace fc { namespace rpc {
void handle_message( const variant_object& obj ) void handle_message( const variant_object& obj )
{ {
wlog( "recv: ${msg}", ("msg", obj) ); wlog( "recv: ${msg}", ("msg", obj) );
fc::exception_ptr eptr;
try try
{ {
auto m = obj.find("method"); auto m = obj.find("method");
@ -158,6 +159,7 @@ namespace fc { namespace rpc {
} }
else if( e != obj.end() ) //if error response else if( e != obj.end() ) //if error response
{ {
fc::exception_ptr eptr;
try try
{ {
auto err = e->value().get_object(); auto err = e->value().get_object();
@ -173,8 +175,9 @@ namespace fc { namespace rpc {
catch ( fc::exception& e ) catch ( fc::exception& e )
{ {
elog( "Error parsing exception: ${e}", ("e", e.to_detail_string() ) ); elog( "Error parsing exception: ${e}", ("e", e.to_detail_string() ) );
await->second->set_exception( e.dynamic_copy_exception() ); eptr = e.dynamic_copy_exception();
} }
if( eptr ) await->second->set_exception( eptr );
} }
else // id found without error, result, nor method field else // id found without error, result, nor method field
{ {
@ -191,12 +194,14 @@ namespace fc { namespace rpc {
{ {
fc_elog( _logger, "json rpc exception: ${exception}", ("exception",e )); fc_elog( _logger, "json rpc exception: ${exception}", ("exception",e ));
elog( "json rpc exception: ${exception}", ("exception",e )); elog( "json rpc exception: ${exception}", ("exception",e ));
close(e.dynamic_copy_exception()); eptr = e.dynamic_copy_exception();
} }
if( eptr ) { close(eptr); }
} }
void read_loop() void read_loop()
{ {
fc::exception_ptr eptr;
try try
{ {
fc::string line; fc::string line;
@ -211,16 +216,17 @@ namespace fc { namespace rpc {
catch ( eof_exception& eof ) catch ( eof_exception& eof )
{ {
_eof = true; _eof = true;
close( eof.dynamic_copy_exception() ); eptr = eof.dynamic_copy_exception();
} }
catch ( exception& e ) catch ( exception& e )
{ {
close( e.dynamic_copy_exception() ); eptr = e.dynamic_copy_exception();
} }
catch ( ... ) catch ( ... )
{ {
close( fc::exception_ptr(new FC_EXCEPTION( unhandled_exception, "json connection read error" )) ); eptr = fc::exception_ptr(new FC_EXCEPTION( unhandled_exception, "json connection read error" ));
} }
if( eptr ) close( eptr );
} }
void close( fc::exception_ptr e ) void close( fc::exception_ptr e )

View file

@ -62,16 +62,14 @@ namespace fc {
} }
_enqueue_thread(); _enqueue_thread();
} }
try std::exception_ptr e;
{ try { thread::current().wait_until( ptr(this,true), timeout_us ); }
thread::current().wait_until( ptr(this,true), timeout_us ); catch (...) { e = std::current_exception(); }
}
catch (...)
{
_dequeue_thread();
throw;
}
_dequeue_thread(); _dequeue_thread();
if( e ) std::rethrow_exception(e);
if( _ready ) if( _ready )
{ {
if( _exceptp ) if( _exceptp )

View file

@ -118,13 +118,18 @@ namespace fc {
cc->next_blocked_mutex = m_blist; cc->next_blocked_mutex = m_blist;
m_blist = cc; m_blist = cc;
} // end lock scope } // end lock scope
std::exception_ptr e;
try { try {
fc::thread::current().my->yield_until( abs_time, false ); fc::thread::current().my->yield_until( abs_time, false );
return( 0 == cc->next_blocked_mutex ); return( 0 == cc->next_blocked_mutex );
} catch (...) { } catch (...) {
cleanup( *this, m_blist_lock, m_blist, cc); e = std::current_exception();
throw;
} }
assert(e);
cleanup( *this, m_blist_lock, m_blist, cc);
std::rethrow_exception(e);
} }
void mutex::lock() { void mutex::lock() {
@ -166,6 +171,7 @@ namespace fc {
#endif #endif
} }
std::exception_ptr e; // cleanup calls yield so we need to move the exception outside of the catch block
try try
{ {
fc::thread::current().yield(false); fc::thread::current().yield(false);
@ -174,17 +180,13 @@ namespace fc {
assert(recursive_lock_count == 0); assert(recursive_lock_count == 0);
recursive_lock_count = 1; recursive_lock_count = 1;
} }
catch ( exception& e )
{
wlog( "lock threw: ${e}", ("e", e));
cleanup( *this, m_blist_lock, m_blist, current_context);
FC_RETHROW_EXCEPTION(e, warn, "lock threw: ${e}", ("e", e));
}
catch ( ... ) catch ( ... )
{ {
wlog( "lock threw unexpected exception" ); e = std::current_exception();
}
if( e ) {
cleanup( *this, m_blist_lock, m_blist, current_context); cleanup( *this, m_blist_lock, m_blist, current_context);
throw; std::rethrow_exception(e);
} }
} }

View file

@ -474,10 +474,7 @@ namespace fc {
{ {
self->process_tasks(); self->process_tasks();
} }
catch ( canceled_exception& ) catch ( canceled_exception& ) { /* allowed exception */ }
{
// allowed exception...
}
catch ( ... ) catch ( ... )
{ {
elog( "fiber ${name} exited with uncaught exception: ${e}", ("e",fc::except_str())("name", self->name) ); elog( "fiber ${name} exited with uncaught exception: ${e}", ("e",fc::except_str())("name", self->name) );