[complement-svn] SF.net SVN: complement: [1680] trunk/complement/explore/test/virtual_time
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-08-16 18:44:30
|
Revision: 1680 http://complement.svn.sourceforge.net/complement/?rev=1680&view=rev Author: complement Date: 2007-08-16 11:44:28 -0700 (Thu, 16 Aug 2007) Log Message: ----------- road to interprocess virtual synchrony Modified Paths: -------------- trunk/complement/explore/test/virtual_time/test/Makefile.inc trunk/complement/explore/test/virtual_time/test/unit_test.cc trunk/complement/explore/test/virtual_time/test/vt_operations.h trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Added Paths: ----------- trunk/complement/explore/test/virtual_time/test/vt_remote.cc Modified: trunk/complement/explore/test/virtual_time/test/Makefile.inc =================================================================== --- trunk/complement/explore/test/virtual_time/test/Makefile.inc 2007-08-13 15:52:01 UTC (rev 1679) +++ trunk/complement/explore/test/virtual_time/test/Makefile.inc 2007-08-16 18:44:28 UTC (rev 1680) @@ -8,4 +8,5 @@ VTmess_core.cc \ vt_object.cc \ vt_dispatch.cc \ - vt_handler.cc + vt_handler.cc \ + vt_remote Modified: trunk/complement/explore/test/virtual_time/test/unit_test.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-08-13 15:52:01 UTC (rev 1679) +++ trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-08-16 18:44:28 UTC (rev 1680) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/11 01:19:11 ptr> +// -*- C++ -*- Time-stamp: <07/08/16 09:04:40 ptr> #include "vt_operations.h" @@ -20,15 +20,16 @@ t.add( &vtime_operations::VTMess_core, vt_oper, "VTmess core transfer", tc[2] = t.add( &vtime_operations::gvt_add, vt_oper, "Group VT add", tc[1] ) ); - t.add( &vtime_operations::VTEntryIntoGroup3, vt_oper, "VTEntryIntoGroup3", - t.add( &vtime_operations::VTEntryIntoGroup2, vt_oper, "VTEntryIntoGroup2", - t.add( &vtime_operations::VTEntryIntoGroup, vt_oper, "VTEntryIntoGroup", - t.add( &vtime_operations::VTSubscription, vt_oper, "VTSubscription", - t.add( &vtime_operations::VTDispatch2, vt_oper, "VTHandler2", - t.add( &vtime_operations::VTDispatch2, vt_oper, "VTHandler1", - t.add( &vtime_operations::VTDispatch2, vt_oper, "VTDispatch2", - t.add( &vtime_operations::VTDispatch1, vt_oper, "VTDispatch1", - t.add( &vtime_operations::vt_object, vt_oper, "VT order", tc[2] ) ) ) ) ) ) ) ) ); + t.add( &vtime_operations::remote, vt_oper, "remote", + t.add( &vtime_operations::VTEntryIntoGroup3, vt_oper, "VTEntryIntoGroup3", + t.add( &vtime_operations::VTEntryIntoGroup2, vt_oper, "VTEntryIntoGroup2", + t.add( &vtime_operations::VTEntryIntoGroup, vt_oper, "VTEntryIntoGroup", + t.add( &vtime_operations::VTSubscription, vt_oper, "VTSubscription", + t.add( &vtime_operations::VTDispatch2, vt_oper, "VTHandler2", + t.add( &vtime_operations::VTDispatch2, vt_oper, "VTHandler1", + t.add( &vtime_operations::VTDispatch2, vt_oper, "VTDispatch2", + t.add( &vtime_operations::VTDispatch1, vt_oper, "VTDispatch1", + t.add( &vtime_operations::vt_object, vt_oper, "VT order", tc[2] )))))))))); return t.girdle(); } Modified: trunk/complement/explore/test/virtual_time/test/vt_operations.h =================================================================== --- trunk/complement/explore/test/virtual_time/test/vt_operations.h 2007-08-13 15:52:01 UTC (rev 1679) +++ trunk/complement/explore/test/virtual_time/test/vt_operations.h 2007-08-16 18:44:28 UTC (rev 1680) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/11 01:18:35 ptr> +// -*- C++ -*- Time-stamp: <07/08/16 09:02:08 ptr> #ifndef __vt_operations_h #define __vt_operations_h @@ -28,6 +28,8 @@ int EXAM_DECL(VTEntryIntoGroup); int EXAM_DECL(VTEntryIntoGroup2); int EXAM_DECL(VTEntryIntoGroup3); + + int EXAM_DECL(remote); }; #endif // __vt_operations_h Added: trunk/complement/explore/test/virtual_time/test/vt_remote.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/vt_remote.cc (rev 0) +++ trunk/complement/explore/test/virtual_time/test/vt_remote.cc 2007-08-16 18:44:28 UTC (rev 1680) @@ -0,0 +1,194 @@ +// -*- C++ -*- Time-stamp: <07/08/16 10:45:48 ptr> + +#include "vt_operations.h" + +// #include <boost/lexical_cast.hpp> + +#include <iostream> +#include <vtime.h> + +#include <stem/EvManager.h> +#include <stem/NetTransport.h> +#include <sockios/sockmgr.h> +#include <sys/wait.h> + +#include <mt/xmt.h> +#include <mt/shm.h> + +using namespace std; +using namespace stem; +using namespace xmt; +using namespace vt; + +class YaRemote : + public vt::VTHandler +{ + public: + YaRemote(); + YaRemote( stem::addr_type id ); + YaRemote( stem::addr_type id, const char *info ); + ~YaRemote(); + + void handler( const stem::Event& ); + void VSNewMember( const stem::Event_base<VSsync_rq>& ); + void VSOutMember( const stem::Event_base<VSsync_rq>& ); + + void greeting(); + + void wait(); + std::string msg; + int count; + int ocount; + + void wait_greeting() + { + gr.try_wait(); + gr.set( false ); + } + + private: + xmt::condition cnd; + xmt::condition gr; + + DECLARE_RESPONSE_TABLE( YaRemote, vt::VTHandler ); +}; + +#define VS_DUMMY_MESS 0x1203 +#define VS_DUMMY_GREETING 0x1204 + +YaRemote::YaRemote() : + VTHandler(), + count(0), + ocount(0) +{ + cnd.set( false ); + gr.set( false ); + + JoinGroup( 0 ); +} + +YaRemote::YaRemote( stem::addr_type id ) : + VTHandler( id ), + count(0), + ocount(0) +{ + cnd.set( false ); + gr.set( false ); + + JoinGroup( 0 ); +} + +YaRemote::YaRemote( stem::addr_type id, const char *info ) : + VTHandler( id, info ), + count(0), + ocount(0) +{ + cnd.set( false ); + gr.set( false ); + + JoinGroup( 0 ); +} + +YaRemote::~YaRemote() +{ + // cnd.wait(); +} + +void YaRemote::handler( const stem::Event& ev ) +{ + msg = ev.value(); + + cnd.set( true ); +} + +void YaRemote::VSNewMember( const stem::Event_base<VSsync_rq>& ev ) +{ + // cerr << "Hello " << ev.src() << endl; + ++count; + + // VTNewMember_data( ev, "" ); + VTHandler::VSNewMember( ev ); + + stem::EventVoid gr_ev( VS_DUMMY_GREETING ); + gr_ev.dest( ev.src() ); + Send( gr_ev ); +} + +void YaRemote::VSOutMember( const stem::Event_base<VSsync_rq>& ev ) +{ + // cerr << "Hello" << endl; + ++ocount; +} + +void YaRemote::wait() +{ + cnd.try_wait(); + + cnd.set( false ); +} + +void YaRemote::greeting() +{ + gr.set( true ); +} + +DEFINE_RESPONSE_TABLE( YaRemote ) + EV_EDS( ST_NULL, VS_DUMMY_MESS, handler ) + EV_VOID( ST_NULL, VS_DUMMY_GREETING, greeting ) +END_RESPONSE_TABLE + +int EXAM_IMPL(vtime_operations::remote) +{ + const char fname[] = "/tmp/yanus_test.shm"; + xmt::shm_alloc<0> seg; + xmt::allocator_shm<xmt::__condition<true>,0> shm_cnd; + xmt::allocator_shm<xmt::__barrier<true>,0> shm_b; + + try { + seg.allocate( fname, 4*4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0600 ); + xmt::__barrier<true>& b = *new ( shm_b.allocate( 1 ) ) xmt::__barrier<true>(); + + try { + xmt::fork(); + + b.wait(); + + NetTransportMgr mgr; + + addr_type zero = mgr.open( "localhost", 6980 ); + + EXAM_ASYNC_CHECK( mgr.good() ); + + YaRemote obj2; + + exit(0); + } + catch ( xmt::fork_in_parent& child ) { + sockmgr_stream_MP<NetTransport> srv( 6980 ); + + EXAM_REQUIRE( srv.good() ); + + b.wait(); + + YaRemote obj1; + + int stat; + EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + + srv.close(); + srv.wait(); + } + + (&b)->~__barrier<true>(); + shm_b.deallocate( &b, 1 ); + } + catch ( const xmt::shm_bad_alloc& err ) { + EXAM_ERROR( err.what() ); + } + + seg.deallocate(); + unlink( fname ); + + return EXAM_RESULT; +} + Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-08-13 15:52:01 UTC (rev 1679) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-08-16 18:44:28 UTC (rev 1680) @@ -4,6 +4,7 @@ #include <iostream> #include <stdint.h> +#include <stem/EvManager.h> namespace vt { @@ -650,7 +651,7 @@ catch ( ... ) { } #endif // __FIT_VS_TRACE - vt.dpool.push_back( make_pair( 0, new Event_base<VTmess>(m) ) ); // 0 should be timestamp + vt.dpool.push_back( make_pair( xmt::timespec(xmt::timespec::now), new Event_base<VTmess>(m) ) ); // 0 should be timestamp } } @@ -736,9 +737,24 @@ // check local or remote? i->second.addr // if remote, forward it to foreign VTDispatcher? - check_and_send( k->second, m ); - - vt.base_advance(g->second); // store last send VT to obj + try { + /* const transport tr = */ manager()->transport( k->second.stem_addr() ); + gaddr_type ga = manager()->reflect( k->second.stem_addr() ); + if ( ga != gaddr_type() ) { + ga.addr = 2; // vtd + addr_type a = manager()->reflect( ga ); + if ( a == badaddr ) { + a = manager()->SubscribeRemote( ga, "vtd" ); + } + m.dest( a ); + Forward( m ); + vt.base_advance(g->second); // store last send VT to obj + } + } + catch ( const range_error& ) { + check_and_send( k->second, m ); + vt.base_advance(g->second); // store last send VT to obj + } } catch ( const out_of_range& err ) { try { Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-08-13 15:52:01 UTC (rev 1679) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-08-16 18:44:28 UTC (rev 1680) @@ -17,6 +17,8 @@ #include <stem/Event.h> #include <stem/EventHandler.h> +#include <mt/time.h> + namespace vt { // typedef stem::addr_type oid_type; @@ -258,7 +260,7 @@ public: // delay pool should be here - typedef std::pair<int,stem::Event_base<VTmess>*> delay_item_t; + typedef std::pair<xmt::timespec,stem::Event_base<VTmess>*> delay_item_t; typedef std::list<delay_item_t> dpool_t; dpool_t dpool; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |