[complement-svn] SF.net SVN: complement: [1555] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-03-12 18:29:17
|
Revision: 1555 http://svn.sourceforge.net/complement/?rev=1555&view=rev Author: complement Date: 2007-03-12 11:29:11 -0700 (Mon, 12 Mar 2007) Log Message: ----------- EvManager.h, EvManager.cc: trace-related locks, flags and functions moved from static to member; fix bogus bug---missed return in << operator for gaddr_type; NetTransport.cc: directly use _trflags, due to function use lock now; _EventHandler.cc: ::getpid call may give lame result after fork; use xmt::getpid; libstem: library version 4.5.0 Modified Paths: -------------- trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Makefile.inc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/lib/stem/_EventHandler.cc trunk/complement/explore/test/stem/unit_test.cc Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2007-03-12 18:26:06 UTC (rev 1554) +++ trunk/complement/explore/include/stem/EvManager.h 2007-03-12 18:29:11 UTC (rev 1555) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/08 16:38:05 ptr> +// -*- C++ -*- Time-stamp: <07/03/12 17:18:41 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -163,12 +163,12 @@ __FIT_DECLSPEC void Remove( void * ); __FIT_DECLSPEC std::ostream& dump( std::ostream& ) const; - static void settrf( unsigned f ); - static void unsettrf( unsigned f ); - static void resettrf( unsigned f ); - static void cleantrf(); - static unsigned trflags(); - static void settrs( std::ostream * ); + void settrf( unsigned f ); + void unsettrf( unsigned f ); + void resettrf( unsigned f ); + void cleantrf(); + unsigned trflags() const; + void settrs( std::ostream * ); protected: bool unsafe_is_avail( addr_type id ) const @@ -256,9 +256,9 @@ xmt::Condition _cnd_queue; static std::string inv_key_str; - static xmt::Mutex _lock_tr; - static unsigned _trflags; - static std::ostream *_trs; + xmt::Mutex _lock_tr; + unsigned _trflags; + std::ostream *_trs; friend class Names; friend class NetTransportMgr; Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2007-03-12 18:26:06 UTC (rev 1554) +++ trunk/complement/explore/lib/stem/ChangeLog 2007-03-12 18:29:11 UTC (rev 1555) @@ -1,3 +1,17 @@ +2007-03-12 Petr Ovtchenkov <pt...@is...> + + * EvManager.h, EvManager.cc: trace-related locks, flags and + functions moved from static to member; fix bogus bug---missed + return in << operator for gaddr_type; + + * NetTransport.cc: directly use _trflags, due to function use + lock now; + + * _EventHandler.cc: ::getpid call may give lame result after + fork; use xmt::getpid; + + * libstem: library version 4.5.0 + 2007-02-08 Petr Ovtchenkov <pt...@is...> * EvManager.h, EvManager.cc: use deque instead of queue; Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2007-03-12 18:26:06 UTC (rev 1554) +++ trunk/complement/explore/lib/stem/EvManager.cc 2007-03-12 18:29:11 UTC (rev 1555) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/08 16:38:41 ptr> +// -*- C++ -*- Time-stamp: <07/03/12 18:53:45 ptr> /* * @@ -41,9 +41,6 @@ const addr_type endextaddr = 0xbfffffff; std::string EvManager::inv_key_str( "invalid key" ); -xmt::Mutex EvManager::_lock_tr; -unsigned EvManager::_trflags = 0; -std::ostream *EvManager::_trs = 0; std::ostream& operator <<( std::ostream& s, const gaddr_type& ga ); @@ -54,7 +51,9 @@ _x_low( begextaddr ), _x_high( endextaddr ), _x_id( _x_low ), - _dispatch_stop( false ) + _dispatch_stop( false ), + _trflags( 0 ), + _trs( 0 ) { // #ifndef __hpux _cnd_queue.set( false ); @@ -82,22 +81,25 @@ EvManager& me = *reinterpret_cast<EvManager *>(p); xmt::Thread::ret_code rt; rt.iword = 0; + xmt::Mutex& lq = me._lock_queue; + queue_type& in_ev_queue = me.in_ev_queue; + queue_type& out_ev_queue = me.out_ev_queue; while ( me.not_finished() ) { - MT_LOCK( me._lock_queue ); - me.in_ev_queue.swap( me.out_ev_queue ); - MT_UNLOCK( me._lock_queue ); - while ( !me.out_ev_queue.empty() ) { - me.Send( me.out_ev_queue.front() ); - me.out_ev_queue.pop_front(); + lq.lock(); + in_ev_queue.swap( out_ev_queue ); + lq.unlock(); + while ( !out_ev_queue.empty() ) { + me.Send( out_ev_queue.front() ); + out_ev_queue.pop_front(); } - MT_LOCK( me._lock_queue ); - if ( me.in_ev_queue.empty() && me.not_finished() ) { + lq.lock(); + if ( in_ev_queue.empty() && me.not_finished() ) { me._cnd_queue.set( false ); - MT_UNLOCK( me._lock_queue ); + lq.unlock(); me._cnd_queue.try_wait(); } else { - MT_UNLOCK( me._lock_queue ); + lq.unlock(); } } @@ -344,22 +346,41 @@ } void EvManager::settrf( unsigned f ) -{ _trflags |= f; } +{ + Locker _x1( _lock_tr ); + _trflags |= f; +} void EvManager::unsettrf( unsigned f ) -{ _trflags &= (0xffffffff & ~f); } +{ + Locker _x1( _lock_tr ); + _trflags &= (0xffffffff & ~f); +} void EvManager::resettrf( unsigned f ) -{ _trflags = f; } +{ + Locker _x1( _lock_tr ); + _trflags = f; +} void EvManager::cleantrf() -{ _trflags = 0; } +{ + Locker _x1( _lock_tr ); + _trflags = 0; +} -unsigned EvManager::trflags() -{ return _trflags; } +unsigned EvManager::trflags() const +{ + Locker _x1( _lock_tr ); + return _trflags; +} + void EvManager::settrs( std::ostream *s ) -{ _trs = s; } +{ + Locker _x1( _lock_tr ); + _trs = s; +} // Remove references to remote objects, that was announced via 'channel' // (related, may be, with socket connection) @@ -658,6 +679,8 @@ << "-" << setw(8) << hex << setfill( '0' ) << ga.addr; s.flags( f ); + + return s; } __FIT_DECLSPEC std::ostream& EvManager::dump( std::ostream& s ) const @@ -666,29 +689,40 @@ s << "Local map:\n"; s << hex << showbase; - for ( local_heap_type::const_iterator i = heap.begin(); i != heap.end(); ++i ) { - s << i->first << "\t=> " << i->second << "\n"; + { + Locker lk( _lock_heap ); + + for ( local_heap_type::const_iterator i = heap.begin(); i != heap.end(); ++i ) { + s << i->first << "\t=> " << i->second << "\n"; + } } s << "\nInfo map:\n"; + { + Locker lk( _lock_iheap ); - for ( info_heap_type::const_iterator i = iheap.begin(); i != iheap.end(); ++i ) { - s << i->first << "\t=> '" << i->second << "'\n"; + for ( info_heap_type::const_iterator i = iheap.begin(); i != iheap.end(); ++i ) { + s << i->first << "\t=> '" << i->second << "'\n"; + } } - s << "\nExternal address map:\n"; - for ( ext_uuid_heap_type::const_iterator i = _ex_heap.begin(); i != _ex_heap.end(); ++i ) { - s << hex << showbase << i->first << "\t=> " << i->second << "\n"; - } + { + Locker lk( _lock_xheap ); - s << "\nUnique Id to transport map:\n"; - for ( uuid_tr_heap_type::const_iterator i = _tr_heap.begin(); i != _tr_heap.end(); ++i ) { - s << i->first << "\t=> " << hex << i->second.first << " " << i->second.second.link << " " << dec << i->second.second.metric << "\n"; - } + s << "\nExternal address map:\n"; + for ( ext_uuid_heap_type::const_iterator i = _ex_heap.begin(); i != _ex_heap.end(); ++i ) { + s << hex << showbase << i->first << "\t=> " << i->second << "\n"; + } - s << "\nTransport to Unique Id map:\n"; - for ( tr_uuid_heap_type::const_iterator i = _ch_heap.begin(); i != _ch_heap.end(); ++i ) { - s << i->first << "\t=> " << i->second << "\n"; + s << "\nUnique Id to transport map:\n"; + for ( uuid_tr_heap_type::const_iterator i = _tr_heap.begin(); i != _tr_heap.end(); ++i ) { + s << i->first << "\t=> " << hex << i->second.first << " " << i->second.second.link << " " << dec << i->second.second.metric << "\n"; + } + + s << "\nTransport to Unique Id map:\n"; + for ( tr_uuid_heap_type::const_iterator i = _ch_heap.begin(); i != _ch_heap.end(); ++i ) { + s << i->first << "\t=> " << i->second << "\n"; + } } s << endl; Modified: trunk/complement/explore/lib/stem/Makefile.inc =================================================================== --- trunk/complement/explore/lib/stem/Makefile.inc 2007-03-12 18:26:06 UTC (rev 1554) +++ trunk/complement/explore/lib/stem/Makefile.inc 2007-03-12 18:29:11 UTC (rev 1555) @@ -1,8 +1,8 @@ -# -*- Makefile -*- Time-stamp: <06/11/30 16:51:10 ptr> +# -*- Makefile -*- Time-stamp: <07/03/12 20:19:19 ptr> LIBNAME = stem MAJOR = 4 -MINOR = 4 +MINOR = 5 PATCH = 0 SRC_CC = _EventHandler.cc NetTransport.cc EvManager.cc EvPack.cc crc.cc \ Names.cc Cron.cc Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2007-03-12 18:26:06 UTC (rev 1554) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2007-03-12 18:29:11 UTC (rev 1555) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/13 13:38:28 ptr> +// -*- C++ -*- Time-stamp: <07/03/12 17:25:23 ptr> /* * @@ -363,7 +363,7 @@ #ifdef __FIT_STEM_TRACE try { xmt::Locker lk(manager()->_lock_tr); - if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->trflags() & EvManager::tracenet) ) { + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracenet) ) { *manager()->_trs << "Pid/ppid: " << xmt::getpid() << "/" << xmt::getppid() << "\n"; manager()->dump( *manager()->_trs ) << endl; } @@ -376,7 +376,7 @@ #ifdef __FIT_STEM_TRACE try { xmt::Locker lk(manager()->_lock_tr); - if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->trflags() & (EvManager::tracefault)) ) { + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & (EvManager::tracefault)) ) { *manager()->_trs << __FILE__ << ":" << __LINE__ << " (" << xmt::getpid() << "/" << xmt::getppid() << ") " @@ -399,7 +399,7 @@ #ifdef __FIT_STEM_TRACE try { xmt::Locker lk(manager()->_lock_tr); - if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->trflags() & (EvManager::tracenet)) ) { + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & (EvManager::tracenet)) ) { *manager()->_trs << __FILE__ << ":" << __LINE__ << endl; } } Modified: trunk/complement/explore/lib/stem/_EventHandler.cc =================================================================== --- trunk/complement/explore/lib/stem/_EventHandler.cc 2007-03-12 18:26:06 UTC (rev 1554) +++ trunk/complement/explore/lib/stem/_EventHandler.cc 2007-03-12 18:29:11 UTC (rev 1555) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/08 17:27:44 ptr> +// -*- C++ -*- Time-stamp: <07/03/12 19:36:45 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -261,7 +261,7 @@ __FIT_DECLSPEC gaddr_type EventHandler::self_glid() const { - return gaddr_type(xmt::hostid(), getpid(), _id ); + return gaddr_type(xmt::hostid(), xmt::getpid(), _id ); } } // namespace stem Modified: trunk/complement/explore/test/stem/unit_test.cc =================================================================== --- trunk/complement/explore/test/stem/unit_test.cc 2007-03-12 18:26:06 UTC (rev 1554) +++ trunk/complement/explore/test/stem/unit_test.cc 2007-03-12 18:29:11 UTC (rev 1555) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/03/09 20:43:27 ptr> +// -*- C++ -*- Time-stamp: <07/03/12 21:20:54 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -56,10 +56,9 @@ void echo(); void echo_net(); + void net_echo(); void peer(); void boring_manager(); - void net_echo(); - void net_echo2(); static xmt::Thread::ret_code thr1( void * ); static xmt::Thread::ret_code thr1new( void * ); @@ -361,7 +360,7 @@ fcnd.set( true ); int stat; - waitpid( child.pid(), &stat, 0 ); + BOOST_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); srv.close(); srv.wait(); @@ -376,6 +375,80 @@ // cerr << "Fine\n"; } +// same as echo_net(), but server in child process + +void stem_test::net_echo() +{ + try { + xmt::__Barrier<true>& b = *new ( shm_b.allocate( 1 ) ) xmt::__Barrier<true>(); + xmt::__Condition<true>& c = *new ( shm_cnd.allocate( 1 ) ) xmt::__Condition<true>(); + + c.set( false ); + + try { + xmt::fork(); + + // server part + { + std::sockmgr_stream_MP<stem::NetTransport> srv( 6995 ); + StEMecho echo( 0, "echo service"); + + // echo.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch ); + // echo.manager()->settrs( &std::cerr ); + + BOOST_REQUIRE( srv.good() ); + c.set( true ); // ok, server listen + + b.wait(); // server may go away + + srv.close(); + srv.wait(); + } + + exit( 0 ); + } + catch ( xmt::fork_in_parent& child ) { + // client part + + stem::NetTransportMgr mgr; + // mgr.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch | stem::EvManager::tracefault ); + // mgr.manager()->settrs( &std::cerr ); + + c.try_wait(); // wait server start + + stem::addr_type zero = mgr.open( "localhost", 6995 ); + + BOOST_REQUIRE( mgr.good() ); + BOOST_REQUIRE( zero != stem::badaddr ); + + EchoClient node; + stem::Event ev( NODE_EV_ECHO ); + ev.dest( zero ); + + ev.value() = node.mess; + node.Send( ev ); + + node.wait(); + + mgr.close(); + mgr.join(); + + b.wait(); // server may go away + + int stat; + BOOST_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + } + + (&c)->~__Condition<true>(); + shm_cnd.deallocate( &c, 1 ); + (&b)->~__Barrier<true>(); + shm_b.deallocate( &b, 1 ); + } + catch ( xmt::shm_bad_alloc& err ) { + BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); + } +} + extern "C" { static void dummy_signal_handler( int ) @@ -640,238 +713,6 @@ // ----------------- -#define EV_STU_MESS 0x801 -#define EV_STU_ECHO 0x802 - -class TestObj : - public stem::EventHandler -{ - public: - TestObj() - { } - - void reset() - { cnd.set( false ); } - - void wait() - { cnd.try_wait(); } - - const std::string& msg() const - { return m; } - - void mess( const stem::Event& ); - void echo( const stem::Event& ); - - private: - xmt::Condition cnd; - std::string m; - - DECLARE_RESPONSE_TABLE( TestObj, stem::EventHandler ); -}; - -void TestObj::mess( const stem::Event& ev ) -{ - // cerr << "hi!\n"; - m = ev.value(); - cnd.set( true ); -} - -void TestObj::echo( const stem::Event& ev ) -{ - m = ev.value(); - cnd.set( true ); -} - -DEFINE_RESPONSE_TABLE( TestObj ) - EV_EDS( ST_NULL, EV_STU_MESS, mess ) - EV_EDS( ST_NULL, EV_STU_ECHO, echo ) -END_RESPONSE_TABLE - -class EchoSrv : - public stem::EventHandler -{ - public: - EchoSrv(); - EchoSrv( stem::addr_type id ); - EchoSrv( stem::addr_type id, const char * ); - - void echo( const stem::Event& ); - - private: - DECLARE_RESPONSE_TABLE( EchoSrv, stem::EventHandler ); -}; - -EchoSrv::EchoSrv() -{ -} - -EchoSrv::EchoSrv( stem::addr_type id ) : - stem::EventHandler( id ) -{ -} - -EchoSrv::EchoSrv( stem::addr_type id, const char *info ) : - stem::EventHandler( id, info ) -{ -} - -// Unconditionally echo message - -void EchoSrv::echo( const stem::Event& ev ) -{ - cerr << __FILE__ << ":" << __LINE__ << endl; - ev.dest( ev.src() ); - Forward( ev ); -} - -DEFINE_RESPONSE_TABLE( EchoSrv ) - EV_EDS( ST_NULL, EV_STU_ECHO, echo ) -END_RESPONSE_TABLE - -void stem_test::net_echo() -{ - try { - xmt::__Barrier<true>& b = *new ( shm_b.allocate( 1 ) ) xmt::__Barrier<true>(); - xmt::__Condition<true>& c = *new ( shm_cnd.allocate( 1 ) ) xmt::__Condition<true>(); - - c.set( false ); - - try { - xmt::fork(); - - // server part - { - std::sockmgr_stream_MP<stem::NetTransport> srv( 6890 ); - EchoSrv echosrv( 0, "Echo service"); - - BOOST_REQUIRE( srv.good() ); - c.set( true ); // ok, server listen - - b.wait(); // server may go away - - srv.close(); - srv.wait(); - } - - exit( 0 ); - } - catch ( xmt::fork_in_parent& child ) { - // client part - - stem::NetTransportMgr client; - - c.try_wait(); // wait server start - - stem::addr_type a = client.open( "localhost", 6890 ); - - BOOST_REQUIRE( client.good() ); - BOOST_REQUIRE( a != stem::badaddr ); - - TestObj t1; - - t1.reset(); - - stem::Event ev( EV_STU_ECHO ); - ev.dest( a ); - - ev.value() = "echo"; - t1.Send( ev ); - - t1.wait(); - - BOOST_CHECK( t1.msg() == "echo" ); - - client.close(); - client.join(); - - b.wait(); // server may go away - - int stat; - BOOST_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); - } - - (&c)->~__Condition<true>(); - shm_cnd.deallocate( &c, 1 ); - (&b)->~__Barrier<true>(); - shm_b.deallocate( &b, 1 ); - } - catch ( xmt::shm_bad_alloc& err ) { - BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); - } -} - -void stem_test::net_echo2() -{ - try { - xmt::__Barrier<true>& b = *new ( shm_b.allocate( 1 ) ) xmt::__Barrier<true>(); - xmt::__Condition<true>& c = *new ( shm_cnd.allocate( 1 ) ) xmt::__Condition<true>(); - - c.set( false ); - - try { - xmt::fork(); - - // server part - { - std::sockmgr_stream_MP<stem::NetTransport> srv( 6890 ); - EchoSrv echosrv( 0, "Echo service"); - - BOOST_REQUIRE( srv.good() ); - c.set( true ); // ok, server listen - - b.wait(); // server may go away - - srv.close(); - srv.wait(); - } - - exit( 0 ); - } - catch ( xmt::fork_in_parent& child ) { - // client part - - stem::NetTransportMgr client; - - c.try_wait(); // wait server start - - stem::addr_type a = client.open( "localhost", 6890 ); - - BOOST_REQUIRE( client.good() ); - BOOST_REQUIRE( a != stem::badaddr ); - - TestObj t1; - - t1.reset(); - - stem::Event ev( EV_STU_ECHO ); - ev.dest( a ); - - ev.value() = "echo"; - t1.Send( ev ); - - t1.wait(); - - BOOST_CHECK( t1.msg() == "echo" ); - - client.close(); - client.join(); - - b.wait(); // server may go away - - int stat; - BOOST_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); - } - - (&c)->~__Condition<true>(); - shm_cnd.deallocate( &c, 1 ); - (&b)->~__Barrier<true>(); - shm_b.deallocate( &b, 1 ); - } - catch ( xmt::shm_bad_alloc& err ) { - BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); - } -} - // ----------------- struct stem_test_suite : @@ -895,10 +736,9 @@ test_case *echo_tc = BOOST_CLASS_TEST_CASE( &stem_test::echo, instance ); test_case *shm_init_tc = BOOST_CLASS_TEST_CASE( &stem_test::shm_init, instance ); test_case *echo_net_tc = BOOST_CLASS_TEST_CASE( &stem_test::echo_net, instance ); + test_case *net_echo_tc = BOOST_CLASS_TEST_CASE( &stem_test::net_echo, instance ); test_case *peer_tc = BOOST_CLASS_TEST_CASE( &stem_test::peer, instance ); test_case *boring_manager_tc = BOOST_CLASS_TEST_CASE( &stem_test::boring_manager, instance ); - test_case *net_echo_tc = BOOST_CLASS_TEST_CASE( &stem_test::net_echo, instance ); - // test_case *net_echo2_tc = BOOST_CLASS_TEST_CASE( &stem_test::net_echo2, instance ); test_case *shm_finit_tc = BOOST_CLASS_TEST_CASE( &stem_test::shm_finit, instance ); basic2_tc->depends_on( basic1_tc ); @@ -911,14 +751,12 @@ echo_tc->depends_on( basic2_tc ); echo_net_tc->depends_on( shm_init_tc ); echo_net_tc->depends_on( echo_tc ); + net_echo_tc->depends_on( shm_init_tc ); + net_echo_tc->depends_on( echo_net_tc ); peer_tc->depends_on( echo_tc ); peer_tc->depends_on( shm_init_tc ); boring_manager_tc->depends_on( peer_tc ); boring_manager_tc->depends_on( shm_init_tc ); - net_echo_tc->depends_on( shm_init_tc ); - net_echo_tc->depends_on( echo_net_tc ); - // net_echo2_tc->depends_on( shm_init_tc ); - // net_echo2_tc->depends_on( net_echo_tc ); shm_finit_tc->depends_on( shm_init_tc ); add( basic1_tc ); @@ -931,10 +769,9 @@ add( echo_tc ); add( shm_init_tc ); add( echo_net_tc ); + add( net_echo_tc ); add( peer_tc ); add( boring_manager_tc ); - add( net_echo_tc ); - // add( net_echo2_tc ); add( shm_finit_tc ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |