[complement-svn] SF.net SVN: complement: [1420] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-11-28 19:10:50
|
Revision: 1420 http://svn.sourceforge.net/complement/?rev=1420&view=rev Author: complement Date: 2006-11-28 11:10:41 -0800 (Tue, 28 Nov 2006) Log Message: ----------- debugging; problem with global address assign Modified Paths: -------------- trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/include/stem/EventHandler.h trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Names.cc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/lib/stem/_EventHandler.cc trunk/complement/explore/test/libstem/unit/Echo.cc trunk/complement/explore/test/libstem/unit/NameService.cc trunk/complement/explore/test/libstem/unit/unit_test.cc Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/include/stem/EvManager.h 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 11:06:04 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 16:52:05 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -178,6 +178,8 @@ info_heap_type::iterator i = iheap.find( id ); if ( i != iheap.end() ) { i->second = info; + } else { + iheap[id] = info; } } @@ -185,7 +187,13 @@ { info_heap_type::iterator i = iheap.find( id ); if ( i != iheap.end() ) { - i->second = info; + if ( info != 0 ) { + i->second = info; + } else { + i->second.clear(); + } + } else if ( info != 0 ) { + iheap[id] = info; } } Modified: trunk/complement/explore/include/stem/EventHandler.h =================================================================== --- trunk/complement/explore/include/stem/EventHandler.h 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/include/stem/EventHandler.h 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 20:32:06 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 20:29:41 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -572,7 +572,7 @@ Init(); ~Init(); private: - static int _count; + static void _guard( int ); }; __FIT_DECLSPEC EventHandler(); @@ -662,7 +662,8 @@ const_h_iterator __find( state_type ) const; addr_type _id; - static EvManager *_mgr; + static class EvManager *_mgr; + static class Names *_ns; friend class Init; }; Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/lib/stem/EvManager.cc 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 12:33:34 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 21:47:34 ptr> /* * @@ -40,8 +40,11 @@ std::string EvManager::inv_key_str( "invalid key" ); -// int EvManager_flags = 0; +extern int superflag; +int superflag; +std::ostream& operator <<( std::ostream& s, const gaddr_type& ga ); + __FIT_DECLSPEC EvManager::EvManager() : _low( beglocaddr ), _high( endlocaddr ), @@ -246,8 +249,6 @@ iheap[id] = info; } - // cerr << "EvManager:: " << tr.link << " / " << hex << addr.pid << " + " << addr.addr << " - " << id << " = " << getpid() << dec << endl; - return id; } @@ -287,12 +288,23 @@ __FIT_DECLSPEC addr_type EvManager::reflect( const gaddr_type& addr ) const { + if ( stem::superflag != 0 ) { + cerr << "%%%%%\n"; + cerr << addr << endl; + cerr << dec << getpid() << endl; + } if ( addr.hid == xmt::hostid() && addr.pid == getpid() ) { // this host, this process + if ( stem::superflag != 0 ) { + cerr << "%%%%% 1\n"; + } if ( (addr.addr & extbit) == 0 ) { // looks like local object Locker _x1( _lock_heap ); local_heap_type::const_iterator l = heap.find( addr.addr ); if ( l != heap.end() ) { + if ( superflag != 0 ) { + cerr << "%%%%% 2\n"; + } return addr.addr; // l->first } } @@ -317,8 +329,14 @@ Locker _x1( _lock_xheap ); uuid_ext_heap_type::const_iterator i = _ui_heap.find( addr ); if ( i == _ui_heap.end() ) { + if ( stem::superflag != 0 ) { + cerr << "%%%%% 3\n"; + } return badaddr; } + if ( stem::superflag != 0 ) { + cerr << "%%%%% 4\n"; + } return i->second; } @@ -348,21 +366,26 @@ __FIT_DECLSPEC void EvManager::unsafe_Remove( void *channel ) { - // cerr << "Remove channel " << channel << hex << " " << getpid() << dec << endl; + if ( superflag != 0 ) { + cerr << "Remove channel" << endl; + // dump( cerr ); + cerr << "==== 1" << endl; + // abort(); + } pair<tr_uuid_heap_type::iterator,tr_uuid_heap_type::iterator> ch_range = _ch_heap.equal_range( channel ); for (tr_uuid_heap_type::iterator i = ch_range.first; i != ch_range.second; ++i ) { -#if 1 _tr_heap.erase( i->second ); addr_type address = _ui_heap[i->second]; _ex_heap.erase( address ); iheap.erase( address ); _ui_heap.erase( i->second ); -#else - cerr << i->first << "; " << hex << i->second.addr << dec << endl; - cerr << hex << _ui_heap[i->second] << dec << endl; -#endif } _ch_heap.erase( ch_range.first, ch_range.second ); + if ( superflag != 0 ) { + cerr << "==== 2" << endl; + dump( cerr ); + cerr << "==== 3" << endl; + } } __FIT_DECLSPEC const detail::transport& EvManager::transport( addr_type id ) const @@ -428,11 +451,10 @@ switch ( k ) { case detail::transport::socket_tcp: - if ( reinterpret_cast<NetTransport_base *>(link)->push( e, gaddr_dst, gaddr_src) ) { + if ( !reinterpret_cast<NetTransport_base *>(link)->push( e, gaddr_dst, gaddr_src) ) { // if I detect bad connection during writing to net // (in the push), I remove this connetion related entries. - // Required by non-Solaris OS. Unsafe variant allow avoid - // deadlock here. + // Unsafe variant allow avoid deadlock here. unsafe_Remove( link ); } break; @@ -463,8 +485,21 @@ EventHandler *object = i->second; // target object _lock_heap.unlock(); + // if ( e.src() & extbit ) { + // xmt::Locker lk( _lock_xheap ); + // + // } + try { + if ( superflag ) { + cerr << hex << e.dest() << " " << e.src() << " " << e.code() << dec << endl; + object->DispatchTrace( e, cerr ); + cerr << endl; + } object->Dispatch( e ); // call dispatcher + if ( superflag ) { + cerr << "***************" << endl; + } } catch ( ... ) { } @@ -529,7 +564,7 @@ << "-" << dec << ga.pid << "-" - << setw(8) << setfill( '0' ) << ga.addr; + << setw(8) << hex << setfill( '0' ) << ga.addr; } __FIT_DECLSPEC std::ostream& EvManager::dump( std::ostream& s ) const Modified: trunk/complement/explore/lib/stem/Names.cc =================================================================== --- trunk/complement/explore/lib/stem/Names.cc 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/lib/stem/Names.cc 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/27 18:45:00 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 17:12:45 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -77,19 +77,20 @@ void __FIT_DECLSPEC Names::ns_name( const Event& rq ) { - cerr << __FILE__ << ":" << __LINE__ << endl; typedef NameRecords<gaddr_type,string> Seq; Event_base<Seq> rs( EV_STEM_NS_NAME ); Seq::container_type& lst = rs.value().container; manager()->_lock_iheap.lock(); - for ( EvManager::info_heap_type::const_iterator i = manager()->iheap.begin(); i != manager()->iheap.end(); ++i ) { + for ( EvManager::info_heap_type::const_iterator i = manager()->iheap.begin(); i != manager()->iheap.end(); ++i ) { + cerr << hex << i->first << " => " << i->second << endl; if ( i->second == rq.value() ) { if ( /* i->first & extbit */ true ) { Locker lk( manager()->_lock_xheap ); EvManager::ext_uuid_heap_type::const_iterator j = manager()->_ex_heap.find( i->first ); if ( j != manager()->_ex_heap.end() ) { lst.push_back( make_pair( j->second, i->second ) ); + cerr << "Found\n"; } } else { Locker lk( manager()->_lock_heap ); @@ -106,8 +107,8 @@ } manager()->_lock_iheap.unlock(); - cerr << __FILE__ << ":" << __LINE__ << endl; rs.dest( rq.src() ); + cerr << "Send\n"; Send( rs ); } Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 11:40:21 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 21:17:59 ptr> /* * @@ -33,6 +33,8 @@ using namespace std; +extern int superflag; + #ifdef _BIG_ENDIAN static const uint32_t EDS_MAGIC = 0xc2454453U; #elif defined(_LITTLE_ENDIAN) @@ -96,11 +98,9 @@ __FIT_DECLSPEC void NetTransport_base::close() { - // cerr << __FILE__ << ":" << __LINE__ << endl; if ( net != 0 ) { manager()->Remove( this ); net->close(); - // cerr << __FILE__ << ":" << __LINE__ << endl; net = 0; } } @@ -154,6 +154,10 @@ str += (char)net->get(); } + // if ( superflag ) { + // cerr << __FILE__ << ":" << __LINE__ << " " << net->good() << endl; + // } + return net->good(); } @@ -256,21 +260,15 @@ gaddr_type src; if ( pop( ev, dst, src ) ) { - // cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << endl; addr_type xdst = manager()->reflect( dst ); - // cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << " " << hex << xdst << dec << endl; if ( xdst == badaddr ) { - // cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << endl; return; } - // cerr << __FILE__ << ":" << __LINE__ << endl; ev.dest( xdst ); addr_type xsrc = manager()->reflect( src ); if ( xsrc == badaddr ) { - // cerr << __FILE__ << ":" << __LINE__ << endl; ev.src( manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ) ); } else { - // cerr << __FILE__ << ":" << __LINE__ << endl; ev.src( xsrc ); } manager()->push( ev ); @@ -282,7 +280,6 @@ catch ( ... ) { s.close(); } - // cerr << "Disconnected" << endl; } // connect initiator (client) function @@ -290,16 +287,12 @@ __FIT_DECLSPEC NetTransportMgr::~NetTransportMgr() { - // cerr << __FILE__ << ":" << __LINE__ << endl; if ( net ) { - // cerr << __FILE__ << ":" << __LINE__ << endl; net->rdbuf()->shutdown( sock_base::stop_in | sock_base::stop_out ); net->close(); // otherwise _loop may not exited // this->close(); - // cerr << __FILE__ << ":" << __LINE__ << endl; join(); // NetTransport_base::close() called during loop thread termination (see _loop) - // cerr << __FILE__ << ":" << __LINE__ << endl; delete net; net = 0; } @@ -317,7 +310,13 @@ net = new sockstream( hostname, port, stype ); } else if ( net->is_open() ) { // net->close(); + if ( superflag != 0 ) { + // cerr << __FILE__ << ":" << __LINE__ << endl; + } close(); // I should wait termination of _loop, clear EDS address mapping, etc. + if ( superflag != 0 ) { + // cerr << __FILE__ << ":" << __LINE__ << endl; + } net->open( hostname, port, stype ); } else { join(); // This is safe: transparent if no _loop, and wait it if one exist @@ -358,6 +357,9 @@ catch ( runtime_error& err ) { cerr << err.what() << endl; } + catch ( ... ) { + // cerr << __FILE__ << ":" << __LINE__ << endl; + } return badaddr; } @@ -365,14 +367,14 @@ void NetTransportMgr::close() { if ( net ) { - // cerr << __FILE__ << ":" << __LINE__ << endl; + if ( superflag != 0 ) { + // cerr << __FILE__ << ":" << __LINE__ << endl; + } net->rdbuf()->shutdown( sock_base::stop_in | sock_base::stop_out ); net->close(); // otherwise _loop may not exited // this->close(); - // cerr << __FILE__ << ":" << __LINE__ << endl; join(); // NetTransport_base::close() called during loop thread termination (see _loop) - // cerr << __FILE__ << ":" << __LINE__ << endl; delete net; net = 0; } @@ -389,8 +391,17 @@ try { while ( me.pop( ev, dst, src ) ) { + if ( superflag ) { + cerr << "NetTransportMgr::_loop\n"; + manager()->dump( cerr ); + cerr << "===\n"; + // cerr << dst.hid << dst.pid << dst.addr << endl; + } addr_type xdst = manager()->reflect( dst ); if ( xdst == badaddr ) { + if ( superflag ) { + cerr << "xdst == badaddr\n"; + } continue; } ev.dest( xdst ); @@ -400,9 +411,11 @@ } else { ev.src( xsrc ); } + if ( superflag ) { + cerr << "Destination: " << hex << ev.dest() << " Source: " << ev.src() << dec << endl; + } manager()->push( ev ); } - // cerr << __FILE__ << ":" << __LINE__ << endl; me.NetTransport_base::close(); } catch ( ... ) { @@ -418,7 +431,6 @@ void NetTransportMP::connect( sockstream& s ) { Event ev; - // cerr << "Connected: " << _hostname << endl; gaddr_type dst; gaddr_type src; @@ -446,7 +458,6 @@ this->close(); // clear connection net = 0; } - // cerr << "Connected: " << _hostname << endl; } } // namespace stem Modified: trunk/complement/explore/lib/stem/_EventHandler.cc =================================================================== --- trunk/complement/explore/lib/stem/_EventHandler.cc 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/lib/stem/_EventHandler.cc 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/27 17:26:35 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 20:32:35 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -25,14 +25,10 @@ namespace stem { -char *Init_buf[32]; +char *Init_buf[128]; EvManager *EventHandler::_mgr = 0; -stem::Names *_ns = 0; -const char *_ns_name = "ns"; +Names *EventHandler::_ns = 0; -int EventHandler::Init::_count = 0; -xmt::MutexRS _init_lock; - #if 0 // depends where fork happens: in the EvManager loop (stack) or not. extern "C" void __at_fork_prepare() { @@ -51,25 +47,31 @@ } #endif -EventHandler::Init::Init() +void EventHandler::Init::_guard( int direction ) { - MT_REENTRANT_RS( _init_lock, _x ); - if ( _count++ == 0 ) { - EventHandler::_mgr = new EvManager(); - stem::_ns = new Names( ns_addr, _ns_name ); + static xmt::MutexRS _init_lock; + static int _count = 0; + + if ( direction ) { + if ( _count++ == 0 ) { + EventHandler::_mgr = new EvManager(); + EventHandler::_ns = new Names( ns_addr, "ns" ); + } + } else { + --_count; + if ( _count == 1 ) { + delete EventHandler::_ns; + } else if ( _count == 0 ) { + delete EventHandler::_mgr; + } } } +EventHandler::Init::Init() +{ _guard( 1 ); } + EventHandler::Init::~Init() -{ - MT_REENTRANT_RS( _init_lock, _x ); - --_count; - if ( _count == 1 ) { - delete stem::_ns; - } else if ( _count == 0 ) { - delete EventHandler::_mgr; - } -} +{ _guard( 0 ); } __FIT_DECLSPEC const string EventHandler::who_is( addr_type k ) const Modified: trunk/complement/explore/test/libstem/unit/Echo.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/Echo.cc 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/test/libstem/unit/Echo.cc 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 11:49:49 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 16:32:53 ptr> /* * Copyright (c) 2006 Modified: trunk/complement/explore/test/libstem/unit/NameService.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/NameService.cc 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/test/libstem/unit/NameService.cc 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 20:14:45 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 17:03:26 ptr> /* * Copyright (c) 2006 @@ -50,7 +50,8 @@ void Naming::names_name( const nsrecords_type& nr ) { - // std::cerr << hex << nr.addr << dec << endl; + std::cerr << hex << /* nr.addr */ "Naming::names_name" << dec << endl; + copy( nr.container.begin(), nr.container.end(), back_insert_iterator<nsrecords_type::container_type>(lst) ); cnd.set(true); Modified: trunk/complement/explore/test/libstem/unit/unit_test.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 11:02:56 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 17:27:34 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -339,10 +339,16 @@ // cerr << "Fine\n"; } +namespace stem { +extern int superflag; +} + void stem_test::peer() { cerr << "peer" << endl; + stem::superflag = 0; + pid_t fpid; shmid_ds ds; @@ -377,8 +383,11 @@ cerr << "1\n"; fcnd.try_wait(); + // c1.manager()->dump( cerr ); stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server - // It done like it should on client side + // It done like it should on client side + // cerr << "===========" << endl; + // c1.manager()->dump( cerr ); BOOST_CHECK( zero != stem::badaddr ); BOOST_CHECK( zero != 0 ); @@ -400,7 +409,7 @@ BOOST_CHECK( c1.manager()->reflect( ga ) != stem::badaddr ); - c1.manager()->dump( cerr ); + // c1.manager()->dump( cerr ); stem::Event evname( EV_STEM_GET_NS_NAME ); evname.dest( c1.manager()->reflect( ga ) ); @@ -409,12 +418,18 @@ pcnd.try_wait(); cerr << "@1\n"; - nm.Send( evname ); - nm.wait(); - cerr << "@2\n"; - Naming::nsrecords_type::const_iterator i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( equal_to<string>(), string( "c2@here" ) ), select2nd<pair<stem::gaddr_type,string> >() ) ); + Naming::nsrecords_type::const_iterator i; + stem::superflag = 1; + do { + nm.reset(); + nm.lst.clear(); + nm.Send( evname ); + nm.wait(); + i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( equal_to<string>(), string( "c2@here" ) ), select2nd<pair<stem::gaddr_type,string> >() ) ); + } while ( i == nm.lst.end() ); + BOOST_CHECK( i != nm.lst.end() ); BOOST_CHECK( i->second == "c2@here" ); @@ -455,6 +470,7 @@ pcnd.set( true ); scnd.try_wait(); + cerr << "2.2\n"; exit( 0 ); } catch ( xmt::fork_in_parent& child ) { @@ -470,8 +486,10 @@ waitpid( child.pid(), &stat, 0 ); waitpid( fpid, &stat, 0 ); + cerr << "3.1\n"; + srv.close(); - srv.wait(); + srv.wait(); } (&fcnd)->~__Condition<true>(); @@ -621,7 +639,7 @@ add( ns_tc ); add( echo_tc ); - add( echo_net_tc ); + // add( echo_net_tc ); add( peer_tc ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |