Thread: [complement-svn] SF.net SVN: complement: [1702] trunk/complement/explore (Page 4)
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-08-23 09:02:29
|
Revision: 1702 http://complement.svn.sourceforge.net/complement/?rev=1702&view=rev Author: complement Date: 2007-08-23 02:02:15 -0700 (Thu, 23 Aug 2007) Log Message: ----------- Janus code moved from vtime.h, vtime.cc to janus.h, janus.cc; libjanus: version 0.3.0; * vshostmgr.h, vshostmgr.cc: object for management virtual syncrony processes; * vshostmgr.h, vshostmgr.cc, janus.h, janus.cc, vtime.h, vtime.cc: procedure of entry into group with remote virtual synchrony objects; * ut/vt_remote.cc: test for interprocess virtual synchrony, entry into group. Modified Paths: -------------- trunk/complement/explore/include/janus/vtime.h trunk/complement/explore/lib/janus/ChangeLog trunk/complement/explore/lib/janus/Makefile.inc trunk/complement/explore/lib/janus/ut/Makefile.inc trunk/complement/explore/lib/janus/ut/VTmess_core.cc trunk/complement/explore/lib/janus/ut/vt_dispatch.cc trunk/complement/explore/lib/janus/ut/vt_handler.cc trunk/complement/explore/lib/janus/ut/vt_object.cc trunk/complement/explore/lib/janus/ut/vt_remote.cc trunk/complement/explore/lib/janus/vtime.cc Added Paths: ----------- trunk/complement/explore/include/janus/janus.h trunk/complement/explore/include/janus/vshostmgr.h trunk/complement/explore/lib/janus/janus.cc trunk/complement/explore/lib/janus/vshostmgr.cc Added: trunk/complement/explore/include/janus/janus.h =================================================================== --- trunk/complement/explore/include/janus/janus.h (rev 0) +++ trunk/complement/explore/include/janus/janus.h 2007-08-23 09:02:15 UTC (rev 1702) @@ -0,0 +1,160 @@ +// -*- C++ -*- Time-stamp: <07/08/23 12:36:32 ptr> + +#ifndef __janus_h +#define __janus_h + +#include <ostream> +#include <iterator> + +#include <mt/xmt.h> +#include <stem/Event.h> +#include <stem/EventHandler.h> + +#include <janus/vtime.h> + +#ifdef STLPORT +# include <unordered_map> +# include <unordered_set> +// # include <hash_map> +// # include <hash_set> +// # define __USE_STLPORT_HASH +# define __USE_STLPORT_TR1 +#else +# if defined(__GNUC__) && (__GNUC__ < 4) +# include <ext/hash_map> +# include <ext/hash_set> +# define __USE_STD_HASH +# else +# include <tr1/unordered_map> +# include <tr1/unordered_set> +# define __USE_STD_TR1 +# endif +#endif + +namespace janus { + +class Janus : + public stem::EventHandler, + public vs_base +{ + private: +#ifdef __USE_STLPORT_HASH + typedef std::hash_map<oid_type, detail::vtime_obj_rec> vt_map_type; + typedef std::hash_multimap<group_type, oid_type> gid_map_type; +#endif +#ifdef __USE_STD_HASH + typedef __gnu_cxx::hash_map<oid_type, detail::vtime_obj_rec> vt_map_type; + typedef __gnu_cxx::hash_multimap<group_type, oid_type> gid_map_type; +#endif +#if defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) + typedef std::tr1::unordered_map<oid_type, detail::vtime_obj_rec> vt_map_type; + typedef std::tr1::unordered_multimap<group_type, oid_type> gid_map_type; +#endif + + public: + typedef std::iterator_traits<gid_map_type::iterator>::difference_type difference_type; + + enum traceflags { + notrace = 0, + tracenet = 1, + tracedispatch = 2, + tracefault = 4, + tracedelayed = 8, + tracegroup = 0x10 + }; + + Janus() : + _trflags( notrace ), + _trs( 0 ), + _hostmgr( 0 ) + { } + + Janus( const char *info ) : + stem::EventHandler( info ), + _trflags( notrace ), + _trs( 0 ), + _hostmgr( 0 ) + { } + + Janus( stem::addr_type id ) : + stem::EventHandler( id ), + _trflags( notrace ), + _trs( 0 ), + _hostmgr( 0 ) + { } + + Janus( stem::addr_type id, const char *info ) : + stem::EventHandler( id, info ), + _trflags( notrace ), + _trs( 0 ), + _hostmgr( 0 ) + { } + + ~Janus(); + + void JaDispatch( const stem::Event_base<VSmess>& ); + + void VSNewMember( const stem::Event_base<VSsync_rq>& e ); + void VSNewRemoteMemberDirect( const stem::Event_base<VSsync_rq>& e ); + void VSNewRemoteMemberRevert( const stem::Event_base<VSsync_rq>& e ); + + void JaSend( const stem::Event& e, group_type ); + void Subscribe( stem::addr_type, oid_type, group_type ); + void Unsubscribe( oid_type, group_type ); + void Unsubscribe( oid_type ); + void get_gvtime( group_type, stem::addr_type, gvtime_type& ); + void set_gvtime( group_type, stem::addr_type, const gvtime_type& ); + + void settrf( unsigned f ); + void unsettrf( unsigned f ); + void resettrf( unsigned f ); + void cleantrf(); + unsigned trflags() const; + void settrs( std::ostream * ); + + void connect( const char *, int ); + void serve( int ); + size_t vs_known_processes() const; + + difference_type group_size( group_type ) const; + + private: + void check_and_send( detail::vtime_obj_rec&, const stem::Event_base<VSmess>& ); + void check_and_send_delayed( detail::vtime_obj_rec& ); + + vt_map_type vtmap; + gid_map_type grmap; + + xmt::mutex _lock_tr; + unsigned _trflags; + std::ostream *_trs; + + protected: + + class VSHostMgr *_hostmgr; + + friend class VTHandler::Init; + friend class VTHandler; + friend class VSHostMgr; + + private: + + DECLARE_RESPONSE_TABLE( Janus, stem::EventHandler ); +}; + +} // namespace janus + +#ifdef __USE_STLPORT_HASH +# undef __USE_STLPORT_HASH +#endif +#ifdef __USE_STD_HASH +# undef __USE_STD_HASH +#endif +#ifdef __USE_STLPORT_TR1 +# undef __USE_STLPORT_TR1 +#endif +#ifdef __USE_STD_TR1 +# undef __USE_STD_TR1 +#endif + +#endif // __janus_h Added: trunk/complement/explore/include/janus/vshostmgr.h =================================================================== --- trunk/complement/explore/include/janus/vshostmgr.h (rev 0) +++ trunk/complement/explore/include/janus/vshostmgr.h 2007-08-23 09:02:15 UTC (rev 1702) @@ -0,0 +1,82 @@ +// -*- C++ -*- Time-stamp: <07/08/23 12:36:32 ptr> + +#ifndef __vshostmgr_h +#define __vshostmgr_h + +#include <janus/vtime.h> + +#include <stem/NetTransport.h> +#include <stem/Event.h> +#include <sockios/sockmgr.h> + +#include <list> + +#ifdef STLPORT +# include <unordered_map> +# include <unordered_set> +// # include <hash_map> +// # include <hash_set> +// # define __USE_STLPORT_HASH +# define __USE_STLPORT_TR1 +#else +# if defined(__GNUC__) && (__GNUC__ < 4) +# include <ext/hash_map> +# include <ext/hash_set> +# define __USE_STD_HASH +# else +# include <tr1/unordered_map> +# include <tr1/unordered_set> +# define __USE_STD_TR1 +# endif +#endif + +namespace janus { + +class VSHostMgr : + public janus::VTHandler +{ + private: + // typedef std::list<stem::gaddr_type> vshost_container_t; +#ifdef __USE_STLPORT_TR1 + typedef std::tr1::unordered_set<stem::gaddr_type> vshost_container_t; +#endif + + public: + typedef vshost_container_t::size_type size_type; + + VSHostMgr(); + VSHostMgr( stem::addr_type id, const char *info = 0 ); + VSHostMgr( const char *info ); + ~VSHostMgr(); + + // void handler( const stem::Event& ); + void VSNewMember( const stem::Event_base<VSsync_rq>& ); + void VSOutMember( const stem::Event_base<VSsync_rq>& ); + void VSsync_time( const stem::Event_base<VSsync>& ev ); + + void connect( const char *, int ); + void serve( int ); + + size_type vs_known_processes() const + { + xmt::recursive_scoped_lock lk( this->_theHistory_lock ); + size_type tmp = vshost.size(); + return tmp; + } + + void Subscribe( stem::addr_type, oid_type, group_type ); + + private: + typedef std::list<stem::NetTransportMgr *> nmgr_container_t; + typedef std::list<std::sockmgr_stream_MP<stem::NetTransport> *> srv_container_t; + + vshost_container_t vshost; + nmgr_container_t _clients; + srv_container_t _servers; + + // DECLARE_RESPONSE_TABLE( VSHostMgr, janus::VTHandler ); +}; + +} // namespace janus + +#endif // __vshostmgr_h Modified: trunk/complement/explore/include/janus/vtime.h =================================================================== --- trunk/complement/explore/include/janus/vtime.h 2007-08-23 08:49:29 UTC (rev 1701) +++ trunk/complement/explore/include/janus/vtime.h 2007-08-23 09:02:15 UTC (rev 1702) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/17 21:54:39 ptr> +// -*- C++ -*- Time-stamp: <07/08/23 10:16:54 ptr> #ifndef __vtime_h #define __vtime_h @@ -332,87 +332,19 @@ } // namespace detail -class Janus : - public stem::EventHandler +struct vs_base { - public: - enum traceflags { - notrace = 0, - tracenet = 1, - tracedispatch = 2, - tracefault = 4, - tracedelayed = 8, - tracegroup = 0x10 - }; - - Janus() : - _trflags( notrace ), - _trs( 0 ) - { } - - Janus( const char *info ) : - stem::EventHandler( info ), - _trflags( notrace ), - _trs( 0 ) - { } - - Janus( stem::addr_type id ) : - stem::EventHandler( id ), - _trflags( notrace ), - _trs( 0 ) - { } - - Janus( stem::addr_type id, const char *info ) : - stem::EventHandler( id, info ), - _trflags( notrace ), - _trs( 0 ) - { } - - void JaDispatch( const stem::Event_base<VSmess>& ); - - void JaSend( const stem::Event& e, group_type ); - void Subscribe( stem::addr_type, oid_type, group_type ); - void Unsubscribe( oid_type, group_type ); - void Unsubscribe( oid_type ); - void get_gvtime( group_type, stem::addr_type, gvtime_type& ); - void set_gvtime( group_type, stem::addr_type, const gvtime_type& ); - - void settrf( unsigned f ); - void unsettrf( unsigned f ); - void resettrf( unsigned f ); - void cleantrf(); - unsigned trflags() const; - void settrs( std::ostream * ); - - private: -#ifdef __USE_STLPORT_HASH - typedef std::hash_map<oid_type, detail::vtime_obj_rec> vt_map_type; - typedef std::hash_multimap<group_type, oid_type> gid_map_type; -#endif -#ifdef __USE_STD_HASH - typedef __gnu_cxx::hash_map<oid_type, detail::vtime_obj_rec> vt_map_type; - typedef __gnu_cxx::hash_multimap<group_type, oid_type> gid_map_type; -#endif -#if defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) - typedef std::tr1::unordered_map<oid_type, detail::vtime_obj_rec> vt_map_type; - typedef std::tr1::unordered_multimap<group_type, oid_type> gid_map_type; -#endif - - void check_and_send( detail::vtime_obj_rec&, const stem::Event_base<VSmess>& ); - void check_and_send_delayed( detail::vtime_obj_rec& ); - - vt_map_type vtmap; - gid_map_type grmap; - - xmt::mutex _lock_tr; - unsigned _trflags; - std::ostream *_trs; - - DECLARE_RESPONSE_TABLE( Janus, stem::EventHandler ); + enum { + vshosts_group = 0, + first_user_group = 10 + }; }; +class Janus; + class VTHandler : - public stem::EventHandler + public stem::EventHandler, + public vs_base { private: class Init @@ -434,8 +366,8 @@ virtual ~VTHandler(); void JaSend( const stem::Event& e ); - void JoinGroup( group_type grp ) - { _vtdsp->Subscribe( self_id(), oid_type( self_id() ), grp ); } + void JoinGroup( group_type grp ); + virtual void VSNewMember( const stem::Event_base<VSsync_rq>& e ); virtual void VSOutMember( const stem::Event_base<VSsync_rq>& e ); virtual void VSsync_time( const stem::Event_base<VSsync>& ); @@ -451,19 +383,21 @@ protected: void VSNewMember_data( const stem::Event_base<VSsync_rq>&, const std::string& data ); - void get_gvtime( group_type g, gvtime_type& gvt ) - { _vtdsp->get_gvtime( g, self_id(), gvt ); } + void get_gvtime( group_type g, gvtime_type& gvt ); private: - static class Janus *_vtdsp; + static Janus *_vtdsp; + friend class Janus; DECLARE_RESPONSE_TABLE( VTHandler, stem::EventHandler ); }; -#define VS_MESS 0x300 -#define VS_NEW_MEMBER 0x301 -#define VS_OUT_MEMBER 0x302 -#define VS_SYNC_TIME 0x303 +#define VS_MESS 0x300 +#define VS_NEW_MEMBER 0x301 +#define VS_OUT_MEMBER 0x302 +#define VS_SYNC_TIME 0x303 +#define VS_NEW_REMOTE_MEMBER 0x304 +#define VS_NEW_MEMBER_RV 0x305 #ifdef __USE_STLPORT_HASH # undef __USE_STLPORT_HASH Modified: trunk/complement/explore/lib/janus/ChangeLog =================================================================== --- trunk/complement/explore/lib/janus/ChangeLog 2007-08-23 08:49:29 UTC (rev 1701) +++ trunk/complement/explore/lib/janus/ChangeLog 2007-08-23 09:02:15 UTC (rev 1702) @@ -1,3 +1,26 @@ +2007-08-23 Petr Ovtchenkov <pt...@is...> + + * janus.h, janus.cc: Janus code moved from vtime.h, vtime.cc; + + * vtime.h, vtime.cc: Janus code moved to janus.h, janus.cc; + + * ut/vt_object.cc, ut/vt_handler.cc, ut/VTmess_core.cc: idem; + + * ut/vt_dispatch.cc: idem; + + * Makefile.inc: idem; + + * libjanus: version 0.3.0; + + * vshostmgr.h, vshostmgr.cc: object for management virtual syncrony + processes; + + * vshostmgr.h, vshostmgr.cc, janus.h, janus.cc, vtime.h, vtime.cc: + procedure of entry into group with remote virtual synchrony objects; + + * ut/vt_remote.cc: test for interprocess virtual synchrony, + entry into group. + 2007-08-17 Petr Ovtchenkov <ye...@ya...> * vtime.h: use available variant of hash_map/hash_set or Modified: trunk/complement/explore/lib/janus/Makefile.inc =================================================================== --- trunk/complement/explore/lib/janus/Makefile.inc 2007-08-23 08:49:29 UTC (rev 1701) +++ trunk/complement/explore/lib/janus/Makefile.inc 2007-08-23 09:02:15 UTC (rev 1702) @@ -1,7 +1,7 @@ -# -*- makefile -*- Time-stamp: <06/10/10 15:22:33 ptr> +# -*- makefile -*- Time-stamp: <07/08/21 11:08:32 ptr> LIBNAME = janus MAJOR = 0 -MINOR = 2 +MINOR = 3 PATCH = 0 -SRC_CC = vtime.cc +SRC_CC = vtime.cc janus.cc vshostmgr.cc Added: trunk/complement/explore/lib/janus/janus.cc =================================================================== --- trunk/complement/explore/lib/janus/janus.cc (rev 0) +++ trunk/complement/explore/lib/janus/janus.cc 2007-08-23 09:02:15 UTC (rev 1702) @@ -0,0 +1,658 @@ +// -*- C++ -*- Time-stamp: <07/08/23 12:36:32 ptr> + +#include <janus/janus.h> +#include <janus/vshostmgr.h> +#include <stem/EvManager.h> + +// #include <iostream> + +namespace janus { + +using namespace std; +using namespace xmt; +using namespace stem; + +Janus::~Janus() +{ + delete _hostmgr; +} + +void Janus::settrf( unsigned f ) +{ + scoped_lock _x1( _lock_tr ); + _trflags |= f; +} + +void Janus::unsettrf( unsigned f ) +{ + scoped_lock _x1( _lock_tr ); + _trflags &= (0xffffffff & ~f); +} + +void Janus::resettrf( unsigned f ) +{ + scoped_lock _x1( _lock_tr ); + _trflags = f; +} + +void Janus::cleantrf() +{ + scoped_lock _x1( _lock_tr ); + _trflags = 0; +} + +unsigned Janus::trflags() const +{ + scoped_lock _x1( _lock_tr ); + + return _trflags; +} + +void Janus::settrs( std::ostream *s ) +{ + scoped_lock _x1( _lock_tr ); + _trs = s; +} + +void Janus::JaDispatch( const stem::Event_base<VSmess>& m ) +{ + pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = + grmap.equal_range( m.value().grp ); + + for ( ; range.first != range.second; ++range.first ) { + vt_map_type::iterator i = vtmap.find( range.first->second ); + if ( i == vtmap.end() || i->second.stem_addr() == m.src() ) { // not for nobody and not for self + continue; + } + try { + // check local or remote? i->second.addr + // if remote, forward it to foreign VTDispatcher? + // looks, like local source shouldn't be here? + check_and_send( i->second, m ); + } + catch ( const out_of_range& err ) { + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracefault) ) { + *_trs << err.what() << " " + << __FILE__ << ":" << __LINE__ << endl; + } + } + catch ( ... ) { + } + } + catch ( const domain_error& err ) { + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracefault) ) { + *_trs << err.what() << " " + << __FILE__ << ":" << __LINE__ << endl; + } + } + catch ( ... ) { + } + } + } +} + +void Janus::check_and_send( detail::vtime_obj_rec& vt, const stem::Event_base<VSmess>& m ) +{ + if ( vt.deliver( m.value() ) ) { + stem::Event ev( m.value().code ); + ev.dest(vt.stem_addr()); + ev.src(m.src()); + ev.value() = m.value().mess; +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracedispatch) ) { + *_trs << "Deliver " << m.value() << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + Forward( ev ); + check_and_send_delayed( vt ); + } else { +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracedelayed) ) { + *_trs << "Delayed " << m.value() << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + vt.dpool.push_back( make_pair( xmt::timespec(xmt::timespec::now), new Event_base<VSmess>(m) ) ); // 0 should be timestamp + } +} + +void Janus::check_and_send_delayed( detail::vtime_obj_rec& vt ) +{ + typedef detail::vtime_obj_rec::dpool_t dpool_t; + bool more; + do { + more = false; + for ( dpool_t::iterator j = vt.dpool.begin(); j != vt.dpool.end(); ) { + if ( vt.deliver_delayed( j->second->value() ) ) { + stem::Event evd( j->second->value().code ); + evd.dest(vt.stem_addr()); + evd.src(j->second->src()); + evd.value() = j->second->value().mess; +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracedispatch) ) { + *_trs << "Deliver delayed " << j->second->value() << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + Forward( evd ); + delete j->second; + vt.dpool.erase( j++ ); + more = true; + } else { +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracedispatch) ) { + *_trs << "Remain delayed " << j->second->value() + << "\nReason: "; + vt.trace_deliver( j->second->value(), *_trs ) << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + ++j; + } + } + } while ( more ); +} + +void Janus::JaSend( const stem::Event& e, group_type grp ) +{ + // This method not called from Dispatch, but work on the same level and in the same + // scope, so this lock (from stem::EventHandler) required here: + xmt::recursive_scoped_lock lk( this->_theHistory_lock ); + + const pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = + grmap.equal_range( grp ); + + for ( gid_map_type::const_iterator o = range.first; o != range.second; ++o ) { + vt_map_type::iterator i = vtmap.find( o->second ); + if ( i != vtmap.end() && i->second.stem_addr() == e.src() ) { // for self + detail::vtime_obj_rec& vt = i->second; + const oid_type& from = o->second; + stem::Event_base<VSmess> m( VS_MESS ); + m.value().src = from; // oid + m.value().code = e.code(); + m.value().mess = e.value(); + m.value().grp = grp; + // m.dest( ??? ); // local VT dispatcher? + m.src( e.src() ); + + // This is like VTDispatch, but VT stamp in every message different, + // in accordance with individual knowlage about object's VT. + + vt.next( from, grp ); // my counter + + for ( gid_map_type::const_iterator g = range.first; g != range.second; ++g ) { + vt_map_type::iterator k = vtmap.find( g->second ); + if ( k == vtmap.end() || k->second.stem_addr() == m.src() ) { // not for nobody and not for self + continue; + } + try { + vt.delta( m.value().gvt, from, g->second, grp ); + + // check local or remote? i->second.addr + // if remote, forward it to foreign VTDispatcher? + 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 = stem::janus_addr; + addr_type a = manager()->reflect( ga ); + if ( a == badaddr ) { + a = manager()->SubscribeRemote( ga, "janus" ); + } + 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 { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracefault) ) { + *_trs << err.what() << " " + << __FILE__ << ":" << __LINE__ << endl; + } + } + catch ( ... ) { + } + } + catch ( const domain_error& err ) { + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracefault) ) { + *_trs << err.what() << " " + << __FILE__ << ":" << __LINE__ << endl; + } + } + catch ( ... ) { + } + } + } + + return; + } + } + + throw domain_error( "VT object not member of group" ); // Error: not group member +} + +void Janus::Subscribe( stem::addr_type addr, oid_type oid, group_type grp ) +{ + // See comment on top of VTSend above + xmt::recursive_scoped_lock lk( this->_theHistory_lock ); + + pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = + grmap.equal_range( grp ); + + for ( ; range.first != range.second; ++range.first ) { + vt_map_type::iterator i = vtmap.find( range.first->second ); + if ( i != vtmap.end() ) { + stem::Event_base<VSsync_rq> ev( VS_NEW_MEMBER ); + ev.dest( i->second.stem_addr() ); + ev.src( addr ); + ev.value().grp = grp; + Forward( ev ); +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << " -> VS_NEW_MEMBER G" << grp << " " + << hex << showbase + << ev.src() << " -> " << ev.dest() << dec << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + } + } + + vtmap[oid].add( addr, grp ); + grmap.insert( make_pair(grp,oid) ); + + // cerr << "**** " << grp << " " << xmt::getpid() << endl; + + if ( /* (grp != vshosts_group) && */ (_hostmgr != 0) ) { + _hostmgr->Subscribe( addr, oid, grp ); + } +} + +void Janus::Unsubscribe( oid_type oid, group_type grp ) +{ + // See comment on top of VTSend above + xmt::recursive_scoped_lock lk( this->_theHistory_lock ); + + pair<gid_map_type::iterator,gid_map_type::iterator> range = + grmap.equal_range( grp ); + + vt_map_type::iterator i = vtmap.find( oid ); + while ( range.first != range.second ) { + if ( range.first->second == oid ) { + grmap.erase( range.first++ ); + } else { + vt_map_type::iterator j = vtmap.find( range.first->second ); + if ( j != vtmap.end() ) { + stem::Event_base<VSsync_rq> ev( VS_OUT_MEMBER ); + ev.dest( j->second.stem_addr() ); + ev.src( i != vtmap.end() ? i->second.stem_addr() : self_id() ); + ev.value().grp = grp; +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << " -> VS_OUT_MEMBER " + << hex << showbase + << ev.src() << " -> " << ev.dest() << dec << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + + Forward( ev ); + } + ++range.first; + } + } + + if ( i != vtmap.end() ) { + if ( i->second.rm_group( grp ) ) { // no groups more + vtmap.erase( i ); + } + } + + if ( grp != vshosts_group ) { + } +} + +void Janus::Unsubscribe( oid_type oid ) +{ + // See comment on top of JaSend above + xmt::recursive_scoped_lock lk( this->_theHistory_lock ); + + vt_map_type::iterator i = vtmap.find( oid ); + if ( i != vtmap.end() ) { + list<group_type> grp_list; + i->second.groups_list( back_inserter( grp_list ) ); + for ( list<group_type>::const_iterator grp = grp_list.begin(); grp != grp_list.end(); ++grp ) { + + pair<gid_map_type::iterator,gid_map_type::iterator> range = + grmap.equal_range( *grp ); + + while ( range.first != range.second ) { + if ( range.first->second == oid ) { + grmap.erase( range.first++ ); + } else { + vt_map_type::iterator j = vtmap.find( range.first->second ); + if ( j != vtmap.end() ) { + stem::Event_base<VSsync_rq> ev( VS_OUT_MEMBER ); + ev.dest( j->second.stem_addr() ); + ev.src( i != vtmap.end() ? i->second.stem_addr() : self_id() ); + ev.value().grp = *grp; +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << " -> VS_OUT_MEMBER " + << hex << showbase + << ev.src() << " -> " << ev.dest() << dec << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + + Forward( ev ); + } + ++range.first; + } + } + i->second.rm_group( *grp ); + } + vtmap.erase( i ); + } + + // if ( grp != vshosts_group ) { + // } +} + +void Janus::get_gvtime( group_type grp, stem::addr_type addr, gvtime_type& gvt ) +{ + // See comment on top of JaSend above + xmt::recursive_scoped_lock lk( this->_theHistory_lock ); + + pair<gid_map_type::iterator,gid_map_type::iterator> range = + grmap.equal_range( grp ); + for ( ; range.first != range.second; ++range.first ) { + vt_map_type::iterator i = vtmap.find( range.first->second ); + if ( i != vtmap.end() && i->second.stem_addr() == addr ) { + i->second.get_gvt( gvt ); + return; + } + } + + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracefault) ) { + *_trs << "virtual synchrony object not member of group" << " " << __FILE__ << ":" << __LINE__ << endl; + } + } + catch ( ... ) { + } + + throw domain_error( "virtual synchrony object not member of group" ); // Error: not group member +} + +void Janus::set_gvtime( group_type grp, stem::addr_type addr, const gvtime_type& gvt ) +{ + // See comment on top of JaSend above + xmt::recursive_scoped_lock lk( this->_theHistory_lock ); + + pair<gid_map_type::iterator,gid_map_type::iterator> range = + grmap.equal_range( grp ); + for ( ; range.first != range.second; ++range.first ) { + vt_map_type::iterator i = vtmap.find( range.first->second ); + if ( i != vtmap.end() && i->second.stem_addr() == addr ) { +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << "Set gvt G" << grp << " " << i->first + << " (" << addr << ") " << gvt << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + i->second.sync( grp, i->first, gvt ); + check_and_send_delayed( i->second ); + return; + } + } + + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracefault) ) { + *_trs << "virtual synchrony object not member of group" << " " << __FILE__ << ":" << __LINE__ << endl; + } + } + catch ( ... ) { + } + + throw domain_error( "virtual synchrony object not member of group" ); // Error: not group member +} + +void Janus::VSNewMember( const stem::Event_base<VSsync_rq>& ev ) +{ + if ( ev.value().grp == vshosts_group ) { + ev.dest( _hostmgr->self_id() ); + Forward( ev ); +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << "<-> VS_NEW_MEMBER G" << vshosts_group << " " + << hex << showbase + << ev.src() << " -> " << ev.dest() << dec << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + + gaddr_type ga = manager()->reflect( ev.src() ); + addr_type janus_addr = badaddr; + if ( ga != gaddr_type() ) { + ga.addr = stem::janus_addr; + janus_addr = manager()->reflect( ga ); + if ( janus_addr == badaddr ) { + janus_addr = manager()->SubscribeRemote( ga, "janus" ); + } + } + stem::Event_base<VSsync_rq> evr( VS_NEW_MEMBER_RV ); + evr.dest( janus_addr ); + evr.value().grp = vshosts_group; + Send( evr ); +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << " -> VS_NEW_MEMBER_RV G" << vshosts_group << " " + << hex << showbase + << evr.src() << " -> " << evr.dest() << dec << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + + } +} + +void Janus::VSNewRemoteMemberDirect( const stem::Event_base<VSsync_rq>& ev ) +{ + if ( ev.value().grp != vshosts_group ) { + group_type grp = ev.value().grp; + pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( grp ); + if ( range.first != range.second ) { // we have local? member within this group + gaddr_type oid = manager()->reflect( ev.src() ); // ???? oid == gaddr + addr_type addr = ev.src(); + gaddr_type ga = manager()->reflect( addr ); + addr_type janus_addr = badaddr; + if ( ga != gaddr_type() ) { + ga.addr = stem::janus_addr; + janus_addr = manager()->reflect( ga ); + if ( janus_addr == badaddr ) { + janus_addr = manager()->SubscribeRemote( ga, "janus" ); + } + } + for ( ; range.first != range.second; ++range.first ) { + vt_map_type::iterator i = vtmap.find( range.first->second ); + if ( i != vtmap.end() ) { + stem::Event_base<VSsync_rq> evs( VS_NEW_MEMBER ); + evs.dest( i->second.stem_addr() ); + evs.src( addr ); + evs.value().grp = grp; + Forward( evs ); +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << " -> VS_NEW_MEMBER (remote) G" << grp << " " + << hex << showbase + << evs.src() << " -> " << evs.dest() << dec << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + stem::Event_base<VSsync_rq> evr( VS_NEW_MEMBER_RV ); + evr.dest( janus_addr ); + evr.src( i->second.stem_addr() ); + evr.value().grp = grp; + Forward( evr ); +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << " -> VS_NEW_MEMBER_RV G" << grp << " " + << hex << showbase + << evr.src() << " -> " << evr.dest() << dec << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + } + } + + vtmap[oid].add( addr, grp ); + grmap.insert( make_pair(grp,oid) ); + // cerr << "**** " << grp << " " << xmt::getpid() << endl; + } + } +} + +void Janus::VSNewRemoteMemberRevert( const stem::Event_base<VSsync_rq>& ev ) +{ + if ( ev.value().grp != vshosts_group ) { + group_type grp = ev.value().grp; + pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( grp ); + if ( range.first != range.second ) { // we have local? member within this group + gaddr_type oid = manager()->reflect( ev.src() ); // ???? oid == gaddr + addr_type addr = ev.src(); + for ( ; range.first != range.second; ++range.first ) { + vt_map_type::iterator i = vtmap.find( range.first->second ); + if ( i != vtmap.end() && ((i->second.stem_addr() & stem::extbit) == 0 )) { + stem::Event_base<VSsync_rq> evs( VS_NEW_MEMBER ); + evs.dest( i->second.stem_addr() ); + evs.src( addr ); + evs.value().grp = grp; + Forward( evs ); +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << " -> VS_NEW_MEMBER (remote revert) G" << grp << " " + << hex << showbase + << evs.src() << " -> " << evs.dest() << dec << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + } + } + + vtmap[oid].add( addr, grp ); + grmap.insert( make_pair(grp,oid) ); + // cerr << "**** " << grp << " " << xmt::getpid() << endl; + } + } else { + gaddr_type oid = manager()->reflect( ev.src() ); // ???? oid == gaddr + addr_type addr = ev.src(); + + vtmap[oid].add( addr, vshosts_group ); + grmap.insert( make_pair(static_cast<group_type>(vshosts_group),oid) ); + // cerr << "**** " << vshosts_group << " " << xmt::getpid() << endl; + } +} + +void Janus::connect( const char *host, int port ) +{ + _hostmgr->connect( host, port ); +} + +void Janus::serve( int port ) +{ + _hostmgr->serve( port ); +} + +size_t Janus::vs_known_processes() const +{ + return _hostmgr->vs_known_processes(); +} + +Janus::difference_type Janus::group_size( group_type grp ) const +{ + // See comment on top of JaSend above + xmt::recursive_scoped_lock lk( this->_theHistory_lock ); + + pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( grp ); + + return distance( range.first, range.second ); +} + +DEFINE_RESPONSE_TABLE( Janus ) + EV_Event_base_T_( ST_NULL, VS_MESS, JaDispatch, VSmess ) + EV_Event_base_T_( ST_NULL, VS_NEW_MEMBER, VSNewMember, VSsync_rq ) + EV_Event_base_T_( ST_NULL, VS_NEW_REMOTE_MEMBER, VSNewRemoteMemberDirect, VSsync_rq ) + EV_Event_base_T_( ST_NULL, VS_NEW_MEMBER_RV, VSNewRemoteMemberRevert, VSsync_rq ) +END_RESPONSE_TABLE + +} // namespace janus Modified: trunk/complement/explore/lib/janus/ut/Makefile.inc =================================================================== --- trunk/complement/explore/lib/janus/ut/Makefile.inc 2007-08-23 08:49:29 UTC (rev 1701) +++ trunk/complement/explore/lib/janus/ut/Makefile.inc 2007-08-23 09:02:15 UTC (rev 1702) @@ -3,6 +3,8 @@ PRGNAME = ut_vtime SRC_CC = ../vtime.cc \ + ../janus.cc \ + ../vshostmgr.cc \ unit_test.cc \ vt_operations.cc \ VTmess_core.cc \ Modified: trunk/complement/explore/lib/janus/ut/VTmess_core.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/VTmess_core.cc 2007-08-23 08:49:29 UTC (rev 1701) +++ trunk/complement/explore/lib/janus/ut/VTmess_core.cc 2007-08-23 09:02:15 UTC (rev 1702) @@ -112,7 +112,7 @@ ev.value().gvt[0][t1] = 2; ev.value().gvt[1][t0] = 3; ev.value().gvt[1][t1] = 4; - ev.value().grp = 7; + ev.value().grp = janus::vs_base::first_user_group + 7; ev.value().mess = "data"; h.Send( ev ); @@ -125,7 +125,7 @@ EXAM_CHECK( h.gvt[0][t1] == 2 ); EXAM_CHECK( h.gvt[1][t0] == 3 ); EXAM_CHECK( h.gvt[1][t1] == 4 ); - EXAM_CHECK( h.grp == 7 ); + EXAM_CHECK( h.grp == (janus::vs_base::first_user_group + 7) ); EXAM_CHECK( h.mess == "data" ); ev.value().code = 3; @@ -141,7 +141,7 @@ EXAM_CHECK( h.gvt[0][t1] == 2 ); EXAM_CHECK( h.gvt[1][t0] == 3 ); EXAM_CHECK( h.gvt[1][t1] == 4 ); - EXAM_CHECK( h.grp == 7 ); + EXAM_CHECK( h.grp == (janus::vs_base::first_user_group + 7) ); EXAM_CHECK( h.mess == "more data" ); return EXAM_RESULT; Modified: trunk/complement/explore/lib/janus/ut/vt_dispatch.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_dispatch.cc 2007-08-23 08:49:29 UTC (rev 1701) +++ trunk/complement/explore/lib/janus/ut/vt_dispatch.cc 2007-08-23 09:02:15 UTC (rev 1702) @@ -1,9 +1,11 @@ -// -*- C++ -*- Time-stamp: <07/08/17 10:39:45 ptr> +// -*- C++ -*- Time-stamp: <07/08/21 11:09:27 ptr> #include "vt_operations.h" #include <iostream> + #include <janus/vtime.h> +#include <janus/janus.h> using namespace janus; using namespace std; @@ -79,15 +81,15 @@ const oid_type t1(1); const oid_type t2(2); - dsp.Subscribe( dummy1.self_id(), t1, 0 ); - dsp.Subscribe( dummy2.self_id(), t2, 0 ); + dsp.Subscribe( dummy1.self_id(), t1, janus::vs_base::first_user_group ); + dsp.Subscribe( dummy2.self_id(), t2, janus::vs_base::first_user_group ); stem::Event ev( VT_MESS2 ); ev.src( dummy1.self_id() ); ev.value() = "hello"; - dsp.JaSend( ev, 0 ); + dsp.JaSend( ev, janus::vs_base::first_user_group ); dummy2.wait(); @@ -107,16 +109,16 @@ const oid_type t2(2); const oid_type t3(3); - dsp.Subscribe( dummy1.self_id(), t1, 0 ); - dsp.Subscribe( dummy2.self_id(), t2, 0 ); - dsp.Subscribe( dummy3.self_id(), t3, 0 ); + dsp.Subscribe( dummy1.self_id(), t1, janus::vs_base::first_user_group ); + dsp.Subscribe( dummy2.self_id(), t2, janus::vs_base::first_user_group ); + dsp.Subscribe( dummy3.self_id(), t3, janus::vs_base::first_user_group ); stem::Event ev( VT_MESS2 ); ev.src( dummy1.self_id() ); ev.value() = "hello"; - dsp.JaSend( ev, 0 ); + dsp.JaSend( ev, janus::vs_base::first_user_group ); dummy2.wait(); dummy3.wait(); Modified: trunk/complement/explore/lib/janus/ut/vt_handler.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_handler.cc 2007-08-23 08:49:29 UTC (rev 1701) +++ trunk/complement/explore/lib/janus/ut/vt_handler.cc 2007-08-23 09:02:15 UTC (rev 1702) @@ -54,7 +54,7 @@ cnd.set( false ); gr.set( false ); - JoinGroup( 0 ); + JoinGroup( first_user_group ); } VTDummy::VTDummy( stem::addr_type id ) : @@ -65,7 +65,7 @@ cnd.set( false ); gr.set( false ); - JoinGroup( 0 ); + JoinGroup( first_user_group ); } VTDummy::VTDummy( stem::addr_type id, const char *info ) : @@ -76,7 +76,7 @@ cnd.set( false ); gr.set( false ); - JoinGroup( 0 ); + JoinGroup( first_user_group ); } VTDummy::~VTDummy() @@ -133,7 +133,7 @@ VTDummy dummy2; stem::Event ev( VS_DUMMY_MESS ); - ev.dest( 0 ); // group + ev.dest( janus::vs_base::first_user_group ); // group ev.value() = "hello"; dummy1.JaSend( ev ); @@ -153,7 +153,7 @@ VTDummy dummy3; stem::Event ev( VS_DUMMY_MESS ); - ev.dest( 0 ); // group + ev.dest( janus::vs_base::first_user_group ); // group ev.value() = "hello"; dummy1.JaSend( ev ); @@ -168,7 +168,7 @@ EXAM_CHECK( dummy1.count == 2 ); EXAM_CHECK( dummy1.msg == "" ); - ev.dest( 100 ); // not this group member + ev.dest( janus::vs_base::first_user_group + 100 ); // not this group member try { dummy1.JaSend( ev ); EXAM_ERROR( "exception expected" ); @@ -185,7 +185,7 @@ VTDummy dummy2; stem::Event ev( VS_DUMMY_MESS ); - ev.dest( 0 ); // group + ev.dest( janus::vs_base::first_user_group ); // group ev.value() = "hello"; dummy1.JaSend( ev ); @@ -226,7 +226,7 @@ VTDummy dummy1; stem::Event ev( VS_DUMMY_MESS ); - ev.dest( 0 ); // group + ev.dest( janus::vs_base::first_user_group ); // group ev.value() = "hello"; { @@ -255,7 +255,7 @@ VTDummy dummy2; stem::Event ev( VS_DUMMY_MESS ); - ev.dest( 0 ); // group + ev.dest( janus::vs_base::first_user_group ); // group ev.value() = "hello"; dummy1.JaSend( ev ); @@ -277,7 +277,7 @@ dummy3.wait_greeting(); ev.value() = "hi"; - ev.dest( 0 ); // group + ev.dest( janus::vs_base::first_user_group ); // group dummy1.JaSend( ev ); dummy2.wait(); @@ -303,7 +303,7 @@ dummy2.wait_greeting(); ev.value() = "hello"; - ev.dest( 0 ); // group + ev.dest( janus::vs_base::first_user_group ); // group dummy1.JaSend( ev ); dummy2.wait(); @@ -317,7 +317,7 @@ dummy3.wait_greeting(); ev.value() = "hi"; - ev.dest( 0 ); // group + ev.dest( janus::vs_base::first_user_group ); // group dummy1.JaSend( ev ); dummy3.wait(); @@ -334,7 +334,7 @@ dummy3.wait_greeting(); ev.value() = "more"; - ev.dest( 0 ); // group + ev.dest( janus::vs_base::first_user_group ); // group dummy1.JaSend( ev ); dummy2.wait(); Modified: trunk/complement/explore/lib/janus/ut/vt_object.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_object.cc 2007-08-23 08:49:29 UTC (rev 1701) +++ trunk/complement/explore/lib/janus/ut/vt_object.cc 2007-08-23 09:02:15 UTC (rev 1702) @@ -12,9 +12,9 @@ { detail::vtime_obj_rec ob; - const group_type gr0 = 0; - const group_type gr1 = 1; - const group_type gr2 = 2; + const group_type gr0 = janus::vs_base::first_user_group + 0; + const group_type gr1 = janus::vs_base::first_user_group + 1; + const group_type gr2 = janus::vs_base::first_user_group + 2; const oid_type obj0(0); const oid_type obj1(1); const oid_type obj2(2); Modified: trunk/complement/explore/lib/janus/ut/vt_remote.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_remote.cc 2007-08-23 08:49:29 UTC (rev 1701) +++ trunk/complement/explore/lib/janus/ut/vt_remote.cc 2007-08-23 09:02:15 UTC (rev 1702) @@ -1,30 +1,41 @@ -// -*- C++ -*- Time-stamp: <07/08/17 10:07:52 ptr> +// -*- C++ -*- Time-stamp: <07/08/23 12:43:15 ptr> #include "vt_operations.h" #include <iostream> #include <janus/vtime.h> +#include <janus/janus.h> +#include <janus/vshostmgr.h> #include <stem/EvManager.h> #include <stem/NetTransport.h> +#include <stem/Event.h> +#include <stem/EvPack.h> #include <sockios/sockmgr.h> #include <sys/wait.h> #include <mt/xmt.h> #include <mt/shm.h> +#include <mt/time.h> +#include <list> +#include <sstream> + using namespace std; using namespace stem; using namespace xmt; using namespace janus; +#define VS_DUMMY_MESS 0x1203 +#define VS_DUMMY_GREETING 0x1204 + class YaRemote : public janus::VTHandler { public: YaRemote(); - YaRemote( stem::addr_type id ); - YaRemote( stem::addr_type id, const char *info ); + YaRemote( stem::addr_type id, const char *info = 0 ); + YaRemote( const char *info ); ~YaRemote(); void handler( const stem::Event& ); @@ -51,9 +62,6 @@ DECLARE_RESPONSE_TABLE( YaRemote, janus::VTHandler ); }; -#define VS_DUMMY_MESS 0x1203 -#define VS_DUMMY_GREETING 0x1204 - YaRemote::YaRemote() : VTHandler(), count(0), @@ -61,30 +69,24 @@ { cnd.set( false ); gr.set( false ); - - JoinGroup( 0 ); } -YaRemote::YaRemote( stem::addr_type id ) : - VTHandler( id ), +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( stem::addr_type id, const char *info ) : - VTHandler( id, info ), +YaRemote::YaRemote( const char *info ) : + VTHandler( info ), count(0), ocount(0) { cnd.set( false ); gr.set( false ); - - JoinGroup( 0 ); } YaRemote::~YaRemote() @@ -101,7 +103,7 @@ void YaRemote::VSNewMember( const stem::Event_base<VSsync_rq>& ev ) { - // cerr << "Hello " << ev.src() << endl; + cerr << "Hello " << xmt::getpid() << endl; ++count; // VTNewMember_data( ev, "" ); @@ -127,7 +129,9 @@ void YaRemote::greeting() { - gr.set( true ); + if ( count > 0 ) { + gr.set( true ); + } } DEFINE_RESPONSE_TABLE( YaRemote ) @@ -137,6 +141,8 @@ int EXAM_IMPL(vtime_operations::remote) { + cerr << "============\n"; + const char fname[] = "/tmp/yanus_test.shm"; xmt::shm_alloc<0> seg; xmt::allocator_shm<xmt::__condition<true>,0> shm_cnd; @@ -151,30 +157,73 @@ b.wait(); - NetTransportMgr mgr; + { + YaRemote obj1( "obj client" ); - addr_type zero = mgr.open( "localhost", 6980 ); + // obj1.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch ); + // obj1.manager()->settrs( &std::cerr ); - EXAM_CHECK_ASYNC( mgr.good() ); + obj1.vtdispatcher()->settrf( janus::Janus::tracenet | janus::Janus::tracedispatch | janus::Janus::tracefault | janus::Janus::tracedelayed | janus::Janus::tracegroup ); + obj1.vtdispatcher()->settrs( &std::cerr ); - YaRemote obj2; + EXAM_CHECK_ASYNC( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 1 ); + obj1.vtdispatcher()->connect( "localhost", 6980 ); + + cerr << obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) << endl; + +#if 1 + while ( obj1.vtdispatcher()->vs_known_processes() < 2 ) { + xmt::Thread::yield(); + xmt::delay( xmt::timespec( 0, 1000000 ) ); + } +#else + while ( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) < 2 ) { + xmt::Thread::yield(); + xmt::delay( xmt::timespec( 0, 1000000 ) ); + } +#endif + + EXAM_CHECK_ASYNC( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 2 ); + cerr << obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) << endl; + + obj1.JoinGroup( janus::vs_base::first_user_group ); + + obj1.wait_greeting(); + + EXAM_CHECK_ASYNC( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 2 ); + + // cerr << "* " << obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) << endl; + } + exit(0); } catch ( xmt::fork_in_parent& child ) { - sockmgr_stream_MP<NetTransport> srv( 6980 ); + YaRemote obj1( "obj srv" ); - EXAM_REQUIRE( srv.good() ); + // obj1.vtdispatcher()->settrf( janus::Janus::tracenet | janus::Janus::tracedispatch | janus::Janus::tracefault | janus::Janus::tracedelayed | janus::Janus::tracegroup ); + // obj1.vtdispatcher()->settrs( &std::cerr ); + obj1.vtdispatcher()->serve( 6980 ); + + obj1.JoinGroup( janus::vs_base::first_user_group ); + b.wait(); - YaRemote obj1; + // while ( obj1.vtdispatcher()->vs_known_processes() < 2 ) { + // xmt::delay( xmt::timespec( 0, 1000000 ) ); + // } + // stem::Event ev( VS_DUMMY_MESS ); + // ev.dest( janus::vs_base::first_user_group ); // group + // ev.value() = "hello"; + + // obj1.JaSend( ev ); + + // obj1.wait_greeting(); + int stat; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); - - srv.close(); - srv.wait(); } (&b)->~__barrier<true>(); Added: trunk/complement/explore/lib/janus/vshostmgr.cc =================================================================== --- trunk/complement/explore/lib/janus/vshostmgr.cc (rev 0) +++ trunk/complement/explore/lib/janus/vshostmgr.cc 2007-08-23 09:02:15 UTC (rev 1702) @@ -0,0 +1,222 @@ +// -*- C++ -*- Time-stamp: <07/08/23 11:24:18 ptr> + +#include <janus/vshostmgr.h> + +#include <iostream> +#include <janus/vtime.h> +#include <janus/janus.h> + +#include <stem/EvManager.h> +#include <stem/NetTransport.h> +#include <stem/Event.h> +#include <stem/EvPack.h> +#include <sockios/sockmgr.h> + +#include <mt/xmt.h> + +#include <list> +#include <sstream> + +namespace janus { + +using namespace std; +using namespace stem; +using namespace xmt; +using namespace janus; + +VSHostMgr::VSHostMgr() : + VTHandler() +{ + vshost.insert( gaddr_type( stem::janus_addr ) ); + JoinGroup( vshosts_group ); +} + +VSHostMgr::VSHostMgr( stem::addr_type id, const char *info ) : + VTHandler( id, info ) +{ + vshost.insert( gaddr_type( stem::janus_addr ) ); + JoinGroup( vshosts_group ); +} + +VSHostMgr::VSHostMgr( const char *info ) : + VTHandler( info ) +{ + // vtdispatcher()->settrf( janus::Janus::tracenet | janus::Janus::tracedispatch | janus::Janus::tracefault | janus::Janus::tracedelayed | janus::Janus::tracegroup ); + + vshost.insert( gaddr_type( stem::janus_addr ) ); + JoinGroup( vshosts_group ); +} + +VSHostMgr::~VSHostMgr() +{ + while ( !_clients.empty() ) { + _clients.front()->close(); + _clients.front()->join(); + delete _clients.front(); + _clients.pop_front(); + } + while ( !_servers.empty() ) { + _servers.front()->close(); + _servers.front()->wait(); + delete _servers.front(); + _servers.pop_front(); + } +} + +void VSHostMgr::VSNewMember( const stem::Event_base<VSsync_rq>& ev ) +{ + // pack vshost, + stringstream s; + + gaddr_type ga = manager()->reflect( ev.src() ); + if ( ga != gaddr_type() ) { + ga.addr = stem::janus_addr; + } + + vshost.insert( ga ); // address of remote Janus + + stem::__pack_base::__net_pack( s, static_cast<uint32_t>(vshost.size()) ); + for ( vshost_container_t::const_iterator i = vshost.begin(); i != vshost.end(); ++i ) { + i->net_pack( s ); + } + VTHandler::VSNewMember_data( ev, s.str() ); + // VTHandler::VSNewMember( ev ); +} + +void VSHostMgr::VSOutMember( const stem::Event_base<VSsync_rq>& ev ) +{ + // remove host from vshost + gaddr_type ga = manager()->reflect( ev.src() ); + if ( ga != gaddr_type() ) { + ga.addr = stem::janus_addr; + } + + vshost_container_t::iterator i = vshost.find( ga ); + if ( i != vshost.end() ) { + vshost.erase( i ); + } +#ifdef __FIT_VS_TRACE + VTHandler::VSOutMember( ev ); +#endif +} + +void VSHostMgr::VSsync_time( const stem::Event_base<VSsync>& ev ) +{ + // extract ev.value().mess, sync with vshost + stringstream s( ev.value().mess ); + + uint32_t sz; + gaddr_type ga; + + stem::__pack_base::__net_unpack( s, sz ); + while ( sz-- > 0 ) { + ga.net_unpack( s ); + // vshost.push_back( ga ); + vshost.insert( ga ); + } + + VTHandler::VSsync_time(ev); +} + +void VSHostMgr::connect( const char *host, int port ) +{ + _clients.push_back( new NetTransportMgr() ); + + addr_type zero = _clients.back()->open( host, port ); + + gaddr_type ga = manager()->reflect( zero ); + if ( ga != gaddr_type() ) { + ga.addr = stem::janus_addr; + addr_type a = manager()->reflect( ga ); + if ( a == badaddr ) { + a = manager()->SubscribeRemote( ga, "janus" ); + } + stem::Event_base<VSsync_rq> ev( VS_NEW_MEMBER ); + ev.dest( a ); + ev.value().grp = vshosts_group; // special group + Send( ev ); +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(vtdispatcher()->_lock_tr); + if ( vtdispatcher()->_trs != 0 && vtdispatcher()->_trs->good() && (vtdispatcher()->_trflags & Janus::tracenet) ) { + *vtdispatcher()->_trs << "connect " << host << ":" << port << "\n" + << " -> VS_NEW_MEMBER G" << vshosts_group << " " + << hex << showbase + << self_id() << " -> " << ev.dest() << dec << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + } +#ifdef __FIT_VS_TRACE + else { + try { + scoped_lock lk(vtdispatcher()->_lock_tr); + if ( vtdispatcher()->_trs != 0 && vtdispatcher()->_trs->good() && (vtdispatcher()->_trflags & Janus::tracenet) ) { + *vtdispatcher()->_trs << "connect " << host << ":" << port << " fail" << endl; + } + } + catch ( ... ) { + } + } +#endif // __FIT_VS_TRACE +} + +void VSHostMgr::serve( int port ) +{ + _servers.push_back( new sockmgr_stream_MP<NetTransport>( port ) ); +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(vtdispatcher()->_lock_tr); + if ( vtdispatcher()->_trs != 0 && vtdispatcher()->_trs->good() && (vtdispatcher()->_trflags & Janus::tracenet) ) { + *vtdispatcher()->_trs << "serve " << port + << (_servers.back()->good() ? " ok" : " fail" ) + << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE +} + +void VSHostMgr::Subscribe( stem::addr_type addr, oid_type oid, group_type grp ) +{ + try { + manager()->transport( addr ); + } + catch ( const range_error& ) { + // only for local object + stem::Event_base<VSsync_rq> ev( VS_NEW_REMOTE_MEMBER ); + ev.src( addr ); + gaddr_type ga = manager()->reflect( stem::janus_addr ); + + for ( vshost_container_t::const_iterator i = vshost.begin(); i != vshost.end(); ++i ) { + if ( ga != *i ) { + ev.dest( manager()->reflect( *i ) ); + ev.value().grp = grp; + Forward( ev ); +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(vtdispatcher()->_lock_tr); + if ( vtdispatcher()->_trs != 0 && vtdispatcher()->_trs->good() && (vtdispatcher()->_trflags & Janus::tracenet) ) { + *vtdispatcher()->_trs << " -> VS_NEW_REMOTE_MEMBER G" << grp << " " + << hex << showbase + << ev.src() << " -> " << ev.dest() << dec << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + } + } + } +} + +// DEFINE_RESPONSE_TABLE( VSHostMgr ) +// EV_Event_base_T_( ST_NULL, VS_NEW_REMOTE_MEMBER, VSNewRemoteMemberDirect, VSsync_rq ) +// EV_Event_base_T_( ST_NULL, VS_NEW_MEMBER_RV, VSNewRemoteMemberRevert, VSsync_rq ) +// END_RESPONSE_TABLE + + +} // namespace janus Modified: trunk/complement/explore/lib/janus/vtime.cc =================================================================== --- trunk/complement/explore/lib/janus/vtime.cc 2007-08-23 08:49:29 UTC (rev 1701) +++ trunk/complement/explore/lib/janus/vtime.cc 2007-08-23 09:02:15 UTC (rev 1702) @@ -1,10 +1,10 @@ -// -*- C++ -*- Time-stamp: <07/08/17 22:28:55 ptr> +// -*- C++ -*- Time-stamp: <07/08/23 08:47:46 ptr> #include <janus/vtime.h> +#include <janus/janus.h> +#include <janus/vshostmgr.h> -#include <iostream> #include <stdint.h> -#include <stem/EvManager.h> namespace janus { @@ -543,442 +543,7 @@ } // namespace detail -void Janus::settrf( unsigned f ) -{ - scoped_lock _x1( _lock_tr ); - _trflags |= f; -} -void Janus::unsettrf( unsigned f ) -{ - scoped_lock _x1( _lock_tr ); - _trflags &= (0xffffffff & ~f); -} - -void Janus::resettrf( unsigned f ) -{ - scoped_lock _x1( _lock_tr ); - _trflags = f; -} - -void Janus::cleantrf() -{ - scoped_lock _x1( _lock_tr ); - _trflags = 0; -} - -unsigned Janus::trflags() const -{ - scoped_lock _x1( _lock_tr ); - - return _trflags; -} - -void Janus::settrs( std::ostream *s ) -{ - scoped_lock _x1( _lock_tr ); - _trs = s; -} - -void Janus::JaDispatch( const stem::Event_base<VSmess>& m ) -{ - pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = - grmap.equal_range( m.value().grp ); - - for ( ; range.first != range.second; ++range.first ) { - vt_map_type::iterator i = vtmap.find( range.first->second ); - if ( i == vtmap.end() || i->second.stem_addr() == m.src() ) { // not for nobody and not for self - continue; - } - try { - // check local or remote? i->second.addr - // if remote, forward it to foreign VTDispatcher? - // looks, like local source shouldn't be here? - check_and_send( i->second, m ); - } - catch ( const out_of_range& err ) { - try { - scoped_lock lk(_lock_tr); - if ( _trs != 0 && _trs->good() && (_trflags & tracefault) ) { - *_trs << err.what() << " " - << __FILE__ << ":" << __LINE__ << endl; - } - } - catch ( ... ) { - } - } - catch ( const domain_error& err ) { - try { - scoped_lock lk(_lock_tr); - if ( _trs != 0 && _trs->good() && (_trflags & tracefault) ) { - *_trs << err.what() << " " - << __FILE__ << ":" << __LINE__ << endl; - } - } - catch ( ... ) { - } - } - } -} - -void Janus::check_and_send( detail::vtime_obj_rec& vt, const stem::Event_base<VSmess>& m ) -{ - if ( vt.deliver( m.value() ) ) { - stem::Event ev( m.value().code ); - ev.dest(vt.stem_addr()); - ev.src(m.src()); - ev.value() = m.value().mess; -#ifdef __FIT_VS_TRACE - try { - scoped_lock lk(_lock_tr); - if ( _trs != 0 && _trs->good() && (_trflags & tracedispatch) ) { - *_trs << "Deliver " << m.value() << endl; - } - } - catch ( ... ) { - } -#endif // __FIT_VS_TRACE - Forward( ev ); - check_and_send_delayed( vt ); - } else { -#ifdef __FIT_VS_TRACE - try { - scoped_lock lk(_lock_tr); - if ( _trs != 0 && _trs->good() && (_trflags & tracedelayed) ) { - *_trs << "Delayed " << m.value() << endl; - } - } - catch ( ... ) { - } -#endif // __FIT_VS_TRACE - vt.dpool.push_back( make_pair( xmt::timespec(xmt::timespec::now), new Event_base<VSmess>(m) ) ); // 0 should be timestamp - } -} - -void Janus::check_and_send_delayed( detail::vtime_obj_rec& vt ) -{ - typedef detail::vtime_obj_rec::dpool_t dpool_t; - bool more; - do { - more = false; - for ( dpool_t::iterator j = vt.dpool.begin(); j != vt.dpool.end(); ) { - if ( vt.deliver_delayed( j->second->value() ) ) { - stem::Event evd( j->second->value().code ); - evd.dest(vt.stem_addr()); - evd.src(j->second->src()); - evd.value() = j->second->value().mess; -#ifdef __FIT_VS_TRACE - try { - scoped_lock lk(_lock_tr); - if ( _trs != 0 && _trs->good() && (_trflags & tracedispatch) ) { - *_trs << "Deliver delayed " << j->second->value() << endl; - } - } - catch ( ... ) { - } -#endif // __FIT_VS_TRACE - Forward( evd ); - delete j->second; - vt.dpool.erase( j++ ); - more = true; - } else { -#ifdef __FIT_VS_TRACE - try { - scoped_lock lk(_lock_tr); - if ( _trs != 0 && _trs->good() && (_trflags & tracedispatch) ) { - *_trs << "Remain delayed " << j->second->value() - << "\nReason: "; - vt.trace_deliver( j->second->value(), *_trs ) << endl; - } - } - catch ( ... ) { - } -#endif // __FIT_VS_TRACE - ++j; - } - } - } while ( more ); -} - -void Janus::JaSend( const stem::Event& e, group_type grp ) -{ - // This method not called from Dispatch, but work on the same level and in the same - // scope, so this lock (from stem::EventHandler) required here: - xmt::recursive_scoped_lock lk( this->_theHistory_lock ); - - const pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = - grmap.equal_range( grp ); - - for ( gid_map_type::const_iterator o = range.first; o != range.second; ++o ) { - vt_map_type::iterator i = vtmap.find( o->second ); - if ( i != vtmap.end() && i->second.stem_addr() == e.src() ) { // for self - detail::vtime_obj_rec& vt = i->second; - const oid_type& from = o->second; - stem::Event_base<VSmess> m( VS_MESS ); - m.value().src = from; // oid - m.value().code = e.code(); - m.value().mess = e.value(); - m.value().grp = grp; - // m.dest( ??? ); // local VT dispatcher? - m.src( e.src() ); - - // This is like VTDispatch, but VT stamp in every message different, - // in accordance with individual knowlage about object's VT. - - vt.next( from, grp ); // my counter - - for ( gid_map_type::const_iterator g = range.first; g != range.second; ++g ) { - vt_map_type::iterator k = vtmap.find( g->second ); - if ( k == vtmap.end() || k->second.stem_addr() == m.src() ) { // not for nobody and not for self - continue; - } - try { - vt.delta( m.value().gvt, from, g->second, grp ); - - ... [truncated message content] |
From: <com...@us...> - 2007-08-26 12:07:52
|
Revision: 1705 http://complement.svn.sourceforge.net/complement/?rev=1705&view=rev Author: complement Date: 2007-08-24 22:59:33 -0700 (Fri, 24 Aug 2007) Log Message: ----------- use ostream and trace flags from EvManager for error reports instead of cerr; library version 4.6.3 Modified Paths: -------------- trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/Makefile.inc trunk/complement/explore/lib/stem/NetTransport.cc Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2007-08-23 17:34:23 UTC (rev 1704) +++ trunk/complement/explore/include/stem/EvManager.h 2007-08-25 05:59:33 UTC (rev 1705) @@ -262,6 +262,8 @@ friend class Names; friend class NetTransportMgr; + friend class NetTransport_base; + friend class NetTransport; }; } // namespace stem Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2007-08-23 17:34:23 UTC (rev 1704) +++ trunk/complement/explore/lib/stem/ChangeLog 2007-08-25 05:59:33 UTC (rev 1705) @@ -1,3 +1,10 @@ +2007-08-25 Petr Ovtchenkov <pt...@is...> + + * EvManager.h, NetTransport.cc: use ostream and trace flags + from EvManager for error reports instead of cerr; + + * libstem: library version 4.6.3 + 2007-08-23 Petr Ovtchenkov <pt...@is...> * NetTransport.h: inhibit copy of NetTransportMgr explicitly; Modified: trunk/complement/explore/lib/stem/Makefile.inc =================================================================== --- trunk/complement/explore/lib/stem/Makefile.inc 2007-08-23 17:34:23 UTC (rev 1704) +++ trunk/complement/explore/lib/stem/Makefile.inc 2007-08-25 05:59:33 UTC (rev 1705) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <07/07/12 00:52:43 ptr> +# -*- Makefile -*- Time-stamp: <07/08/25 09:58:31 ptr> LIBNAME = stem MAJOR = 4 MINOR = 6 -PATCH = 2 +PATCH = 3 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-08-23 17:34:23 UTC (rev 1704) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2007-08-25 05:59:33 UTC (rev 1705) @@ -2,7 +2,7 @@ /* * - * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 + * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 * Petr Ovtchenkov * * Copyright (c) 1999-2001 @@ -115,7 +115,17 @@ } if ( buf[0] != EDS_MAGIC ) { - cerr << "EDS Magic fail" << endl; + try { + xmt::scoped_lock lk(manager()->_lock_tr); + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracefault) ) { + *manager()->_trs << __FILE__ << ":" << __LINE__ << " StEM Magic fail (" + << net->rdbuf()->inet_addr() << ":" << net->rdbuf()->port() << ")" + << endl; + } + } + catch ( ... ) { + } + NetTransport_base::close(); return false; } @@ -131,14 +141,33 @@ uint32_t sz = from_net( buf[18] ); if ( sz >= EDS_MSG_LIMIT ) { - cerr << "EDS Message size too big: " << sz << endl; + try { + xmt::scoped_lock lk(manager()->_lock_tr); + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracefault) ) { + *manager()->_trs << __FILE__ << ":" << __LINE__ << " StEM Message size too big: " << sz + << " (" << net->rdbuf()->inet_addr() << ":" << net->rdbuf()->port() + << ")" << endl; + } + } + catch ( ... ) { + } NetTransport_base::close(); return false; } adler32_type adler = adler32( (unsigned char *)buf, sizeof(uint32_t) * 19 ); if ( adler != from_net( buf[19] ) ) { - cerr << "EDS Adler-32 fail" << endl; + try { + xmt::scoped_lock lk(manager()->_lock_tr); + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracefault) ) { + *manager()->_trs << __FILE__ << ":" << __LINE__ << " StEM Adler-32 fail" + << " (" << net->rdbuf()->inet_addr() << ":" << net->rdbuf()->port() + << ")" << endl; + } + } + catch ( ... ) { + } + NetTransport_base::close(); return false; } @@ -169,7 +198,6 @@ dst._xnet_pack( reinterpret_cast<char *>(buf + 2) ); src._xnet_pack( reinterpret_cast<char *>(buf + 9) ); - // MT_IO_REENTRANT_W( *net ) MT_IO_LOCK_W( *net ) buf[16] = to_net( ++_count ); @@ -237,10 +265,31 @@ } } catch ( runtime_error& err ) { + try { + xmt::scoped_lock lk(manager()->_lock_tr); + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracefault) ) { + *manager()->_trs << __FILE__ << ":" << __LINE__ << " " << err.what() + << " (" << s.rdbuf()->inet_addr() << ":" << s.rdbuf()->port() + << ")" << endl; + } + } + catch ( ... ) { + } + s.close(); - cerr << err.what() << endl; } catch ( ... ) { + try { + xmt::scoped_lock lk(manager()->_lock_tr); + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracefault) ) { + *manager()->_trs << __FILE__ << ":" << __LINE__ << " unknown exception" + << " (" << s.rdbuf()->inet_addr() << ":" << s.rdbuf()->port() + << ")" << endl; + } + } + catch ( ... ) { + } + s.close(); } } @@ -269,9 +318,29 @@ } } catch ( ios_base::failure& ex ) { - cerr << ex.what() << endl; + try { + xmt::scoped_lock lk(manager()->_lock_tr); + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracefault) ) { + *manager()->_trs << __FILE__ << ":" << __LINE__ << " " << ex.what() + << " (" << s.rdbuf()->inet_addr() << ":" << s.rdbuf()->port() + << ")" << endl; + } + } + catch ( ... ) { + } } catch ( ... ) { + try { + xmt::scoped_lock lk(manager()->_lock_tr); + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracefault) ) { + *manager()->_trs << __FILE__ << ":" << __LINE__ << " unknown exception" + << " (" << s.rdbuf()->inet_addr() << ":" << s.rdbuf()->port() + << ")" << endl; + } + } + catch ( ... ) { + } + s.close(); } } @@ -332,10 +401,28 @@ } } catch ( runtime_error& err ) { - cerr << err.what() << endl; + try { + xmt::scoped_lock lk(manager()->_lock_tr); + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracefault) ) { + *manager()->_trs << __FILE__ << ":" << __LINE__ << " " << err.what() + << " (" << _channel.rdbuf()->inet_addr() << ":" << _channel.rdbuf()->port() + << ")" << endl; + } + } + catch ( ... ) { + } } catch ( ... ) { - // cerr << __FILE__ << ":" << __LINE__ << endl; + try { + xmt::scoped_lock lk(manager()->_lock_tr); + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracefault) ) { + *manager()->_trs << __FILE__ << ":" << __LINE__ << " unknown exception" + << " (" << _channel.rdbuf()->inet_addr() << ":" << _channel.rdbuf()->port() + << ")" << endl; + } + } + catch ( ... ) { + } } return badaddr; } @@ -344,6 +431,7 @@ void NetTransportMgr::close() { _channel.rdbuf()->shutdown( sock_base::stop_in | sock_base::stop_out ); + // _channel.rdbuf()->shutdown( sock_base::stop_in ); NetTransport_base::close(); // _channel.close(); join(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-08-27 15:11:00
|
Revision: 1706 http://complement.svn.sourceforge.net/complement/?rev=1706&view=rev Author: complement Date: 2007-08-27 08:10:53 -0700 (Mon, 27 Aug 2007) Log Message: ----------- use namespace std for max Modified Paths: -------------- trunk/complement/explore/include/mt/shm.h trunk/complement/explore/lib/mt/ChangeLog Modified: trunk/complement/explore/include/mt/shm.h =================================================================== --- trunk/complement/explore/include/mt/shm.h 2007-08-25 05:59:33 UTC (rev 1705) +++ trunk/complement/explore/include/mt/shm.h 2007-08-27 15:10:53 UTC (rev 1706) @@ -536,7 +536,7 @@ template <int _Inst> void shm_alloc<_Inst>::deallocate( pointer p, size_type n ) { - n = max( n + (__align - n % __align) % __align, sizeof(_fheader) ); + n = std::max( n + (__align - n % __align) % __align, sizeof(_fheader) ); _master *m = reinterpret_cast<_master *>( _seg.address() ); if ( m != reinterpret_cast<_master *>(-1) && (reinterpret_cast<char *>(p) - reinterpret_cast<char *>(_seg.address())) < (_seg.max_size() + sizeof(_master) + sizeof(_aheader) ) ) { xmt::basic_lock<xmt::__mutex<false,true> > lk( m->_lock ); @@ -597,7 +597,7 @@ template <int _Inst> void *shm_alloc<_Inst>::_traverse( size_type *_prev, size_type n ) { - n = max( n + (__align - n % __align) % __align, sizeof(_fheader) ); + n = std::max( n + (__align - n % __align) % __align, sizeof(_fheader) ); for ( _fheader *h = reinterpret_cast<_fheader *>(reinterpret_cast<char *>(_seg.address()) + *_prev); *_prev != 0; _prev = &h->_next, h = reinterpret_cast<_fheader *>(reinterpret_cast<char *>(_seg.address()) + *_prev)) { if ( h->_sz >= (n + sizeof( _fheader )) ) { // reduce this free block, write new free header Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-08-25 05:59:33 UTC (rev 1705) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-08-27 15:10:53 UTC (rev 1706) @@ -1,3 +1,7 @@ +2007-08-27 Petr Ovtchenkov <pt...@is...> + + * shm.h: use namespace std for max. + 2007-08-03 Petr Ovtchenkov <pt...@is...> * test/mt/Makefile: let's try don't include boost's -I if macro This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-08-27 15:32:41
|
Revision: 1707 http://complement.svn.sourceforge.net/complement/?rev=1707&view=rev Author: complement Date: 2007-08-27 08:32:34 -0700 (Mon, 27 Aug 2007) Log Message: ----------- janus.h, janus.cc: hide methods, intended for internal protocol usage only; vtime.h, vtime.cc: LeaveGroup added; vshostmgr.h, vshostmgr.cc: trick with finalizer---event after that message queue free from VS_OUT_MEMBER events; ut/unit_test.cc, ut/vt_object.cc, ut/vt_handler.cc, ut/VTmess_core.cc, ut/vt_operations.cc, ut/vt_operations.h, ut/vt_dispatch.cc, ut/vt_remote.cc: move test suite to janus namespace; ut/unit_test.cc, ut/vt_remote.cc: test two groups and interprocess virtual synchrony; Modified Paths: -------------- trunk/complement/explore/include/janus/janus.h trunk/complement/explore/include/janus/vshostmgr.h trunk/complement/explore/include/janus/vtime.h trunk/complement/explore/lib/janus/ChangeLog trunk/complement/explore/lib/janus/janus.cc trunk/complement/explore/lib/janus/ut/VTmess_core.cc trunk/complement/explore/lib/janus/ut/unit_test.cc trunk/complement/explore/lib/janus/ut/vt_dispatch.cc trunk/complement/explore/lib/janus/ut/vt_handler.cc trunk/complement/explore/lib/janus/ut/vt_object.cc trunk/complement/explore/lib/janus/ut/vt_operations.cc trunk/complement/explore/lib/janus/ut/vt_operations.h trunk/complement/explore/lib/janus/ut/vt_remote.cc trunk/complement/explore/lib/janus/vshostmgr.cc trunk/complement/explore/lib/janus/vtime.cc Modified: trunk/complement/explore/include/janus/janus.h =================================================================== --- trunk/complement/explore/include/janus/janus.h 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/include/janus/janus.h 2007-08-27 15:32:34 UTC (rev 1707) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/23 12:36:32 ptr> +// -*- C++ -*- Time-stamp: <07/08/25 01:40:20 ptr> #ifndef __janus_h #define __janus_h @@ -41,14 +41,17 @@ #ifdef __USE_STLPORT_HASH typedef std::hash_map<oid_type, detail::vtime_obj_rec> vt_map_type; typedef std::hash_multimap<group_type, oid_type> gid_map_type; + typedef std::hash_set<stem::addr_type> addr_cache_t; #endif #ifdef __USE_STD_HASH typedef __gnu_cxx::hash_map<oid_type, detail::vtime_obj_rec> vt_map_type; typedef __gnu_cxx::hash_multimap<group_type, oid_type> gid_map_type; + typedef __gnu_cxx::hash_set<stem::addr_type> addr_cache_t; #endif #if defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) typedef std::tr1::unordered_map<oid_type, detail::vtime_obj_rec> vt_map_type; typedef std::tr1::unordered_multimap<group_type, oid_type> gid_map_type; + typedef std::tr1::unordered_set<stem::addr_type> addr_cache_t; #endif public: @@ -92,18 +95,7 @@ ~Janus(); - void JaDispatch( const stem::Event_base<VSmess>& ); - - void VSNewMember( const stem::Event_base<VSsync_rq>& e ); - void VSNewRemoteMemberDirect( const stem::Event_base<VSsync_rq>& e ); - void VSNewRemoteMemberRevert( const stem::Event_base<VSsync_rq>& e ); - void JaSend( const stem::Event& e, group_type ); - void Subscribe( stem::addr_type, oid_type, group_type ); - void Unsubscribe( oid_type, group_type ); - void Unsubscribe( oid_type ); - void get_gvtime( group_type, stem::addr_type, gvtime_type& ); - void set_gvtime( group_type, stem::addr_type, const gvtime_type& ); void settrf( unsigned f ); void unsettrf( unsigned f ); @@ -119,6 +111,12 @@ difference_type group_size( group_type ) const; private: + void Subscribe( stem::addr_type, const oid_type&, group_type ); + void Unsubscribe( const oid_type&, group_type ); + void Unsubscribe( const oid_type& ); + + void get_gvtime( group_type, stem::addr_type, gvtime_type& ); + void set_gvtime( group_type, stem::addr_type, const gvtime_type& ); void check_and_send( detail::vtime_obj_rec&, const stem::Event_base<VSmess>& ); void check_and_send_delayed( detail::vtime_obj_rec& ); @@ -137,8 +135,18 @@ friend class VTHandler; friend class VSHostMgr; +#ifdef __FIT_EXAM + friend class vtime_operations; +#endif + private: + void JaDispatch( const stem::Event_base<VSmess>& ); + void VSNewMember( const stem::Event_base<VSsync_rq>& e ); + void VSNewRemoteMemberDirect( const stem::Event_base<VSsync_rq>& e ); + void VSNewRemoteMemberRevert( const stem::Event_base<VSsync_rq>& e ); + void VSOutMember( const stem::Event_base<VSsync_rq>& e ); + DECLARE_RESPONSE_TABLE( Janus, stem::EventHandler ); }; Modified: trunk/complement/explore/include/janus/vshostmgr.h =================================================================== --- trunk/complement/explore/include/janus/vshostmgr.h 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/include/janus/vshostmgr.h 2007-08-27 15:32:34 UTC (rev 1707) @@ -37,9 +37,15 @@ { private: // typedef std::list<stem::gaddr_type> vshost_container_t; -#ifdef __USE_STLPORT_TR1 +#if defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) typedef std::tr1::unordered_set<stem::gaddr_type> vshost_container_t; #endif +#ifdef __USE_STD_HASH + typedef __gnu_cxx::hash_set<stem::gaddr_type> vshost_container_t; +#endif +#ifdef __USE_STLPORT_HASH + typedef std::hash_set<stem::gaddr_type> vshost_container_t; +#endif public: typedef vshost_container_t::size_type size_type; @@ -64,7 +70,7 @@ return tmp; } - void Subscribe( stem::addr_type, oid_type, group_type ); + void Subscribe( stem::addr_type, group_type ); private: typedef std::list<stem::NetTransportMgr *> nmgr_container_t; @@ -74,6 +80,28 @@ nmgr_container_t _clients; srv_container_t _servers; + class Finalizer : + public stem::EventHandler + { + public: + Finalizer( const char *info ) : + EventHandler( info ) + { cnd.set( false ); } + + void wait() + { cnd.try_wait(); } + + private: + void final() + { cnd.set( true ); } + + xmt::condition cnd; + + DECLARE_RESPONSE_TABLE( Finalizer, stem::EventHandler ); + }; + + Finalizer finalizer; + // DECLARE_RESPONSE_TABLE( VSHostMgr, janus::VTHandler ); }; Modified: trunk/complement/explore/include/janus/vtime.h =================================================================== --- trunk/complement/explore/include/janus/vtime.h 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/include/janus/vtime.h 2007-08-27 15:32:34 UTC (rev 1707) @@ -367,6 +367,7 @@ void JaSend( const stem::Event& e ); void JoinGroup( group_type grp ); + void LeaveGroup( group_type grp ); virtual void VSNewMember( const stem::Event_base<VSsync_rq>& e ); virtual void VSOutMember( const stem::Event_base<VSsync_rq>& e ); @@ -381,6 +382,7 @@ { return _vtdsp; } protected: + void Unsubscribe(); void VSNewMember_data( const stem::Event_base<VSsync_rq>&, const std::string& data ); void get_gvtime( group_type g, gvtime_type& gvt ); @@ -398,6 +400,7 @@ #define VS_SYNC_TIME 0x303 #define VS_NEW_REMOTE_MEMBER 0x304 #define VS_NEW_MEMBER_RV 0x305 +#define VS_HOST_MGR_FINAL 0x306 #ifdef __USE_STLPORT_HASH # undef __USE_STLPORT_HASH Modified: trunk/complement/explore/lib/janus/ChangeLog =================================================================== --- trunk/complement/explore/lib/janus/ChangeLog 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/lib/janus/ChangeLog 2007-08-27 15:32:34 UTC (rev 1707) @@ -1,3 +1,26 @@ +2007-08-27 Petr Ovtchenkov <pt...@is...> + + * janus.h, janus.cc: hide methods, intended for internal + protocol usage only; + + * vtime.h, vtime.cc: LeaveGroup added; + + * vshostmgr.h, vshostmgr.cc: trick with finalizer---event after + that message queue free from VS_OUT_MEMBER events; + + * ut/unit_test.cc: move test suite to janus namespace; + + * ut/vt_object.cc, ut/vt_handler.cc, ut/VTmess_core.cc: + idem; + + * ut/vt_operations.cc, ut/vt_operations.h, ut/vt_dispatch.cc: + idem; + + * ut/vt_remote.cc: idem; + + * ut/unit_test.cc, ut/vt_remote.cc: test two groups and + interprocess virtual synchrony; + 2007-08-23 Petr Ovtchenkov <pt...@is...> * janus.h, janus.cc: Janus code moved from vtime.h, vtime.cc; Modified: trunk/complement/explore/lib/janus/janus.cc =================================================================== --- trunk/complement/explore/lib/janus/janus.cc 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/lib/janus/janus.cc 2007-08-27 15:32:34 UTC (rev 1707) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/23 12:36:32 ptr> +// -*- C++ -*- Time-stamp: <07/08/26 12:44:25 ptr> #include <janus/janus.h> #include <janus/vshostmgr.h> @@ -261,7 +261,7 @@ throw domain_error( "VT object not member of group" ); // Error: not group member } -void Janus::Subscribe( stem::addr_type addr, oid_type oid, group_type grp ) +void Janus::Subscribe( stem::addr_type addr, const oid_type& oid, group_type grp ) { // See comment on top of VTSend above xmt::recursive_scoped_lock lk( this->_theHistory_lock ); @@ -298,11 +298,11 @@ // cerr << "**** " << grp << " " << xmt::getpid() << endl; if ( /* (grp != vshosts_group) && */ (_hostmgr != 0) ) { - _hostmgr->Subscribe( addr, oid, grp ); + _hostmgr->Subscribe( addr, grp ); } } -void Janus::Unsubscribe( oid_type oid, group_type grp ) +void Janus::Unsubscribe( const oid_type& oid, group_type grp ) { // See comment on top of VTSend above xmt::recursive_scoped_lock lk( this->_theHistory_lock ); @@ -311,6 +311,8 @@ grmap.equal_range( grp ); vt_map_type::iterator i = vtmap.find( oid ); + addr_cache_t addr_cache; + while ( range.first != range.second ) { if ( range.first->second == oid ) { grmap.erase( range.first++ ); @@ -318,9 +320,28 @@ vt_map_type::iterator j = vtmap.find( range.first->second ); if ( j != vtmap.end() ) { stem::Event_base<VSsync_rq> ev( VS_OUT_MEMBER ); - ev.dest( j->second.stem_addr() ); + stem::addr_type addr = j->second.stem_addr(); + + // if address is foreign, send VS_OUT_MEMBER to foreign janus + if ( (addr & stem::extbit) != 0 ) { + gaddr_type ga = manager()->reflect( addr ); + if ( ga != gaddr_type() ) { + ga.addr = stem::janus_addr; + } + addr = manager()->reflect( ga ); + // send only once, foreign janus will resend to other group members + // in the same process: + if ( addr_cache.find(addr) != addr_cache.end() ) { + ++range.first; + continue; + } else { + addr_cache.insert( addr ); + } + } + ev.dest( addr ); ev.src( i != vtmap.end() ? i->second.stem_addr() : self_id() ); ev.value().grp = grp; + Forward( ev ); #ifdef __FIT_VS_TRACE try { scoped_lock lk(_lock_tr); @@ -333,8 +354,6 @@ catch ( ... ) { } #endif // __FIT_VS_TRACE - - Forward( ev ); } ++range.first; } @@ -346,11 +365,12 @@ } } - if ( grp != vshosts_group ) { - } + // if ( /* (grp != vshosts_group) && */ (_hostmgr != 0) ) { + // _hostmgr->Unsubscribe( oid, grp ); + // } } -void Janus::Unsubscribe( oid_type oid ) +void Janus::Unsubscribe( const oid_type& oid ) { // See comment on top of JaSend above xmt::recursive_scoped_lock lk( this->_theHistory_lock ); @@ -364,6 +384,8 @@ pair<gid_map_type::iterator,gid_map_type::iterator> range = grmap.equal_range( *grp ); + addr_cache_t addr_cache; + while ( range.first != range.second ) { if ( range.first->second == oid ) { grmap.erase( range.first++ ); @@ -371,9 +393,28 @@ vt_map_type::iterator j = vtmap.find( range.first->second ); if ( j != vtmap.end() ) { stem::Event_base<VSsync_rq> ev( VS_OUT_MEMBER ); - ev.dest( j->second.stem_addr() ); + stem::addr_type addr = j->second.stem_addr(); + + // if address is foreign, send VS_OUT_MEMBER to foreign janus + if ( (addr & stem::extbit) != 0 ) { + gaddr_type ga = manager()->reflect( addr ); + if ( ga != gaddr_type() ) { + ga.addr = stem::janus_addr; + } + addr = manager()->reflect( ga ); + // send only once, foreign janus will resend to other group members + // in the same process: + if ( addr_cache.find(addr) != addr_cache.end() ) { + ++range.first; + continue; + } else { + addr_cache.insert( addr ); + } + } + ev.dest( addr ); ev.src( i != vtmap.end() ? i->second.stem_addr() : self_id() ); ev.value().grp = *grp; + Forward( ev ); #ifdef __FIT_VS_TRACE try { scoped_lock lk(_lock_tr); @@ -386,8 +427,6 @@ catch ( ... ) { } #endif // __FIT_VS_TRACE - - Forward( ev ); } ++range.first; } @@ -504,7 +543,7 @@ if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { *_trs << " -> VS_NEW_MEMBER_RV G" << vshosts_group << " " << hex << showbase - << evr.src() << " -> " << evr.dest() << dec << endl; + << self_id() << " -> " << evr.dest() << dec << endl; } } catch ( ... ) { @@ -520,8 +559,7 @@ group_type grp = ev.value().grp; pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( grp ); if ( range.first != range.second ) { // we have local? member within this group - gaddr_type oid = manager()->reflect( ev.src() ); // ???? oid == gaddr - addr_type addr = ev.src(); + const addr_type addr = ev.src(); gaddr_type ga = manager()->reflect( addr ); addr_type janus_addr = badaddr; if ( ga != gaddr_type() ) { @@ -571,6 +609,8 @@ } } + const gaddr_type oid = manager()->reflect( addr ); // ???? oid == gaddr + vtmap[oid].add( addr, grp ); grmap.insert( make_pair(grp,oid) ); // cerr << "**** " << grp << " " << xmt::getpid() << endl; @@ -584,8 +624,7 @@ group_type grp = ev.value().grp; pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( grp ); if ( range.first != range.second ) { // we have local? member within this group - gaddr_type oid = manager()->reflect( ev.src() ); // ???? oid == gaddr - addr_type addr = ev.src(); + const addr_type addr = ev.src(); for ( ; range.first != range.second; ++range.first ) { vt_map_type::iterator i = vtmap.find( range.first->second ); if ( i != vtmap.end() && ((i->second.stem_addr() & stem::extbit) == 0 )) { @@ -609,13 +648,14 @@ } } + const gaddr_type oid = manager()->reflect( addr ); // ???? oid == gaddr vtmap[oid].add( addr, grp ); grmap.insert( make_pair(grp,oid) ); // cerr << "**** " << grp << " " << xmt::getpid() << endl; } } else { - gaddr_type oid = manager()->reflect( ev.src() ); // ???? oid == gaddr - addr_type addr = ev.src(); + const addr_type addr = ev.src(); + const gaddr_type oid = manager()->reflect( ev.src() ); // ???? oid == gaddr vtmap[oid].add( addr, vshosts_group ); grmap.insert( make_pair(static_cast<group_type>(vshosts_group),oid) ); @@ -623,6 +663,67 @@ } } +void Janus::VSOutMember( const stem::Event_base<VSsync_rq>& ev ) +{ +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << "<- VS_OUT_MEMBER G" << ev.value().grp + << hex << showbase + << ev.src() << " -> " << ev.dest() << dec << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + + const gaddr_type oid = manager()->reflect( ev.src() ); // ???? oid == gaddr + const group_type grp = ev.value().grp; + + + pair<gid_map_type::iterator,gid_map_type::iterator> range = + grmap.equal_range( grp ); + + vt_map_type::iterator i = vtmap.find( oid ); + + while ( range.first != range.second ) { + if ( range.first->second == oid ) { + grmap.erase( range.first++ ); + } else { + vt_map_type::iterator j = vtmap.find( range.first->second ); + if ( j != vtmap.end() ) { + stem::addr_type addr = j->second.stem_addr(); + + // send only to local addresses + if ( (addr & stem::extbit) == 0 ) { + ev.dest( addr ); + Forward( ev ); +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << " -> VS_OUT_MEMBER " + << hex << showbase + << ev.src() << " -> " << ev.dest() << dec << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + } + } + ++range.first; + } + } + + if ( i != vtmap.end() ) { + if ( i->second.rm_group( grp ) ) { // no groups more + vtmap.erase( i ); + } + } +} + void Janus::connect( const char *host, int port ) { _hostmgr->connect( host, port ); @@ -653,6 +754,7 @@ EV_Event_base_T_( ST_NULL, VS_NEW_MEMBER, VSNewMember, VSsync_rq ) EV_Event_base_T_( ST_NULL, VS_NEW_REMOTE_MEMBER, VSNewRemoteMemberDirect, VSsync_rq ) EV_Event_base_T_( ST_NULL, VS_NEW_MEMBER_RV, VSNewRemoteMemberRevert, VSsync_rq ) + EV_Event_base_T_( ST_NULL, VS_OUT_MEMBER, VSOutMember, VSsync_rq ) END_RESPONSE_TABLE } // namespace janus Modified: trunk/complement/explore/lib/janus/ut/VTmess_core.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/VTmess_core.cc 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/lib/janus/ut/VTmess_core.cc 2007-08-27 15:32:34 UTC (rev 1707) @@ -5,7 +5,8 @@ #include <iostream> #include <janus/vtime.h> -using namespace janus; +namespace janus { + using namespace std; class VTM_handler : @@ -146,3 +147,6 @@ return EXAM_RESULT; } + +} // namespace janus + Modified: trunk/complement/explore/lib/janus/ut/unit_test.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/unit_test.cc 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/lib/janus/ut/unit_test.cc 2007-08-27 15:32:34 UTC (rev 1707) @@ -6,11 +6,13 @@ int EXAM_IMPL(vtime_test_suite) { + using namespace janus; + exam::test_suite::test_case_type tc[3]; exam::test_suite t( "virtual time operations" ); - vtime_operations vt_oper; + janus::vtime_operations vt_oper; t.add( &vtime_operations::vt_max, vt_oper, "Max", tc[1] = t.add( &vtime_operations::vt_add, vt_oper, "Additions", @@ -20,16 +22,17 @@ 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::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] )))))))))); + t.add( &vtime_operations::mgroups, vt_oper, "mgroups", + 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/lib/janus/ut/vt_dispatch.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_dispatch.cc 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/lib/janus/ut/vt_dispatch.cc 2007-08-27 15:32:34 UTC (rev 1707) @@ -7,7 +7,8 @@ #include <janus/vtime.h> #include <janus/janus.h> -using namespace janus; +namespace janus { + using namespace std; class Dummy : @@ -129,3 +130,6 @@ return EXAM_RESULT; } + +} // namespace janus + Modified: trunk/complement/explore/lib/janus/ut/vt_handler.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_handler.cc 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/lib/janus/ut/vt_handler.cc 2007-08-27 15:32:34 UTC (rev 1707) @@ -7,7 +7,8 @@ #include <stem/EvManager.h> -using namespace janus; +namespace janus { + using namespace std; class VTDummy : @@ -353,3 +354,5 @@ return EXAM_RESULT; } + +} // namespace janus Modified: trunk/complement/explore/lib/janus/ut/vt_object.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_object.cc 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/lib/janus/ut/vt_object.cc 2007-08-27 15:32:34 UTC (rev 1707) @@ -5,7 +5,8 @@ #include <iostream> #include <janus/vtime.h> -using namespace janus; +namespace janus { + using namespace std; int EXAM_IMPL(vtime_operations::vt_object) @@ -186,3 +187,5 @@ return EXAM_RESULT; } + +} // namespace janus Modified: trunk/complement/explore/lib/janus/ut/vt_operations.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_operations.cc 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/lib/janus/ut/vt_operations.cc 2007-08-27 15:32:34 UTC (rev 1707) @@ -5,7 +5,8 @@ #include <iostream> #include <janus/vtime.h> -using namespace janus; +namespace janus { + using namespace std; int EXAM_IMPL(vtime_operations::vt_compare) @@ -319,3 +320,5 @@ return EXAM_RESULT; } + +} // namespace janus Modified: trunk/complement/explore/lib/janus/ut/vt_operations.h =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_operations.h 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/lib/janus/ut/vt_operations.h 2007-08-27 15:32:34 UTC (rev 1707) @@ -5,6 +5,8 @@ #include <exam/suite.h> +namespace janus { + struct vtime_operations { int EXAM_DECL(vt_compare); @@ -30,6 +32,9 @@ int EXAM_DECL(VTEntryIntoGroup3); int EXAM_DECL(remote); + int EXAM_DECL(mgroups); }; +} // namespace janus + #endif // __vt_operations_h Modified: trunk/complement/explore/lib/janus/ut/vt_remote.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_remote.cc 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/lib/janus/ut/vt_remote.cc 2007-08-27 15:32:34 UTC (rev 1707) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/23 21:31:56 ptr> +// -*- C++ -*- Time-stamp: <07/08/26 12:54:05 ptr> #include "vt_operations.h" @@ -21,13 +21,16 @@ #include <list> #include <sstream> +namespace janus { + using namespace std; using namespace stem; using namespace xmt; -using namespace janus; -#define VS_DUMMY_MESS 0x1203 -#define VS_DUMMY_GREETING 0x1204 +#define VS_DUMMY_MESS 0x1203 +#define VS_DUMMY_GREETING 0x1204 +#define VS_DUMMY_GREETING2 0x1205 +#define VS_DUMMY_MESS2 0x1206 class YaRemote : public janus::VTHandler @@ -39,12 +42,16 @@ ~YaRemote(); void handler( const stem::Event& ); + void handler2( const stem::Event& ); void VSNewMember( const stem::Event_base<VSsync_rq>& ); void VSOutMember( const stem::Event_base<VSsync_rq>& ); void greeting(); + void greeting2(); void wait(); + void wait2(); + std::string msg; int count; int ocount; @@ -55,9 +62,17 @@ gr.set( false ); } + void wait_greeting2() + { + gr2.try_wait(); + gr2.set( false ); + } + private: xmt::condition cnd; + xmt::condition cnd2; xmt::condition gr; + xmt::condition gr2; DECLARE_RESPONSE_TABLE( YaRemote, janus::VTHandler ); }; @@ -68,7 +83,9 @@ ocount(0) { cnd.set( false ); + cnd2.set( false ); gr.set( false ); + gr2.set( false ); } YaRemote::YaRemote( stem::addr_type id, const char *info ) : @@ -77,7 +94,9 @@ ocount(0) { cnd.set( false ); + cnd2.set( false ); gr.set( false ); + gr2.set( false ); } YaRemote::YaRemote( const char *info ) : @@ -86,7 +105,9 @@ ocount(0) { cnd.set( false ); + cnd2.set( false ); gr.set( false ); + gr2.set( false ); } YaRemote::~YaRemote() @@ -101,6 +122,13 @@ cnd.set( true ); } +void YaRemote::handler2( const stem::Event& ev ) +{ + msg = ev.value(); + + cnd2.set( true ); +} + void YaRemote::VSNewMember( const stem::Event_base<VSsync_rq>& ev ) { // cerr << "Hello " << xmt::getpid() << endl; @@ -109,14 +137,19 @@ // VTNewMember_data( ev, "" ); VTHandler::VSNewMember( ev ); - stem::EventVoid gr_ev( VS_DUMMY_GREETING ); - gr_ev.dest( ev.src() ); - Send( gr_ev ); + if ( ev.value().grp == janus::vs_base::first_user_group ) { + stem::EventVoid gr_ev( VS_DUMMY_GREETING ); + gr_ev.dest( ev.src() ); + Send( gr_ev ); + } else if ( ev.value().grp == (janus::vs_base::first_user_group + 1) ) { + stem::EventVoid gr_ev( VS_DUMMY_GREETING2 ); + gr_ev.dest( ev.src() ); + Send( gr_ev ); + } } void YaRemote::VSOutMember( const stem::Event_base<VSsync_rq>& ev ) { - cerr << "VSOutMember" << endl; ++ocount; } @@ -127,14 +160,28 @@ cnd.set( false ); } +void YaRemote::wait2() +{ + cnd2.try_wait(); + + cnd2.set( false ); +} + void YaRemote::greeting() { gr.set( true ); } +void YaRemote::greeting2() +{ + gr2.set( true ); +} + DEFINE_RESPONSE_TABLE( YaRemote ) EV_EDS( ST_NULL, VS_DUMMY_MESS, handler ) + EV_EDS( ST_NULL, VS_DUMMY_MESS2, handler2 ) EV_VOID( ST_NULL, VS_DUMMY_GREETING, greeting ) + EV_VOID( ST_NULL, VS_DUMMY_GREETING2, greeting2 ) END_RESPONSE_TABLE int EXAM_IMPL(vtime_operations::remote) @@ -154,50 +201,60 @@ b.wait(); { - YaRemote obj1( "obj client" ); + VTHandler obj0; // this need to keep VSHostMgr after YaRemote exit + // to check exit from group with another process + { + YaRemote obj1( "obj client" ); - // obj1.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch ); - // obj1.manager()->settrs( &std::cerr ); + // obj1.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch ); + // obj1.manager()->settrs( &std::cerr ); - // obj1.vtdispatcher()->settrf( janus::Janus::tracenet | janus::Janus::tracedispatch | janus::Janus::tracefault | janus::Janus::tracedelayed | janus::Janus::tracegroup ); - // obj1.vtdispatcher()->settrs( &std::cerr ); + // obj1.vtdispatcher()->settrf( janus::Janus::tracenet | janus::Janus::tracedispatch | janus::Janus::tracefault | janus::Janus::tracedelayed | janus::Janus::tracegroup ); + // obj1.vtdispatcher()->settrs( &std::cerr ); - EXAM_CHECK_ASYNC( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 1 ); + EXAM_CHECK_ASYNC( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 1 ); - obj1.vtdispatcher()->connect( "localhost", 6980 ); + obj1.vtdispatcher()->connect( "localhost", 6980 ); - // cerr << obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) << endl; + // cerr << obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) << endl; - while ( obj1.vtdispatcher()->vs_known_processes() < 2 ) { - xmt::Thread::yield(); - xmt::delay( xmt::timespec( 0, 1000000 ) ); - } + while ( obj1.vtdispatcher()->vs_known_processes() < 2 ) { + xmt::Thread::yield(); + xmt::delay( xmt::timespec( 0, 1000000 ) ); + } - /*******************************************************************\ - * This variant is wrong, because of group_size don't guarantee - * that information in the object is relevant (i.e. VSsync happens); - * for example, in case below group_size already 2, but no janus string - * stored yet. + /*******************************************************************\ + * This variant is wrong, because of group_size don't guarantee + * that information in the object is relevant (i.e. VSsync happens); + * for example, in case below group_size already 2, but no janus string + * stored yet. - while ( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) < 2 ) { - xmt::Thread::yield(); - xmt::delay( xmt::timespec( 0, 1000000 ) ); - } - \********************************************************************/ + while ( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) < 2 ) { + xmt::Thread::yield(); + xmt::delay( xmt::timespec( 0, 1000000 ) ); + } + \********************************************************************/ - // cerr << obj1.vtdispatcher()->vs_known_processes() << endl; + // cerr << obj1.vtdispatcher()->vs_known_processes() << endl; - EXAM_CHECK_ASYNC( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 2 ); - // cerr << obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) << endl; + EXAM_CHECK_ASYNC( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 2 ); + // cerr << obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) << endl; - obj1.JoinGroup( janus::vs_base::first_user_group ); + obj1.JoinGroup( janus::vs_base::first_user_group ); - obj1.wait_greeting(); + obj1.wait_greeting(); - EXAM_CHECK_ASYNC( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 2 ); - EXAM_CHECK_ASYNC( obj1.count == 1 ); - // cerr << "* " << obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) << endl; - obj1.wait(); + EXAM_CHECK_ASYNC( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 2 ); + EXAM_CHECK_ASYNC( obj1.count == 1 ); + // cerr << "* " << obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) << endl; + obj1.wait(); + + // obj1.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch ); + // obj1.manager()->settrs( &std::cerr ); + } + // obj1 here away, but in another process (remote) still exist object in + // first_user_group, that's why 1 here: + EXAM_CHECK_ASYNC( obj0.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 1); } exit(0); @@ -226,15 +283,19 @@ obj1.JaSend( ev ); - EXAM_CHECK( obj1.count == 1 ); + EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 2 ); + EXAM_CHECK( obj1.count == 1 ); + // obj1.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch ); + // obj1.manager()->settrs( &std::cerr ); + int stat; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); - // cerr << obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) << endl; - // cerr << obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) << endl; + EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 1 ); + + EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 1 ); // cerr << obj1.vtdispatcher()->vs_known_processes() << endl; - // cerr << obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) << endl; } (&b)->~__barrier<true>(); @@ -250,3 +311,109 @@ return EXAM_RESULT; } +int EXAM_IMPL(vtime_operations::mgroups) +{ + 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(); + + { + VTHandler obj0; // this need to keep VSHostMgr after YaRemote exit + // to check exit from group with another process + { + YaRemote obj1( "obj client" ); + + obj1.vtdispatcher()->connect( "localhost", 6980 ); + + while ( obj1.vtdispatcher()->vs_known_processes() < 2 ) { + xmt::Thread::yield(); + xmt::delay( xmt::timespec( 0, 1000000 ) ); + } + + obj1.JoinGroup( janus::vs_base::first_user_group ); + obj1.JoinGroup( janus::vs_base::first_user_group + 1); + + obj1.wait_greeting(); + obj1.wait_greeting2(); + + EXAM_CHECK_ASYNC( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 2 ); + EXAM_CHECK_ASYNC( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group + 1) == 2 ); + EXAM_CHECK_ASYNC( obj1.count == 2 ); + + stem::Event ev( VS_DUMMY_MESS2 ); + ev.dest( janus::vs_base::first_user_group + 1 ); + ev.value() = "hello"; + + obj1.JaSend( ev ); + + obj1.wait(); + + // obj1.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch ); + // obj1.manager()->settrs( &std::cerr ); + } + + EXAM_CHECK_ASYNC( obj0.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 1); + EXAM_CHECK_ASYNC( obj0.vtdispatcher()->group_size(janus::vs_base::first_user_group + 1) == 1); + } + + exit(0); + } + catch ( xmt::fork_in_parent& child ) { + YaRemote obj1( "obj srv" ); + + obj1.vtdispatcher()->serve( 6980 ); + + obj1.JoinGroup( janus::vs_base::first_user_group ); + obj1.JoinGroup( janus::vs_base::first_user_group + 1); + + b.wait(); + + obj1.wait_greeting(); + obj1.wait_greeting2(); + + stem::Event ev( VS_DUMMY_MESS ); + ev.dest( janus::vs_base::first_user_group ); + ev.value() = "hello"; + + obj1.JaSend( ev ); + + EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 2 ); + EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group + 1) == 2 ); + EXAM_CHECK( obj1.count == 2 ); + + obj1.wait2(); + + int stat; + EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + + EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 1 ); + EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group + 1) == 1 ); + // cerr << obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group + 1) << endl; + + EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 1 ); + } + + (&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; +} + +} // namespace janus Modified: trunk/complement/explore/lib/janus/vshostmgr.cc =================================================================== --- trunk/complement/explore/lib/janus/vshostmgr.cc 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/lib/janus/vshostmgr.cc 2007-08-27 15:32:34 UTC (rev 1707) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/23 11:24:18 ptr> +// -*- C++ -*- Time-stamp: <07/08/26 12:56:20 ptr> #include <janus/vshostmgr.h> @@ -25,21 +25,24 @@ using namespace janus; VSHostMgr::VSHostMgr() : - VTHandler() + VTHandler(), + finalizer( "vshostmgr aux" ) { vshost.insert( gaddr_type( stem::janus_addr ) ); JoinGroup( vshosts_group ); } VSHostMgr::VSHostMgr( stem::addr_type id, const char *info ) : - VTHandler( id, info ) + VTHandler( id, info ), + finalizer( "vshostmgr aux" ) { vshost.insert( gaddr_type( stem::janus_addr ) ); JoinGroup( vshosts_group ); } VSHostMgr::VSHostMgr( const char *info ) : - VTHandler( info ) + VTHandler( info ), + finalizer( "vshostmgr aux" ) { // vtdispatcher()->settrf( janus::Janus::tracenet | janus::Janus::tracedispatch | janus::Janus::tracefault | janus::Janus::tracedelayed | janus::Janus::tracegroup ); @@ -49,18 +52,38 @@ VSHostMgr::~VSHostMgr() { - while ( !_clients.empty() ) { - _clients.front()->close(); - _clients.front()->join(); - delete _clients.front(); - _clients.pop_front(); + if ( !_clients.empty() || !_servers.empty() ) { + VTHandler::Unsubscribe(); // before channels closed! + + stem::EventVoid ev( VS_HOST_MGR_FINAL ); + + ev.dest( finalizer.self_id() ); + Send( ev ); + + finalizer.wait(); + + // give the chance to deliver VS_OUT_MEMBER message to remotes... + // Do you know better solution, because this one is ugly? + for ( int i = 0; i < 5; ++i ) { + xmt::Thread::yield(); + xmt::delay( xmt::timespec( 0, 100000 ) ); + } + + // shutdown clients... + while ( !_clients.empty() ) { + _clients.front()->close(); + _clients.front()->join(); + delete _clients.front(); + _clients.pop_front(); + } + // ... and servers + while ( !_servers.empty() ) { + _servers.front()->close(); + _servers.front()->wait(); + delete _servers.front(); + _servers.pop_front(); + } } - while ( !_servers.empty() ) { - _servers.front()->close(); - _servers.front()->wait(); - delete _servers.front(); - _servers.pop_front(); - } } void VSHostMgr::VSNewMember( const stem::Event_base<VSsync_rq>& ev ) @@ -180,7 +203,7 @@ #endif // __FIT_VS_TRACE } -void VSHostMgr::Subscribe( stem::addr_type addr, oid_type oid, group_type grp ) +void VSHostMgr::Subscribe( stem::addr_type addr, group_type grp ) { try { manager()->transport( addr ); @@ -199,7 +222,7 @@ #ifdef __FIT_VS_TRACE try { scoped_lock lk(vtdispatcher()->_lock_tr); - if ( vtdispatcher()->_trs != 0 && vtdispatcher()->_trs->good() && (vtdispatcher()->_trflags & Janus::tracenet) ) { + if ( vtdispatcher()->_trs != 0 && vtdispatcher()->_trs->good() && (vtdispatcher()->_trflags & Janus::tracegroup) ) { *vtdispatcher()->_trs << " -> VS_NEW_REMOTE_MEMBER G" << grp << " " << hex << showbase << ev.src() << " -> " << ev.dest() << dec << endl; @@ -218,5 +241,9 @@ // EV_Event_base_T_( ST_NULL, VS_NEW_MEMBER_RV, VSNewRemoteMemberRevert, VSsync_rq ) // END_RESPONSE_TABLE +DEFINE_RESPONSE_TABLE( VSHostMgr::Finalizer ) + EV_VOID( ST_NULL, VS_HOST_MGR_FINAL, final ) +END_RESPONSE_TABLE + } // namespace janus Modified: trunk/complement/explore/lib/janus/vtime.cc =================================================================== --- trunk/complement/explore/lib/janus/vtime.cc 2007-08-27 15:10:53 UTC (rev 1706) +++ trunk/complement/explore/lib/janus/vtime.cc 2007-08-27 15:32:34 UTC (rev 1707) @@ -621,16 +621,25 @@ VTHandler::~VTHandler() { - _vtdsp->Unsubscribe( oid_type( self_id() ) ); + Unsubscribe(); ((Init *)Init_buf)->~Init(); } +void VTHandler::Unsubscribe() +{ + _vtdsp->Unsubscribe( oid_type( self_id() ) ); +} + void VTHandler::JoinGroup( group_type grp ) { _vtdsp->Subscribe( self_id(), oid_type( self_id() ), grp ); } +void VTHandler::LeaveGroup( group_type grp ) +{ + _vtdsp->Unsubscribe( oid_type( self_id() ), grp ); +} void VTHandler::VSNewMember( const stem::Event_base<VSsync_rq>& ev ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-08-29 12:15:27
|
Revision: 1710 http://complement.svn.sourceforge.net/complement/?rev=1710&view=rev Author: complement Date: 2007-08-29 05:15:22 -0700 (Wed, 29 Aug 2007) Log Message: ----------- gmake/targetdirs.mak: default installation path is /usr/local now; BASE_INSTALL_*_DIR now free from TARGET_NAME prefix, TARGET_NAME prefix appear in INSTALL_*_DIR* as prefix for lib, bin, etc.; gmake/linux/sys.mak: add INSTALL_D for directory creation during installation and INSTALL_F for installing plain file, like header; configure: process --prefix --bindir, --libdir, --includedir (paths for installation); configure may run not only from same dir; gmake/unix/rules-install-so.mak: installation of headers, dummy yet. lib/mt/Makefile: experiments with installation of headers. Modified Paths: -------------- trunk/complement/explore/Makefiles/ChangeLog trunk/complement/explore/Makefiles/gmake/linux/sys.mak trunk/complement/explore/Makefiles/gmake/targetdirs.mak trunk/complement/explore/Makefiles/gmake/unix/rules-install-so.mak trunk/complement/explore/configure trunk/complement/explore/lib/mt/Makefile Modified: trunk/complement/explore/Makefiles/ChangeLog =================================================================== --- trunk/complement/explore/Makefiles/ChangeLog 2007-08-29 05:27:04 UTC (rev 1709) +++ trunk/complement/explore/Makefiles/ChangeLog 2007-08-29 12:15:22 UTC (rev 1710) @@ -1,3 +1,16 @@ +2007-08-29 Petr Ovtchenkov <pt...@is...> + + * gmake/targetdirs.mak: default installation path is /usr/local + now; BASE_INSTALL_*_DIR now free from TARGET_NAME prefix, + TARGET_NAME prefix appear in INSTALL_*_DIR* as prefix for lib, + bin, etc.; + + * gmake/linux/sys.mak: add INSTALL_D for directory creation during + installation and INSTALL_F for installing plain file, like header; + + * gmake/unix/rules-install-so.mak: installation of headers, + dummy yet. + 2007-08-17 Petr Ovtchenkov <pt...@is...> * gmake/app/gcc.mak, gmake/lib/gcc.mak: use ${CXXFLAGS} when Modified: trunk/complement/explore/Makefiles/gmake/linux/sys.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/linux/sys.mak 2007-08-29 05:27:04 UTC (rev 1709) +++ trunk/complement/explore/Makefiles/gmake/linux/sys.mak 2007-08-29 12:15:22 UTC (rev 1710) @@ -1,6 +1,6 @@ # Time-stamp: <06/11/10 23:43:27 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -20,6 +20,8 @@ INSTALL_SO := ${INSTALL} -c -m 0755 ${_INSTALL_STRIP_OPTION} INSTALL_A := ${INSTALL} -c -m 0644 INSTALL_EXE := ${INSTALL} -c -m 0755 +INSTALL_D := ${INSTALL} -d -m 0755 +INSTALL_F := ${INSTALL} -c -p -m 0644 # bash's built-in test is like extern # EXT_TEST := /usr/bin/test Modified: trunk/complement/explore/Makefiles/gmake/targetdirs.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/targetdirs.mak 2007-08-29 05:27:04 UTC (rev 1709) +++ trunk/complement/explore/Makefiles/gmake/targetdirs.mak 2007-08-29 12:15:22 UTC (rev 1710) @@ -33,21 +33,24 @@ OUTPUT_DIR_A_STLDBG := $(OUTPUT_DIR_STLDBG) endif -BASE_INSTALL_DIR ?= ${SRCROOT}/build/$(TARGET_NAME) +# BASE_INSTALL_DIR ?= ${SRCROOT}/build/$(TARGET_NAME) +BASE_INSTALL_DIR ?= /usr/local BASE_INSTALL_LIB_DIR ?= ${BASE_INSTALL_DIR} BASE_INSTALL_BIN_DIR ?= ${BASE_INSTALL_DIR} +BASE_INSTALL_HDR_DIR ?= ${BASE_INSTALL_DIR} -INSTALL_LIB_DIR ?= ${BASE_INSTALL_LIB_DIR}lib -INSTALL_LIB_DIR_DBG ?= ${BASE_INSTALL_LIB_DIR}lib +INSTALL_LIB_DIR ?= ${BASE_INSTALL_LIB_DIR}/${TARGET_NAME}lib +INSTALL_LIB_DIR_DBG ?= ${BASE_INSTALL_LIB_DIR}/${TARGET_NAME}lib ifndef WITHOUT_STLPORT -INSTALL_LIB_DIR_STLDBG ?= ${BASE_INSTALL_LIB_DIR}lib +INSTALL_LIB_DIR_STLDBG ?= ${BASE_INSTALL_LIB_DIR}/${TARGET_NAME}lib endif -INSTALL_BIN_DIR ?= ${BASE_INSTALL_BIN_DIR}bin +INSTALL_BIN_DIR ?= ${BASE_INSTALL_BIN_DIR}/${TARGET_NAME}bin INSTALL_BIN_DIR_DBG ?= ${INSTALL_BIN_DIR}_g ifndef WITHOUT_STLPORT INSTALL_BIN_DIR_STLDBG ?= ${INSTALL_BIN_DIR}_stlg endif +INSTALL_HDR_DIR ?= ${BASE_INSTALL_DIR}/include ifndef WITHOUT_STLPORT OUTPUT_DIRS := $(OUTPUT_DIR) $(OUTPUT_DIR_DBG) $(OUTPUT_DIR_STLDBG) \ Modified: trunk/complement/explore/Makefiles/gmake/unix/rules-install-so.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/unix/rules-install-so.mak 2007-08-29 05:27:04 UTC (rev 1709) +++ trunk/complement/explore/Makefiles/gmake/unix/rules-install-so.mak 2007-08-29 12:15:22 UTC (rev 1710) @@ -79,7 +79,7 @@ endif -PHONY += install install-strip $(INSTALL_TAGS) $(INSTALL_STRIP_TAGS) +PHONY += install install-strip install-headers $(INSTALL_TAGS) $(INSTALL_STRIP_TAGS) install: $(INSTALL_TAGS) @@ -139,3 +139,34 @@ install-stldbg-shared: stldbg-shared $(INSTALL_LIB_DIR_STLDBG) $(INSTALL_LIB_DIR_STLDBG)/${SO_NAME_STLDBGxxx} ${POST_INSTALL_STLDBG} endif + +define do_install_headers +if [ ! -d $(INSTALL_HDR_DIR) ]; then \ + echo $(INSTALL_D) $(INSTALL_HDR_DIR); \ +fi; \ +for dd in $(HEADERS_BASE); do \ + d=`dirname $$dd`; \ + h=`basename $$dd`; \ + f=`cd $$d; find $$h \( -type d \( -wholename "*/.svn" -o -prune \) \) -print`; \ + for ddd in $$f; do \ + if [ ! -d $(INSTALL_HDR_DIR)/$$ddd ]; then \ + echo $(INSTALL_D) $(INSTALL_HDR_DIR)/$$ddd; \ + fi; \ + done; \ + f=`find $$dd \( -type f \( \! \( -wholename "*/.svn/*" -o -name "*~" -o -name "*.bak" \) \) \) -print`; \ + for ff in $$f; do \ + h=`echo $$ff | sed -e "s|$$d|$(INSTALL_HDR_DIR)|"`; \ + echo $(INSTALL_F) $$ff $$h; \ + done; \ +done; \ +for f in $(HEADERS); do \ + h=`basename $$f`; \ + echo $(INSTALL_F) $$f $(INSTALL_HDR_DIR)/$$h; \ +done +endef + +# _HEADERS_FROM = $(shell for dd in $(HEADERS_BASE); do find $$dd \( -type f \( \! \( -wholename "*/.svn/*" -o -name "*~" -o -name "*.bak" \) \) \) -print ; done ) +# _HEADERS_TO = $(foreach d,$(HEADERS_BASE),$(patsubst $(d)/%,$(BASE_INSTALL_DIR)include/%,$(_HEADERS_FROM))) + +install-headers: + @$(do_install_headers) Modified: trunk/complement/explore/configure =================================================================== --- trunk/complement/explore/configure 2007-08-29 05:27:04 UTC (rev 1709) +++ trunk/complement/explore/configure 2007-08-29 12:15:22 UTC (rev 1710) @@ -1,10 +1,10 @@ #!/bin/sh -# Time-stamp: <07/06/08 23:24:03 ptr> +# Time-stamp: <07/08/29 11:36:31 ptr> -configmak=Makefiles/gmake/config.mak +base=`dirname $0` -# rm -f ${configmak} +configmak=$base/Makefiles/gmake/config.mak # echo "# STLPORT_DIR := /export/home/windows/guest/STLlab/STLport" >> ${configmak} # echo "# MSVC_DIR := c:/Program Files/Microsoft Visual Studio/VC98" >> ${configmak} @@ -25,8 +25,15 @@ Available options: + --prefix=<dir> base install path (/usr/local/) + --bindir=<dir> install path for executables (PREFIX/bin) + --libdir=<dir> install path for libraries (PREFIX/lib) + --includedir=<dir> install path for headers (PREFIX/include) + --target=<target> target platform (cross-compiling) + --help print this help message and exit + --with-stlport=<dir> use STLport in catalog <dir> --without-stlport compile without STLport (default) --with-boost=<dir> use boost headers in catalog <dir> @@ -68,6 +75,9 @@ if [ "$compiler_family_set" = "" ]; then write_option gcc COMPILER_NAME fi + # if [ "$prefix_set" = "" ]; then + # write_option "/usr/local" BASE_INSTALL_DIR + # fi } case $# in @@ -168,6 +178,19 @@ esac compiler_family_set=y ;; + --prefix=*) + write_option "$option" BASE_INSTALL_DIR + # prefix_set=y + ;; + --bindir=*) + write_option "$option" INSTALL_BIN_DIR + ;; + --libdir=*) + write_option "$option" INSTALL_LIB_DIR + ;; + --includedir=*) + write_option "$option" INSTALL_HDR_DIR + ;; esac done Modified: trunk/complement/explore/lib/mt/Makefile =================================================================== --- trunk/complement/explore/lib/mt/Makefile 2007-08-29 05:27:04 UTC (rev 1709) +++ trunk/complement/explore/lib/mt/Makefile 2007-08-29 12:15:22 UTC (rev 1710) @@ -6,6 +6,7 @@ include ${SRCROOT}/Makefiles/gmake/top.mak INCLUDES += -I$(SRCROOT)/include +HEADERS_BASE = $(SRCROOT)/include/mt $(SRCROOT)/include/config $(SRCROOT)/include/misc check: all-shared $(MAKE) -C ut all-shared This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-09-01 05:33:26
|
Revision: 1717 http://complement.svn.sourceforge.net/complement/?rev=1717&view=rev Author: complement Date: 2007-08-31 22:33:23 -0700 (Fri, 31 Aug 2007) Log Message: ----------- copyright info added Modified Paths: -------------- trunk/complement/explore/include/exam/logger.h trunk/complement/explore/include/exam/suite.h trunk/complement/explore/lib/exam/logger.cc trunk/complement/explore/lib/exam/suite.cc trunk/complement/explore/lib/exam/ut/dummy_test.cc trunk/complement/explore/lib/exam/ut/exam_self_test.cc trunk/complement/explore/lib/exam/ut/exam_test_suite.cc trunk/complement/explore/lib/exam/ut/exam_test_suite.h Modified: trunk/complement/explore/include/exam/logger.h =================================================================== --- trunk/complement/explore/include/exam/logger.h 2007-08-30 15:44:47 UTC (rev 1716) +++ trunk/complement/explore/include/exam/logger.h 2007-09-01 05:33:23 UTC (rev 1717) @@ -1,5 +1,12 @@ -// -*- C++ -*- Time-stamp: <07/07/13 11:01:52 ptr> +// -*- C++ -*- Time-stamp: <07/09/01 09:08:25 ptr> +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + */ + #ifndef __logger_h #define __logger_h Modified: trunk/complement/explore/include/exam/suite.h =================================================================== --- trunk/complement/explore/include/exam/suite.h 2007-08-30 15:44:47 UTC (rev 1716) +++ trunk/complement/explore/include/exam/suite.h 2007-09-01 05:33:23 UTC (rev 1717) @@ -1,5 +1,12 @@ -// -*- C++ -*- Time-stamp: <07/07/21 09:06:00 ptr> +// -*- C++ -*- Time-stamp: <07/09/01 09:07:43 ptr> +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + */ + #ifndef __suite_h #define __suite_h Modified: trunk/complement/explore/lib/exam/logger.cc =================================================================== --- trunk/complement/explore/lib/exam/logger.cc 2007-08-30 15:44:47 UTC (rev 1716) +++ trunk/complement/explore/lib/exam/logger.cc 2007-09-01 05:33:23 UTC (rev 1717) @@ -1,5 +1,12 @@ -// -*- C++ -*- Time-stamp: <07/07/13 10:53:32 ptr> +// -*- C++ -*- Time-stamp: <07/09/01 09:09:27 ptr> +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + */ + #include <exam/logger.h> #include <iostream> Modified: trunk/complement/explore/lib/exam/suite.cc =================================================================== --- trunk/complement/explore/lib/exam/suite.cc 2007-08-30 15:44:47 UTC (rev 1716) +++ trunk/complement/explore/lib/exam/suite.cc 2007-09-01 05:33:23 UTC (rev 1717) @@ -1,5 +1,12 @@ -// -*- C++ -*- Time-stamp: <07/07/21 09:13:17 ptr> +// -*- C++ -*- Time-stamp: <07/09/01 09:09:43 ptr> +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + */ + #include <exam/suite.h> #include <stack> Modified: trunk/complement/explore/lib/exam/ut/dummy_test.cc =================================================================== --- trunk/complement/explore/lib/exam/ut/dummy_test.cc 2007-08-30 15:44:47 UTC (rev 1716) +++ trunk/complement/explore/lib/exam/ut/dummy_test.cc 2007-09-01 05:33:23 UTC (rev 1717) @@ -1,3 +1,12 @@ +// -*- C++ -*- Time-stamp: <07/09/01 09:10:32 ptr> + +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + */ + #include <exam/suite.h> int EXAM_IMPL(func) Modified: trunk/complement/explore/lib/exam/ut/exam_self_test.cc =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_self_test.cc 2007-08-30 15:44:47 UTC (rev 1716) +++ trunk/complement/explore/lib/exam/ut/exam_self_test.cc 2007-09-01 05:33:23 UTC (rev 1717) @@ -1,5 +1,12 @@ -// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> +// -*- C++ -*- Time-stamp: <07/09/01 09:10:26 ptr> +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + */ + #include "exam_test_suite.h" int main( int, char ** ) Modified: trunk/complement/explore/lib/exam/ut/exam_test_suite.cc =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.cc 2007-08-30 15:44:47 UTC (rev 1716) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.cc 2007-09-01 05:33:23 UTC (rev 1717) @@ -1,5 +1,12 @@ -// -*- C++ -*- Time-stamp: <07/07/21 09:01:26 ptr> +// -*- C++ -*- Time-stamp: <07/09/01 09:10:55 ptr> +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + */ + #include "exam_test_suite.h" #include "dummy_test.cc" Modified: trunk/complement/explore/lib/exam/ut/exam_test_suite.h =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.h 2007-08-30 15:44:47 UTC (rev 1716) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.h 2007-09-01 05:33:23 UTC (rev 1717) @@ -1,5 +1,12 @@ -// -*- C++ -*- Time-stamp: <07/07/16 23:40:09 ptr> +// -*- C++ -*- Time-stamp: <07/09/01 09:11:13 ptr> +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + */ + #ifndef __exam_test_suite_h #define __exam_test_suite_h This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-09-01 05:45:14
|
Revision: 1718 http://complement.svn.sourceforge.net/complement/?rev=1718&view=rev Author: complement Date: 2007-08-31 22:45:11 -0700 (Fri, 31 Aug 2007) Log Message: ----------- add inet_sockaddr() method, that return sockaddr_in in whole; replace sleep by yield in recvfrom, but function not really in use now Modified Paths: -------------- trunk/complement/explore/include/sockios/sockstream trunk/complement/explore/include/sockios/sockstream.cc trunk/complement/explore/lib/sockios/ChangeLog Modified: trunk/complement/explore/include/sockios/sockstream =================================================================== --- trunk/complement/explore/include/sockios/sockstream 2007-09-01 05:33:23 UTC (rev 1717) +++ trunk/complement/explore/include/sockios/sockstream 2007-09-01 05:45:11 UTC (rev 1718) @@ -1,22 +1,14 @@ -// -*- C++ -*- Time-stamp: <06/07/11 12:28:37 ptr> +// -*- C++ -*- Time-stamp: <07/08/31 09:49:58 ptr> /* - * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 + * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 * Petr Ovtchenkov * * Portion Copyright (c) 1999-2001 * Parallel Graphics Ltd. * - * Licensed under the Academic Free License Version 2.1 + * Licensed under the Academic Free License version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ #ifndef __SOCKSTREAM__ @@ -494,6 +486,14 @@ { return /* is_open() && */ _address.any.sa_family == AF_INET ? _address.inet.sin_addr.s_addr : 0; } + const sockaddr_in& inet_sockaddr() const throw( std::domain_error ) + { + if ( _address.any.sa_family != AF_INET ) { + throw domain_error( "socket not belongs to inet type" ); + } + return /* is_open() && */ _address.inet; + } + sock_base::stype stype() const { return _type; } @@ -613,7 +613,6 @@ private: typedef basic_sockbuf<charT,traits,_Alloc> _Self_type; - // int __rdsync(); int (basic_sockbuf<charT,traits,_Alloc>::*_xwrite)( const void *, size_t ); int (basic_sockbuf<charT,traits,_Alloc>::*_xread)( void *, size_t ); int write( const void *buf, size_t n ) @@ -651,7 +650,7 @@ void __hostname(); sock_base::socket_type _fd; - union { + union sockaddr_t { sockaddr_in inet; sockaddr any; } _address; @@ -660,9 +659,6 @@ int _errno; sock_base::stype _type; // bool _doclose; - // if open, and connected, other side hostname, - // otherwise undefined: - // string _hostname; }; template <class charT, class traits, class _Alloc> Modified: trunk/complement/explore/include/sockios/sockstream.cc =================================================================== --- trunk/complement/explore/include/sockios/sockstream.cc 2007-09-01 05:33:23 UTC (rev 1717) +++ trunk/complement/explore/include/sockios/sockstream.cc 2007-09-01 05:45:11 UTC (rev 1718) @@ -1,22 +1,14 @@ // -*- C++ -*- Time-stamp: <06/08/21 23:58:48 ptr> /* - * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 + * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 * Petr Ovtchenkov * * Portion Copyright (c) 1999-2001 * Parallel Graphics Ltd. * - * Licensed under the Academic Free License Version 2.1 + * Licensed under the Academic Free License version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ #ifdef __unix @@ -106,7 +98,7 @@ throw std::invalid_argument( "protocol not implemented" ); } if ( _bbuf == 0 ) - _M_allocate_block( 0xb00 ); // max 1460 (dec) [0x5b4] --- single segment + _M_allocate_block( type == sock_base::sock_stream ? 0xb00 : 0xffff ); // max 1460 (dec) [0x5b4] --- single segment if ( _bbuf == 0 ) { throw std::length_error( "can't allocate block" ); } @@ -114,21 +106,7 @@ setp( _bbuf, _bbuf + ((_ebuf - _bbuf)>>1) ); setg( this->epptr(), this->epptr(), this->epptr() ); - // _STLP_ASSERT( this->pbase() != 0 ); - // _STLP_ASSERT( this->pptr() != 0 ); - // _STLP_ASSERT( this->epptr() != 0 ); - // _STLP_ASSERT( this->eback() != 0 ); - // _STLP_ASSERT( this->gptr() != 0 ); - // _STLP_ASSERT( this->egptr() != 0 ); - // _STLP_ASSERT( _bbuf != 0 ); - // _STLP_ASSERT( _ebuf != 0 ); - _errno = 0; // if any - // __hostname(); - -// in_port_t ppp = 0x5000; -// cerr << hex << _address.inet.sin_port << " " << ppp << endl; -// cerr << hex << _address.inet.sin_addr.s_addr << endl; } catch ( std::domain_error& ) { #ifdef WIN32 @@ -234,7 +212,7 @@ throw std::invalid_argument( "protocol not implemented" ); } if ( _bbuf == 0 ) - _M_allocate_block( 0xb00 ); // max 1460 (dec) [0x5b4] --- single segment + _M_allocate_block( type == sock_base::sock_stream ? 0xb00 : 0xffff ); // max 1460 (dec) [0x5b4] --- single segment if ( _bbuf == 0 ) { throw std::length_error( "can't allocate block" ); } @@ -242,21 +220,7 @@ setp( _bbuf, _bbuf + ((_ebuf - _bbuf)>>1) ); setg( this->epptr(), this->epptr(), this->epptr() ); - // _STLP_ASSERT( this->pbase() != 0 ); - // _STLP_ASSERT( this->pptr() != 0 ); - // _STLP_ASSERT( this->epptr() != 0 ); - // _STLP_ASSERT( this->eback() != 0 ); - // _STLP_ASSERT( this->gptr() != 0 ); - // _STLP_ASSERT( this->egptr() != 0 ); - // _STLP_ASSERT( _bbuf != 0 ); - // _STLP_ASSERT( _ebuf != 0 ); - _errno = 0; // if any - // __hostname(); - -// in_port_t ppp = 0x5000; -// cerr << hex << _address.inet.sin_port << " " << ppp << endl; -// cerr << hex << _address.inet.sin_addr.s_addr << endl; } catch ( std::domain_error& ) { #ifdef WIN32 @@ -357,7 +321,7 @@ } if ( _bbuf == 0 ) { - _M_allocate_block( 0xb00 ); + _M_allocate_block( t == sock_base::sock_stream ? 0xb00 : 0xffff ); } if ( _bbuf == 0 ) { @@ -373,28 +337,8 @@ setp( _bbuf, _bbuf + ((_ebuf - _bbuf)>>1) ); setg( this->epptr(), this->epptr(), this->epptr() ); - // _STLP_ASSERT( this->pbase() != 0 ); - // _STLP_ASSERT( this->pptr() != 0 ); - // _STLP_ASSERT( this->epptr() != 0 ); - // _STLP_ASSERT( this->eback() != 0 ); - // _STLP_ASSERT( this->gptr() != 0 ); - // _STLP_ASSERT( this->egptr() != 0 ); - // _STLP_ASSERT( _bbuf != 0 ); - // _STLP_ASSERT( _ebuf != 0 ); - _errno = 0; // if any - // __hostname(); -// in_port_t ppp = 0x5000; -// cerr << hex << _address.inet.sin_port << " " << ppp << endl; -// cerr << hex << _address.inet.sin_addr.s_addr << endl; -// sockaddr_in xxx; -// int len = sizeof( xxx ); - -// getpeername( fd(), (sockaddr *)&xxx, &len ); -// cerr << hex << xxx.sin_port << endl; -// cerr << hex << xxx.sin_addr.s_addr << endl; - return this; } @@ -546,16 +490,6 @@ long count = this->pptr() - this->pbase(); if ( count ) { - // _STLP_ASSERT( this->pbase() != 0 ); - - // Never do this: read and and write in basic_sockbuf are independent, - // so reading here lead to lost message if reading and writing occur - // simultaneously from different threads - -// if ( __rdsync() != 0 ) { // I should read something, if other side write -// return traits::eof(); // otherwise I can't write without pipe broken -// } - if ( (this->*_xwrite)( this->pbase(), sizeof(charT) * count ) != count * sizeof(charT) ) return traits::eof(); } @@ -576,12 +510,6 @@ return 0; } - // _STLP_ASSERT( this->pbase() != 0 ); - // _STLP_ASSERT( this->pptr() != 0 ); - // _STLP_ASSERT( this->epptr() != 0 ); - // _STLP_ASSERT( _bbuf != 0 ); - // _STLP_ASSERT( _ebuf != 0 ); - if ( this->epptr() - this->pptr() > n ) { traits::copy( this->pptr(), s, n ); this->pbump( n ); @@ -605,52 +533,7 @@ return n; } -#if 0 // No needs: the sockets are essential bi-direction entities template<class charT, class traits, class _Alloc> -int basic_sockbuf<charT, traits, _Alloc>::__rdsync() -{ -#ifdef WIN32 - unsigned long nlen = 0; - int nmsg = ioctlsocket( fd(), FIONREAD, &nlen ); -#else - long nlen = 0; - int nmsg = ioctl( fd(), I_NREAD, &nlen ); // shouldn't work, as I understand... -#endif - if ( nmsg > 0 && nlen > 0 ) { - // _STLP_ASSERT( _bbuf != 0 ); - // _STLP_ASSERT( _ebuf != 0 ); - // _STLP_ASSERT( this->gptr() != 0 ); - // _STLP_ASSERT( this->egptr() != 0 ); - - bool shift_req = this->gptr() == this->eback() ? false : (_ebuf - this->gptr()) > nlen ? false : true; - if ( shift_req ) { - // _STLP_ASSERT( this->gptr() > this->eback() ); - // _STLP_ASSERT( this->gptr() <= this->egptr() ); - traits::move( this->eback(), this->gptr(), this->egptr() - this->gptr() ); - setg( this->eback(), this->eback(), this->eback() + (this->egptr() - this->gptr()) ); - } - if ( this->gptr() == _ebuf ) { // I should read something, if other side write - return -1; // otherwise I can't write without pipe broken - } - long offset = (this->*_xread)( this->egptr(), sizeof(char_type) * (_ebuf - this->egptr()) ); - if ( offset < 0 ) // allow message of zero length - return -1; - offset /= sizeof(charT); - setg( this->eback(), this->gptr(), this->egptr() + offset ); - } - - return 0; -} -#endif // 0 - -#if defined(__HP_aCC) && (__HP_aCC == 1) - union basic_sockbuf_sockaddr { - sockaddr_in inet; - sockaddr any; - }; -#endif - -template<class charT, class traits, class _Alloc> int basic_sockbuf<charT, traits, _Alloc>::recvfrom( void *buf, size_t n ) { #if defined(_WIN32) || (defined(__hpux) && !defined(_INCLUDE_POSIX1C_SOURCE)) @@ -659,20 +542,9 @@ socklen_t sz = sizeof( sockaddr_in ); #endif -#if defined(__HP_aCC) && (__HP_aCC == 1) - basic_sockbuf_sockaddr addr; -#else - union { - sockaddr_in inet; - sockaddr any; - } addr; -#endif -#ifdef __FIT_POLL - timespec t; + sockaddr_t addr; - t.tv_sec = 0; - t.tv_nsec = 10000; - +#ifdef __FIT_POLL pollfd pfd; pfd.fd = _fd; pfd.events = POLLIN; @@ -704,23 +576,14 @@ return 0; // poll wait infinite, so it can't return 0 (timeout), so it return -1. } #endif // __FIT_POLL - if ( port() == addr.inet.sin_port && inet_addr() == addr.inet.sin_addr.s_addr ) { -// if ( memcmp( (void *)&_address.any, (const void *)&addr, sizeof(sockaddr) ) == 0 ) { + if ( memcmp( &_address.inet, &addr.inet, sizeof(sockaddr_in) ) == 0 ) { #ifdef WIN32 return ::recvfrom( _fd, (char *)buf, n, 0, &_address.any, &sz ); #else return ::recvfrom( _fd, buf, n, 0, &_address.any, &sz ); #endif } -#ifdef __unix -// cerr << "Sleeping in sockstream: " -// << port() << "/" << addr.inet.sin_port << ", " -// << inet_addr() << "/" << addr.inet.sin_addr.s_addr << endl; - nanosleep( &t, 0 ); -#endif -#ifdef WIN32 - Sleep( t ); -#endif + xmt::Thread::yield(); } while ( true ); return 0; // never Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2007-09-01 05:33:23 UTC (rev 1717) +++ trunk/complement/explore/lib/sockios/ChangeLog 2007-09-01 05:45:11 UTC (rev 1718) @@ -1,3 +1,11 @@ +2007-09-01 Petr Ovtchenkov <pt...@is...> + + * sockstream: clean; add inet_sockaddr() method, that return + sockaddr_in in whole; + + * sockstream.cc: clean; replace sleep by yield in recvfrom, + but function not really in use now; + 2007-08-23 Petr Ovtchenkov <pt...@is...> * sockmgr.h: explicitly inhibit copy of basic_sockmgr and This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-09-01 05:46:37
|
Revision: 1719 http://complement.svn.sourceforge.net/complement/?rev=1719&view=rev Author: complement Date: 2007-08-31 22:46:34 -0700 (Fri, 31 Aug 2007) Log Message: ----------- add search by sockaddr_in in connections container; this useful for non-streamed connections, like UDP Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/lib/sockios/ChangeLog Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2007-09-01 05:45:11 UTC (rev 1718) +++ trunk/complement/explore/include/sockios/sockmgr.h 2007-09-01 05:46:34 UTC (rev 1719) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/11 20:57:31 ptr> +// -*- C++ -*- Time-stamp: <07/08/31 09:55:36 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -239,8 +239,8 @@ ~_Connect() { if ( _proc ) { s.close(); _proc->close(); } delete _proc; } - void open( sock_base::socket_type st, const sockaddr& addr ) - { s.open( st, addr ); _proc = new Connect( s ); } + void open( sock_base::socket_type st, const sockaddr& addr, sock_base::stype t = sock_base::sock_stream ) + { s.open( st, addr, t ); _proc = new Connect( s ); } sockstream s; Connect *_proc; @@ -262,6 +262,13 @@ { return __x.s.rdbuf()->fd() == __y; } }; + struct iaddr_equal : + public std::binary_function<_Connect,sockaddr,bool> + { + bool operator()(const _Connect& __x, const sockaddr& __y) const + { return memcmp( &(__x.s.rdbuf()->inet_sockaddr()), reinterpret_cast<const sockaddr_in *>(&__y), sizeof(sockaddr_in) ) == 0; } + }; + struct pfd_equal : public std::binary_function<typename _fd_sequence::value_type,int,bool> { @@ -287,6 +294,7 @@ protected: typedef sockmgr_stream_MP<Connect> _Self_type; typedef fd_equal _Compare; + typedef iaddr_equal _Compare_inet; typedef typename _Sequence::value_type value_type; typedef typename _Sequence::size_type size_type; typedef _Sequence container_type; @@ -296,6 +304,7 @@ _Sequence _M_c; _Compare _M_comp; + _Compare_inet _M_comp_inet; pfd_equal _pfdcomp; xmt::mutex _c_lock; Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2007-09-01 05:45:11 UTC (rev 1718) +++ trunk/complement/explore/lib/sockios/ChangeLog 2007-09-01 05:46:34 UTC (rev 1719) @@ -6,6 +6,9 @@ * sockstream.cc: clean; replace sleep by yield in recvfrom, but function not really in use now; + * sockmgr.h: add search by sockaddr_in in connections container; + this useful for non-streamed connections, like UDP. + 2007-08-23 Petr Ovtchenkov <pt...@is...> * sockmgr.h: explicitly inhibit copy of basic_sockmgr and This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-09-04 07:29:30
|
Revision: 1721 http://complement.svn.sourceforge.net/complement/?rev=1721&view=rev Author: complement Date: 2007-09-04 00:29:28 -0700 (Tue, 04 Sep 2007) Log Message: ----------- performance measure feature; libexam version 0.3.0 Modified Paths: -------------- trunk/complement/explore/include/exam/logger.h trunk/complement/explore/include/exam/suite.h trunk/complement/explore/lib/exam/ChangeLog trunk/complement/explore/lib/exam/Makefile.inc trunk/complement/explore/lib/exam/logger.cc trunk/complement/explore/lib/exam/suite.cc trunk/complement/explore/lib/exam/ut/Makefile trunk/complement/explore/lib/exam/ut/dummy_test.cc trunk/complement/explore/lib/exam/ut/exam_test_suite.cc trunk/complement/explore/lib/exam/ut/exam_test_suite.h Modified: trunk/complement/explore/include/exam/logger.h =================================================================== --- trunk/complement/explore/include/exam/logger.h 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/include/exam/logger.h 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:08:25 ptr> +// -*- C++ -*- Time-stamp: <07/09/04 10:38:27 ptr> /* * Copyright (c) 2007 @@ -13,6 +13,8 @@ #include <string> #include <cstdio> #include <ostream> +#include <mt/time.h> +#include <list> namespace exam { @@ -64,6 +66,9 @@ virtual void begin_ts() = 0; virtual void end_ts() = 0; virtual void result( const base_logger::stat&, const std::string& suite_name ) = 0; + virtual void tc_pre() = 0; + virtual void tc_post() = 0; + virtual void tc_break() = 0; virtual void tc( tc_result, const std::string& ) = 0; protected: @@ -89,13 +94,41 @@ virtual void begin_ts(); virtual void end_ts(); virtual void result( const base_logger::stat&, const std::string& ); + virtual void tc_pre() + { } + virtual void tc_post() + { } + virtual void tc_break() + { } virtual void tc( base_logger::tc_result, const std::string& ); - private: + protected: std::ostream *s; FILE *f; }; +class trivial_time_logger : + public trivial_logger +{ + public: + explicit trivial_time_logger( std::ostream& str ) : + trivial_logger( str ) + { } + + explicit trivial_time_logger( FILE *fs ) : + trivial_logger( fs ) + { } + + virtual void tc_pre(); + virtual void tc_post(); + virtual void tc_break(); + virtual void tc( base_logger::tc_result, const std::string& ); + + private: + typedef std::list<xmt::timespec> time_container_t; + time_container_t tst; +}; + } // namespace exam #endif // __logger_h Modified: trunk/complement/explore/include/exam/suite.h =================================================================== --- trunk/complement/explore/include/exam/suite.h 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/include/exam/suite.h 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:07:43 ptr> +// -*- C++ -*- Time-stamp: <07/09/04 11:08:48 ptr> /* * Copyright (c) 2007 @@ -168,8 +168,8 @@ typedef int (*func_type)( test_suite *, int ); typedef vertex_t test_case_type; - test_suite( const std::string& name ); - test_suite( const char *name ); + test_suite( const std::string& name, unsigned n = 1 ); + test_suite( const char *name, unsigned n = 1 ); ~test_suite(); test_case_type add( func_type, const std::string& name ); @@ -227,8 +227,9 @@ test_case_map_type _test; base_logger::stat _stat; std::string _suite_name; + unsigned _iterations; - void run_test_case( vertex_t v ); + void run_test_case( vertex_t v, unsigned n = 1 ); static bool vertices_compare( weight_t, weight_t ); static int _root_func( test_suite *, int = 0 ); Modified: trunk/complement/explore/lib/exam/ChangeLog =================================================================== --- trunk/complement/explore/lib/exam/ChangeLog 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/ChangeLog 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,3 +1,18 @@ +2007-09-04 Petr Ovtchenkov <pt...@is...> + + * logger.h, logger.cc: added trivial_time_logger for performance + measure; added methods tc_pre, tc_post and tc_break for run before + test case, after test case, or after exception within test case; + + * suite.h, suite.cc: add iterations number for each test-case; + this test suite -wide parameter, because mainly intended for + performance measure [statistic] and not useful for problem + detection and tracking; + + * ut/exam_test_suite.cc, ut/dummy_test.cc: test; + + * libexam: version 0.3.0. + 2007-08-03 Petr Ovtchenkov <pt...@is...> * suite.h: remove private keyword for dummy, to make gcc 3.3.6 happy. Modified: trunk/complement/explore/lib/exam/Makefile.inc =================================================================== --- trunk/complement/explore/lib/exam/Makefile.inc 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/Makefile.inc 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,7 +1,7 @@ -# -*- Makefile -*- Time-stamp: <07/07/21 09:21:58 ptr> +# -*- Makefile -*- Time-stamp: <07/09/04 11:12:48 ptr> LIBNAME = exam MAJOR = 0 -MINOR = 2 +MINOR = 3 PATCH = 0 SRC_CC = logger.cc suite.cc Modified: trunk/complement/explore/lib/exam/logger.cc =================================================================== --- trunk/complement/explore/lib/exam/logger.cc 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/logger.cc 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:09:27 ptr> +// -*- C++ -*- Time-stamp: <07/09/04 10:47:22 ptr> /* * Copyright (c) 2007 @@ -115,4 +115,51 @@ } } +void trivial_time_logger::tc_pre() +{ + tst.push_back( xmt::timespec( xmt::timespec::now ) ); +} + +void trivial_time_logger::tc_post() +{ + tst.back() = xmt::timespec( xmt::timespec::now ) - tst.back(); +} + +void trivial_time_logger::tc_break() +{ + tst.pop_back(); +} + +void trivial_time_logger::tc( base_logger::tc_result r, const std::string& name ) +{ + if ( r == pass ) { + // here tst.size() > 0, if test case not throw excepion + time_container_t::const_iterator a = tst.begin(); + if ( a != tst.end() ) { + unsigned n = 1; + double sum(*a); + double sum_sq = sum * sum; + ++a; + for ( ; a != tst.end(); ++a ) { + double v(*a); + sum += v; + sum_sq += v * v; + // mean = ((n + 1) * mean + static_cast<double>(*a)) / (n + 2); + ++n; + } + sum_sq -= sum * sum / n; + sum_sq = max( 0.0, sum_sq ); // clear epsilon (round error) + sum_sq /= n * n; // dispersion + sum /= n; // mean + if ( s != 0 ) { + *s << " " << sum << " " << sum_sq << " " << name << endl; + } else { + fprintf( f, " %f %f %s\n", sum, sum_sq, name.c_str() ); + } + } + } + tst.clear(); + trivial_logger::tc( r, name ); +} + } //namespace exam Modified: trunk/complement/explore/lib/exam/suite.cc =================================================================== --- trunk/complement/explore/lib/exam/suite.cc 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/suite.cc 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:09:43 ptr> +// -*- C++ -*- Time-stamp: <07/09/04 11:10:58 ptr> /* * Copyright (c) 2007 @@ -29,11 +29,12 @@ return -1; } -test_suite::test_suite( const string& name ) : +test_suite::test_suite( const string& name, unsigned n ) : _count(0), _last_state( 0 ), _suite_name( name ), - local_logger( logger ) + local_logger( logger ), + _iterations( n ) { _vertices.push_back( std::make_pair( 0, 0 ) ); _test[0].tc = detail::make_test_case( detail::call( _root_func ) ); @@ -43,11 +44,12 @@ _stack.push( this ); } -test_suite::test_suite( const char *name ) : +test_suite::test_suite( const char *name, unsigned n ) : _count(0), _last_state( 0 ), _suite_name( name ), - local_logger( logger ) + local_logger( logger ), + _iterations( n ) { _vertices.push_back( std::make_pair( 0, 0 ) ); _test[0].tc = detail::make_test_case( detail::call( _root_func ) ); @@ -97,7 +99,7 @@ _test[j->second].state = skip; } } - run_test_case( i->first ); + run_test_case( i->first, _iterations ); } local_logger->end_ts(); @@ -203,12 +205,22 @@ _stack.top()->report( file, line, cnd, expr ); } -void test_suite::run_test_case( test_suite::vertex_t v ) +void test_suite::run_test_case( test_suite::vertex_t v, unsigned n ) { try { ++_stat.total; if ( _test[v].state == 0 ) { - if ( (*_test[v].tc)( this, 0 ) == 0 ) { + int res = 0; + while ( (res == 0) && (n-- > 0) ) { + _lock_ll.lock(); + local_logger->tc_pre(); + _lock_ll.unlock(); + res = (*_test[v].tc)( this, 0 ); + _lock_ll.lock(); + local_logger->tc_post(); + _lock_ll.unlock(); + } + if ( res == 0 ) { if ( _last_state == 0 ) { ++_stat.passed; scoped_lock lk( _lock_ll ); @@ -234,12 +246,16 @@ } } catch ( init_exception& ) { + _lock_ll.lock(); + local_logger->tc_break(); + _lock_ll.unlock(); --_stat.total; } catch ( ... ) { ++_stat.failed; _test[v].state = fail; scoped_lock lk( _lock_ll ); + local_logger->tc_break(); local_logger->tc( base_logger::fail, _test[v].name ); } } Modified: trunk/complement/explore/lib/exam/ut/Makefile =================================================================== --- trunk/complement/explore/lib/exam/ut/Makefile 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/ut/Makefile 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/08/03 22:53:39 ptr> +# -*- Makefile -*- Time-stamp: <07/09/03 22:27:45 ptr> SRCROOT := ../../.. @@ -9,23 +9,24 @@ DEFS += -D__FIT_EXAM LIBEXAM_DIR = ${CoMT_DIR}/lib/exam +LIBXMT_DIR = ${CoMT_DIR}/lib/mt LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR} ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L$(LIBXMT_DIR)/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:$(LIBXMT_DIR)/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif -release-shared : LDLIBS = -lexam -dbg-shared : LDLIBS = -lexamg +release-shared : LDLIBS = -lexam -lxmt +dbg-shared : LDLIBS = -lexamg -lxmtg ifndef WITHOUT_STLPORT -stldbg-shared : LDLIBS = -lexamstlg +stldbg-shared : LDLIBS = -lexamstlg -lxmtstlg endif Modified: trunk/complement/explore/lib/exam/ut/dummy_test.cc =================================================================== --- trunk/complement/explore/lib/exam/ut/dummy_test.cc 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/ut/dummy_test.cc 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:10:32 ptr> +// -*- C++ -*- Time-stamp: <07/09/03 22:22:09 ptr> /* * Copyright (c) 2007 @@ -57,3 +57,14 @@ return EXAM_RESULT; } + +int EXAM_IMPL(loop) +{ + int j = 0; + for ( int i = 0; i < 100000; ++i ) { + j += 2; + } + + return EXAM_RESULT; +} + Modified: trunk/complement/explore/lib/exam/ut/exam_test_suite.cc =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.cc 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.cc 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:10:55 ptr> +// -*- C++ -*- Time-stamp: <07/09/04 11:11:41 ptr> /* * Copyright (c) 2007 @@ -8,6 +8,7 @@ */ #include "exam_test_suite.h" +#include <iostream> #include "dummy_test.cc" @@ -243,6 +244,40 @@ return EXAM_RESULT; } +int EXAM_IMPL(exam_basic_test::perf) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t( "exam self test, time profile", 20 ); + t.set_logger( &tlogger ); + + t.add( loop, "timer" ); + + t.girdle(); + + double mean = -1.0; + double disp = -1.0; + std::string nm; + + buff >> mean >> disp; // >> nm; + + EXAM_CHECK( mean >= 0.0 ); + EXAM_CHECK( disp >= 0.0 ); + + std::getline( buff, nm ); + + EXAM_CHECK( nm == " timer" ); + + std::getline( buff, nm ); + + EXAM_CHECK( nm == "*** PASS exam self test, time profile (+1-0~0/1) ***" ); + + // std::cerr << buff.str() << std::endl; + + return EXAM_RESULT; +} + const std::string exam_basic_test::r0 = "\ *** PASS exam self test, good function (+2-0~0/2) ***\n"; @@ -325,5 +360,7 @@ exam::test_suite::test_case_type d2 = t.add( &exam_basic_test::multiple_dep, exam_basic, "multiple dependencies", d ); t.add( &exam_basic_test::multiple_dep_complex, exam_basic, "complex multiple dependencies", d2 ); + t.add( &exam_basic_test::perf, exam_basic, "performance timer test", d0 ); + return t.girdle(); } Modified: trunk/complement/explore/lib/exam/ut/exam_test_suite.h =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.h 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.h 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:11:13 ptr> +// -*- C++ -*- Time-stamp: <07/09/03 22:21:36 ptr> /* * Copyright (c) 2007 @@ -16,34 +16,38 @@ class exam_basic_test { - public: - exam_basic_test() : - buff(), - logger( buff ) - { } + public: + exam_basic_test() : + buff(), + logger( buff ), + tlogger( buff ) + { } - int EXAM_DECL(function_good); - int EXAM_DECL(function); - int EXAM_DECL(dep); - int EXAM_DECL(trace); - int EXAM_DECL(dep_test_suite); - int EXAM_DECL(multiple_dep); - int EXAM_DECL(multiple_dep_complex); + int EXAM_DECL(function_good); + int EXAM_DECL(function); + int EXAM_DECL(dep); + int EXAM_DECL(trace); + int EXAM_DECL(dep_test_suite); + int EXAM_DECL(multiple_dep); + int EXAM_DECL(multiple_dep_complex); + int EXAM_DECL(perf); private: - std::stringstream buff; - exam::trivial_logger logger; + std::stringstream buff; + exam::trivial_logger logger; + exam::trivial_time_logger tlogger; + - static const std::string r0; - static const std::string r1; - static const std::string r2; - static const std::string r3; - static const std::string r4; - static const std::string r5; - static const std::string r6; - static const std::string r7; - static const std::string r8; - static const std::string r9; + static const std::string r0; + static const std::string r1; + static const std::string r2; + static const std::string r3; + static const std::string r4; + static const std::string r5; + static const std::string r6; + static const std::string r7; + static const std::string r8; + static const std::string r9; }; int EXAM_DECL(exam_self_test); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-09-05 11:10:45
|
Revision: 1722 http://complement.svn.sourceforge.net/complement/?rev=1722&view=rev Author: complement Date: 2007-09-05 04:10:42 -0700 (Wed, 05 Sep 2007) Log Message: ----------- looks like non-POD return from thread is unstable, and should be avoided; replace union rec_code by void * or long, depends upon operation environment Modified Paths: -------------- trunk/complement/explore/include/mt/xmt.h trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/include/stem/Cron.h trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/include/stem/NetTransport.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/ut/flck.cc trunk/complement/explore/lib/mt/ut/lfs.cc trunk/complement/explore/lib/mt/ut/mt_test.cc trunk/complement/explore/lib/mt/ut/mt_test.h trunk/complement/explore/lib/mt/ut/mt_test_suite.cc trunk/complement/explore/lib/mt/ut/signal-1.cc trunk/complement/explore/lib/mt/ut/signal-2.cc trunk/complement/explore/lib/mt/ut/signal-3.cc trunk/complement/explore/lib/mt/xmt.cc trunk/complement/explore/lib/sockios/ChangeLog trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.cc trunk/complement/explore/lib/sockios/ut/sockios_test.cc trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/Cron.cc trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/lib/stem/ut/unit_test.cc Modified: trunk/complement/explore/include/mt/xmt.h =================================================================== --- trunk/complement/explore/include/mt/xmt.h 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/include/mt/xmt.h 2007-09-05 11:10:42 UTC (rev 1722) @@ -1377,13 +1377,14 @@ class Thread { public: - union ret_code - { - void *pword; - long iword; - }; +#ifdef _PTHREADS + typedef void * ret_t; +#endif +#ifdef __FIT_WIN32THREADS + typedef long ret_t; +#endif - typedef ret_code (*entrance_type)( void * ); + typedef ret_t (*entrance_type)( void * ); #ifdef __FIT_WIN32THREADS typedef unsigned long thread_key_type; typedef HANDLE thread_id_type; @@ -1444,7 +1445,7 @@ __FIT_DECLSPEC void launch( entrance_type entrance, const void *p = 0, size_t psz = 0, size_t stack_sz = 0 ); - __FIT_DECLSPEC ret_code join(); + __FIT_DECLSPEC ret_t join(); __FIT_DECLSPEC int suspend(); __FIT_DECLSPEC int resume(); __FIT_DECLSPEC int kill( int sig ); Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/11 21:14:42 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 00:54:04 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -258,14 +258,71 @@ template <class Connect> bool sockmgr_stream_MP<Connect>::accept_udp() { -#if 0 if ( !is_open() ) { return false; } + _xsockaddr addr; socklen_t sz = sizeof( sockaddr_in ); - _xsockaddr addr; + bool _in_buf; + do { + _in_buf = false; + _pfd[0].revents = 0; + _pfd[1].revents = 0; + while ( poll( &_pfd[0], /* _pfd.size() */ 1, -1 ) < 0 ) { // wait infinite + if ( errno == EINTR ) { // may be interrupted, check and ignore + errno = 0; + continue; + } + return false; // poll wait infinite, so it can't return 0 (timeout), so it return -1. + } + + // New connction open before data read from opened sockets. + // This policy may be worth to revise. + + if ( (_pfd[0].revents & POLLERR) != 0 /* || (_pfd[1].revents & POLLERR) != 0 */ ) { + return false; // return 0 only for binded socket, or control socket + } + + if ( _pfd[0].revents != 0 ) { + xmt::scoped_lock lk(_fd_lck); + if ( !is_open_unsafe() ) { // may be already closed + return false; + } + // poll found event on binded socket + // get address of caller only + char buff[65535]; + ::recvfrom( fd(), buff, 65535, MSG_PEEK, &addr.any, &sz ); + try { + xmt::scoped_lock _l( _c_lock ); + // if addr.any pesent in _M_c + typename container_type::iterator i = + find_if( _M_c.begin(), _M_c.end(), bind2nd( _M_comp_inet, addr.any ) ); + if ( i == _M_c.end() ) { + _M_c.push_back( _Connect() ); + _M_c.back().open( fd(), addr.any, sock_base::sock_dgram ); + _Connect *cl_new = &_M_c.back(); + } + // + // ... + // + } + catch ( ... ) { + } + } +#if 0 + if ( _pfd[1].revents != 0 ) { // fd come back for poll + pollfd rfd; + ::read( _pfd[1].fd, reinterpret_cast<char *>(&rfd.fd), sizeof(sock_base::socket_type) ); + rfd.events = POLLIN; + rfd.revents = 0; + _pfd.push_back( rfd ); + } +#endif + } while ( /* !_shift_fd() && */ !_in_buf ); + +#if 0 if ( poll( &_pfd[0], 1, -1 ) < 0 ) { // wait infinite return false; // poll wait infinite, so it can't return 0 (timeout), so it return -1. } @@ -316,14 +373,12 @@ } template <class Connect> -xmt::Thread::ret_code sockmgr_stream_MP<Connect>::loop( void *p ) +xmt::Thread::ret_t sockmgr_stream_MP<Connect>::loop( void *p ) { _Self_type *me = static_cast<_Self_type *>(p); me->loop_id.pword( _idx ) = me; // push pointer to self for signal processing - xmt::Thread::ret_code rtc; - xmt::Thread::ret_code rtc_observer; - rtc.iword = 0; - rtc_observer.iword = 0; + xmt::Thread::ret_t rtc = 0; + xmt::Thread::ret_t rtc_observer = 0; xmt::Thread thr_observer; @@ -336,8 +391,8 @@ if ( thr_observer.bad() ) { if ( thr_observer.is_join_req() ) { rtc_observer = thr_observer.join(); - if ( rtc_observer.iword != 0 ) { - rtc.iword = -2; // there was connect_processor that was killed + if ( rtc_observer != 0 ) { + rtc = reinterpret_cast<xmt::Thread::ret_t>(-2); // there was connect_processor that was killed } } thr_observer.launch( observer, me, 0, PTHREAD_STACK_MIN * 2 ); @@ -345,7 +400,7 @@ } } catch ( ... ) { - rtc.iword = -1; + rtc = reinterpret_cast<xmt::Thread::ret_t>(-1); } xmt::block_signal( SIGINT ); @@ -367,19 +422,18 @@ rtc_observer = thr_observer.join(); me->_M_c.clear(); // FIN still may not come yet; force close - if ( rtc_observer.iword != 0 && rtc.iword == 0 ) { - rtc.iword = -2; // there was connect_processor that was killed + if ( rtc_observer != 0 && rtc == 0 ) { + rtc = reinterpret_cast<xmt::Thread::ret_t>(-2); // there was connect_processor that was killed } return rtc; } template <class Connect> -xmt::Thread::ret_code sockmgr_stream_MP<Connect>::connect_processor( void *p ) +xmt::Thread::ret_t sockmgr_stream_MP<Connect>::connect_processor( void *p ) { _Self_type *me = static_cast<_Self_type *>(p); - xmt::Thread::ret_code rtc; - rtc.iword = 0; + xmt::Thread::ret_t rtc = 0; try { timespec idle( me->_idle ); @@ -449,18 +503,17 @@ } while ( me->_is_follow() && idle_count < 2 ); } catch ( ... ) { - rtc.iword = -1; + rtc = reinterpret_cast<xmt::Thread::ret_t>(-1); } return rtc; } template <class Connect> -xmt::Thread::ret_code sockmgr_stream_MP<Connect>::observer( void *p ) +xmt::Thread::ret_t sockmgr_stream_MP<Connect>::observer( void *p ) { _Self_type *me = static_cast<_Self_type *>(p); - xmt::Thread::ret_code rtc; - rtc.iword = 0; + xmt::Thread::ret_t rtc = 0; int pool_size[3]; // size_t thr_pool_size[3]; timespec tpop; @@ -518,11 +571,11 @@ } if ( mgr.size() > 0 ) { mgr.signal( SIGTERM ); - rtc.iword = -1; + rtc = reinterpret_cast<xmt::Thread::ret_t>(-1); } } catch ( ... ) { - rtc.iword = -1; + rtc = reinterpret_cast<xmt::Thread::ret_t>(-1); } return rtc; @@ -802,14 +855,11 @@ } template <class Connect> -xmt::Thread::ret_code sockmgr_stream_MP_SELECT<Connect>::loop( void *p ) +xmt::Thread::ret_t sockmgr_stream_MP_SELECT<Connect>::loop( void *p ) { _Self_type *me = static_cast<_Self_type *>(p); me->loop_id.pword( _idx ) = me; // push pointer to self for signal processing - xmt::Thread::ret_code rtc; - rtc.iword = 0; - try { _Connect *s; unsigned _sfd; @@ -843,8 +893,8 @@ } me->close(); me->_c_lock.unlock(); - rtc.iword = -1; - return rtc; + + return reinterpret_cast<xmt::Thread::ret_t>(-1); // throw; } @@ -863,7 +913,7 @@ me->close(); me->_c_lock.unlock(); - return rtc; + return 0; } #endif // !__FIT_NO_SELECT Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/include/sockios/sockmgr.h 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/31 09:55:36 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 00:45:19 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -251,9 +251,9 @@ typedef std::deque<typename _Sequence::iterator> _connect_pool_sequence; void _open( sock_base::stype t = sock_base::sock_stream ); - static xmt::Thread::ret_code loop( void * ); - static xmt::Thread::ret_code connect_processor( void * ); - static xmt::Thread::ret_code observer( void * ); + static xmt::Thread::ret_t loop( void * ); + static xmt::Thread::ret_t connect_processor( void * ); + static xmt::Thread::ret_t observer( void * ); struct fd_equal : public std::binary_function<_Connect,int,bool> @@ -391,7 +391,7 @@ protected: void _open( sock_base::stype t = sock_base::sock_stream ); - static xmt::Thread::ret_code loop( void * ); + static xmt::Thread::ret_t loop( void * ); struct _Connect { sockstream *s; Modified: trunk/complement/explore/include/stem/Cron.h =================================================================== --- trunk/complement/explore/include/stem/Cron.h 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/include/stem/Cron.h 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/11 21:20:12 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 01:08:54 ptr> /* * Copyright (c) 1998, 2002, 2003, 2005, 2007 @@ -152,7 +152,7 @@ __FIT_DECLSPEC void EmptyStop(); private: - static xmt::Thread::ret_code _loop( void * ); + static xmt::Thread::ret_t _loop( void * ); xmt::Thread _thr; xmt::condition cond; Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/include/stem/EvManager.h 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/11 21:17:27 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 01:09:05 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -239,7 +239,7 @@ const addr_type _x_high; addr_type _x_id; - static xmt::Thread::ret_code _Dispatch( void * ); + static xmt::Thread::ret_t _Dispatch( void * ); bool not_finished(); Modified: trunk/complement/explore/include/stem/NetTransport.h =================================================================== --- trunk/complement/explore/include/stem/NetTransport.h 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/include/stem/NetTransport.h 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/13 13:22:52 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 01:10:17 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -97,14 +97,14 @@ virtual __FIT_DECLSPEC void close(); int join() - { return _thr.join().iword; } + { return reinterpret_cast<int>(_thr.join()); } private: NetTransportMgr( const NetTransportMgr& ); NetTransportMgr& operator =( const NetTransportMgr& ); protected: - static xmt::Thread::ret_code _loop( void * ); + static xmt::Thread::ret_t _loop( void * ); xmt::Thread _thr; std::sockstream _channel; }; Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,3 +1,17 @@ +2007-09-05 Petr Ovtchenkov <pt...@is...> + + * xmt.h, xmt.cc: looks like non-POD return from thread is unstable, + and should be avoided; replace union rec_code by void * or long, + depends upon operation environment; + + * ut/signal-1.cc, ut/signal-2.cc, ut/signal-3.cc: ditto; + + * ut/flck.cc, ut/mt_test.cc, ut/mt_test.h: ditto; + + * ut/lfs.cc, ut/mt_test_suite.cc: ditto; + + * libxmt: version 1.12.0 + 2007-08-27 Petr Ovtchenkov <pt...@is...> * shm.h: use namespace std for max. Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/mt/Makefile.inc 2007-09-05 11:10:42 UTC (rev 1722) @@ -2,7 +2,7 @@ LIBNAME = xmt MAJOR = 1 -MINOR = 11 +MINOR = 12 PATCH = 0 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/ut/flck.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/flck.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/mt/ut/flck.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/16 21:34:09 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 00:00:06 ptr> /* * Copyright (c) 2004, 2006, 2007 @@ -30,11 +30,8 @@ static mutex b; static int cnt = 0; -static Thread::ret_code thread_func( void * ) +static Thread::ret_t thread_func( void * ) { - Thread::ret_code rt; - rt.iword = 0; - try { for ( int count = 0; count < 10; ++count ) { int fd = open( fname, O_RDWR | O_CREAT | O_APPEND, 00666 ); @@ -83,17 +80,14 @@ b.lock(); BOOST_MESSAGE( "* The error returned: " << check << ", errno " << errno ); b.unlock(); - rt.iword = -1; + return reinterpret_cast<Thread::ret_t>(-1); } - return rt; + return 0; } -static Thread::ret_code thread_func_r( void * ) +static Thread::ret_t thread_func_r( void * ) { - Thread::ret_code rt; - rt.iword = 0; - char buf[64]; // buf[14] = 0; int ln = 0; @@ -200,10 +194,10 @@ b.lock(); BOOST_MESSAGE( "* The error returned: " << check << ", errno " << errno << ' ' << buf ); b.unlock(); - rt.iword = -1; + return reinterpret_cast<Thread::ret_t>(-1); } - return rt; + return 0; } int EXAM_IMPL(flock_test) Modified: trunk/complement/explore/lib/mt/ut/lfs.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/lfs.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/mt/ut/lfs.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/16 21:33:58 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 00:01:28 ptr> /* * Copyright (c) 2004, 2006, 2007 @@ -31,11 +31,8 @@ static int cnt = 0; static condition cnd; -static Thread::ret_code thread_func( void * ) +static Thread::ret_t thread_func( void * ) { - Thread::ret_code rt; - rt.iword = 0; - try { for ( int count = 0; count < 10; ++count ) { olfstream s( fname, ios_base::out | ios_base::app ); @@ -75,17 +72,14 @@ } catch ( ... ) { BOOST_REQUIRE( false ); - rt.iword = -1; + return reinterpret_cast<Thread::ret_t>(-1); } - return rt; + return 0; } -static Thread::ret_code thread_func_r( void * ) +static Thread::ret_t thread_func_r( void * ) { - Thread::ret_code rt; - rt.iword = 0; - try { string buf; int ln = 0; @@ -141,17 +135,14 @@ b.lock(); BOOST_REQUIRE( false ); b.unlock(); - rt.iword = -1; + return reinterpret_cast<Thread::ret_t>(-1); } - return rt; + return 0; } -static Thread::ret_code thread_func_manip( void * ) +static Thread::ret_t thread_func_manip( void * ) { - Thread::ret_code rt; - rt.iword = 0; - for ( int count = 0; count < 10; ++count ) { olfstream s( fname, ios_base::out | ios_base::app ); @@ -183,14 +174,11 @@ s.close(); } - return rt; + return 0; } -static Thread::ret_code thread_func_manip_r( void * ) +static Thread::ret_t thread_func_manip_r( void * ) { - Thread::ret_code rt; - rt.iword = 0; - string buf; cnd.try_wait(); @@ -232,7 +220,7 @@ s.close(); } - return rt; + return 0; } int EXAM_IMPL(lfs_test) Modified: trunk/complement/explore/lib/mt/ut/mt_test.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/mt/ut/mt_test.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/06 10:03:33 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 00:31:04 ptr> /* * Copyright (c) 2006, 2007 @@ -46,14 +46,11 @@ static int x = 0; -xmt::Thread::ret_code thread_entry_call( void * ) +xmt::Thread::ret_t thread_entry_call( void * ) { x = 1; - xmt::Thread::ret_code rt; - rt.iword = 2; - - return rt; + return reinterpret_cast<xmt::Thread::ret_t>(2); } int EXAM_IMPL(mt_test::join_test) @@ -62,7 +59,7 @@ xmt::Thread t( thread_entry_call ); - EXAM_CHECK( t.join().iword == 2 ); + EXAM_CHECK( reinterpret_cast<int>(t.join()) == 2 ); EXAM_CHECK( x == 1 ); @@ -73,15 +70,12 @@ * Start two threads, align ones on barrier, join. */ -xmt::Thread::ret_code thread2_entry_call( void *p ) +xmt::Thread::ret_t thread2_entry_call( void *p ) { - xmt::Thread::ret_code rt; - rt.iword = 1; - xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); - return rt; + return reinterpret_cast<xmt::Thread::ret_t>(1); } int EXAM_IMPL(mt_test::barrier2) @@ -91,8 +85,9 @@ xmt::Thread t1( thread2_entry_call, &b ); xmt::Thread t2( thread2_entry_call, &b ); - EXAM_CHECK( t2.join().iword == 1 ); - EXAM_CHECK( t1.join().iword == 1 ); + EXAM_CHECK( reinterpret_cast<int>(t2.join()) == 1 ); + // std::cerr << t2.join() << std::endl; + EXAM_CHECK( reinterpret_cast<int>(t1.join()) == 1 ); return EXAM_RESULT; } @@ -102,16 +97,13 @@ * relinquish control to other; join (within Thread dtors) */ -xmt::Thread::ret_code thread3_entry_call( void *p ) +xmt::Thread::ret_t thread3_entry_call( void *p ) { - xmt::Thread::ret_code rt; - rt.iword = 0; - xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); EXAM_CHECK_ASYNC( xmt::Thread::yield() == 0 ); - return rt; + return 0; } int EXAM_IMPL(mt_test::yield) @@ -139,7 +131,7 @@ static xmt::mutex m1; -xmt::Thread::ret_code thr1( void *p ) +xmt::Thread::ret_t thr1( void *p ) { xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); @@ -154,13 +146,10 @@ m1.unlock(); - xmt::Thread::ret_code rt; - rt.iword = 0; - - return rt; + return 0; } -xmt::Thread::ret_code thr2( void *p ) +xmt::Thread::ret_t thr2( void *p ) { xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); @@ -173,10 +162,7 @@ x = 2; m1.unlock(); - xmt::Thread::ret_code rt; - rt.iword = 0; - - return rt; + return 0; } int EXAM_IMPL(mt_test::mutex_test) @@ -208,7 +194,7 @@ #ifdef __FIT_PTHREAD_SPINLOCK static xmt::spinlock sl1; -xmt::Thread::ret_code thr1s( void *p ) +xmt::Thread::ret_t thr1s( void *p ) { xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); @@ -223,13 +209,10 @@ sl1.unlock(); - xmt::Thread::ret_code rt; - rt.iword = 0; - - return rt; + return 0; } -xmt::Thread::ret_code thr2s( void *p ) +xmt::Thread::ret_t thr2s( void *p ) { xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); @@ -242,10 +225,7 @@ x = 2; sl1.unlock(); - xmt::Thread::ret_code rt; - rt.iword = 0; - - return rt; + return 0; } #endif @@ -309,7 +289,7 @@ m2.unlock(); } -xmt::Thread::ret_code thr1r( void *p ) +xmt::Thread::ret_t thr1r( void *p ) { xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); @@ -326,14 +306,10 @@ m2.unlock(); - xmt::Thread::ret_code rt; - - rt.iword = 0; - - return rt; + return 0; } -xmt::Thread::ret_code thr2r( void *p ) +xmt::Thread::ret_t thr2r( void *p ) { xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); @@ -351,11 +327,7 @@ m2.unlock(); - xmt::Thread::ret_code rt; - - rt.iword = 0; - - return rt; + return 0; } int EXAM_IMPL(mt_test::recursive_mutex_test) @@ -926,21 +898,18 @@ static int my_thr_scnt = 0; static xmt::mutex lock; -xmt::Thread::ret_code thread_mgr_entry_call( void * ) +xmt::Thread::ret_t thread_mgr_entry_call( void * ) { lock.lock(); ++my_thr_cnt; ++my_thr_scnt; lock.unlock(); - xmt::Thread::ret_code rt; - rt.iword = 0; - lock.lock(); --my_thr_cnt; lock.unlock(); - return rt; + return 0; } int EXAM_IMPL(mt_test::thr_mgr) Modified: trunk/complement/explore/lib/mt/ut/mt_test.h =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test.h 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/mt/ut/mt_test.h 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/16 21:01:43 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 00:02:19 ptr> /* * Copyright (c) 2006, 2007 @@ -32,7 +32,7 @@ int EXAM_DECL(thr_mgr); private: - // static xmt::Thread::ret_code thread_entry_call( void * ); + // static xmt::Thread::ret_t thread_entry_call( void * ); // static int x; }; Modified: trunk/complement/explore/lib/mt/ut/mt_test_suite.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/17 10:20:08 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 00:29:06 ptr> /* * Copyright (c) 2006, 2007 @@ -62,28 +62,5 @@ t.add( &shm_test::shm_segment, shmtest, "mt_test::shm_segment" ) ) ) ) ); - // add( barrier_tc, 0, 2 ); - // add( join_tc ); - // add( barrier2_tc, 0, 3 ); - // add( yield_tc, 0, 3 ); - // add( mutex_test_tc, 0, 3 ); -#ifdef __FIT_PTHREAD_SPINLOCK - // add( spinlock_test_tc, 0, 3 ); -#endif - // add( recursive_mutex_test_tc, 0, 3 ); - - // add( fork_tc ); - // add( pid_tc ); - // add( shm_segment_tc ); - // add( shm_alloc_tc ); - // add( fork_shm_tc, 0, 5 ); - // add( shm_nm_obj_tc, 0, 5 ); - - // add( thr_mgr_tc ); - - // add( shm_init_tc ); - // add( shm_nm_obj_more_tc ); - // add( shm_finit_tc ); - return t.girdle(); }; Modified: trunk/complement/explore/lib/mt/ut/signal-1.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/signal-1.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/mt/ut/signal-1.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/17 09:49:18 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 00:03:41 ptr> /* * Copyright (c) 2003, 2006, 2007 @@ -23,8 +23,8 @@ * handler (within thread 1): v == 1?; v = 4 */ -static Thread::ret_code thread_one( void * ); -static Thread::ret_code thread_two( void * ); +static Thread::ret_t thread_one( void * ); +static Thread::ret_t thread_two( void * ); static Thread *th_one = 0; static Thread *th_two = 0; @@ -54,7 +54,7 @@ } } -Thread::ret_code thread_one( void * ) +Thread::ret_t thread_one( void * ) { xmt::unblock_signal( SIGINT ); // we wait this signal // Default handler make exit() call: @@ -68,13 +68,10 @@ th_one->kill( SIGINT ); // send signal SIGINT to self - Thread::ret_code rt; - rt.iword = 0; - - return rt; + return 0; } -Thread::ret_code thread_two( void * ) +Thread::ret_t thread_two( void * ) { cnd.set( false ); @@ -89,10 +86,7 @@ EXAM_CHECK_ASYNC( v == 4 ); - Thread::ret_code rt; - rt.iword = 0; - - return rt; + return 0; } int EXAM_IMPL(signal_1_test) Modified: trunk/complement/explore/lib/mt/ut/signal-2.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/signal-2.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/mt/ut/signal-2.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/16 21:34:49 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 00:04:38 ptr> /* * Copyright (c) 2003, 2006, 2007 @@ -17,8 +17,8 @@ using namespace std; using namespace xmt; -static Thread::ret_code thread_one( void * ); -static Thread::ret_code thread_two( void * ); +static Thread::ret_t thread_one( void * ); +static Thread::ret_t thread_two( void * ); static Thread *th_one = 0; static Thread *th_two = 0; @@ -40,11 +40,8 @@ } } -Thread::ret_code thread_one( void * ) +Thread::ret_t thread_one( void * ) { - Thread::ret_code rt; - rt.iword = 0; - try { xmt::unblock_signal( SIGINT ); // we wait this signal // I set own handler, that throw signal: @@ -77,10 +74,10 @@ v = 5; } - return rt; + return 0; } -Thread::ret_code thread_two( void * ) +Thread::ret_t thread_two( void * ) { try { // pm.lock(); @@ -108,10 +105,7 @@ // v = 5; } - Thread::ret_code rt; - rt.iword = 0; - - return rt; + return 0; } int EXAM_IMPL(signal_2_test) Modified: trunk/complement/explore/lib/mt/ut/signal-3.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/signal-3.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/mt/ut/signal-3.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/17 09:50:35 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 00:05:31 ptr> /* * Copyright (c) 2003, 2006, 2007 @@ -28,8 +28,8 @@ * */ -static Thread::ret_code thread_one( void * ); -static Thread::ret_code thread_two( void * ); +static Thread::ret_t thread_one( void * ); +static Thread::ret_t thread_two( void * ); static Thread *th_one = 0; static Thread *th_two = 0; @@ -59,7 +59,7 @@ } } -Thread::ret_code thread_one( void * ) +Thread::ret_t thread_one( void * ) { EXAM_CHECK_ASYNC( v == 1 ); @@ -67,13 +67,10 @@ th_two->kill( SIGINT ); // send signal SIGINT to self - Thread::ret_code rt; - rt.iword = 0; - - return rt; + return 0; } -Thread::ret_code thread_two( void * ) +Thread::ret_t thread_two( void * ) { xmt::signal_handler( SIGINT, handler ); xmt::block_signal( SIGINT ); // block signal @@ -90,10 +87,7 @@ EXAM_CHECK_ASYNC( v == 4 ); - Thread::ret_code rt; - rt.iword = 0; - - return rt; + return 0; } int EXAM_IMPL(signal_3_test) Modified: trunk/complement/explore/lib/mt/xmt.cc =================================================================== --- trunk/complement/explore/lib/mt/xmt.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/mt/xmt.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -397,28 +397,26 @@ } __FIT_DECLSPEC -Thread::ret_code Thread::join() +Thread::ret_t Thread::join() { - ret_code rt; + ret_t rt = 0; #ifdef __FIT_WIN32THREADS - rt.iword = 0; if ( !_not_run() ) { WaitForSingleObject( _id, -1 ); - GetExitCodeThread( _id, &rt.iword ); + GetExitCodeThread( _id, &rt ); CloseHandle( _id ); // Locker lk( _llock ); _id = bad_thread_id; } #endif // __FIT_WIN32THREADS #if defined(__FIT_UITHREADS) || defined(_PTHREADS) - rt.pword = 0; if ( is_join_req() ) { # ifdef _PTHREADS - pthread_join( _rip_id, &rt.pword ); + pthread_join( _rip_id, &rt ); # endif # ifdef __FIT_UITHREADS - thr_join( _rip_id, 0, &rt.pword ); + thr_join( _rip_id, 0, &rt ); # endif // Locker lk( _llock ); _rip_id = bad_thread_id; @@ -509,14 +507,10 @@ void Thread::_exit( int code ) { #ifdef _PTHREADS - ret_code v; - v.iword = code; - pthread_exit( v.pword ); + pthread_exit( reinterpret_cast<ret_t>(code) ); #endif #ifdef __FIT_UITHREADS - ret_code v; - v.iword = code; - thr_exit( v.pword ); + thr_exit( reinterpret_cast<ret_t>(code) ); #endif #ifdef __FIT_WIN32THREADS ExitThread( code ); @@ -786,7 +780,7 @@ // of me->_entrance!!! void *_param = me->_param; size_t _param_sz = me->_param_sz; - ret_code ret; + ret_t ret = 0; //#ifdef _PTHREADS //# ifndef __hpux @@ -846,7 +840,7 @@ #ifndef _WIN32 cerr << e.what() << endl; #endif - ret.iword = -1; + ret = reinterpret_cast<ret_t>(-1); } catch ( int sig ) { if ( (me->_flags & (daemon | detached)) != 0 ) { // otherwise join expected @@ -866,7 +860,7 @@ #ifndef _WIN32 cerr << "\n--- Thread: signal " << sig /* (_sig_ ? _sig_ : "unknown") */ << " detected ---" << endl; #endif - ret.iword = sig; + ret = reinterpret_cast<ret_t>(sig); } catch ( ... ) { if ( (me->_flags & (daemon | detached)) != 0 ) { // otherwise join expected @@ -884,7 +878,7 @@ #ifndef _WIN32 cerr << "\n--- Thread: unknown exception occur ---" << endl; #endif - ret.iword = -1; + ret = reinterpret_cast<ret_t>(-1); } try { @@ -895,14 +889,14 @@ } } catch ( ... ) { - ret.iword = -1; + ret = reinterpret_cast<ret_t>(-1); } #if defined( __SUNPRO_CC ) && defined( __i386 ) - Thread::_exit( ret.iword ); + Thread::_exit( ret ); #endif - return ret.pword; + return ret; } #ifdef _WIN32 #pragma warning( default : 4101 ) Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/sockios/ChangeLog 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,3 +1,11 @@ +2007-09-05 Petr Ovtchenkov <pt...@is...> + + * sockmgr.h, sockmgr.cc: looks like non-POD return from thread is + unstable, and should be avoided; replace union rec_code by void * + or long, depends upon operation environment; + + * ut/ConnectionProcessor.cc, ut/sockios_test.cc: ditto. + 2007-09-01 Petr Ovtchenkov <pt...@is...> * sockstream: clean; add inet_sockaddr() method, that return Modified: trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/18 23:10:22 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 00:39:10 ptr> /* * @@ -384,10 +384,9 @@ static srv_type *srv_p; condition cnd; -Thread::ret_code server_proc( void * ) +Thread::ret_t server_proc( void * ) { - Thread::ret_code rt; - rt.iword = 0; + unsigned rt = 0; cnd.set( false ); srv_type srv( port ); // start server @@ -395,20 +394,19 @@ ::srv_p = &srv; if ( !srv.is_open() || !srv.good() ) { - ++rt.iword; + ++rt; } cnd.set( true ); srv.wait(); - return rt; + return reinterpret_cast<Thread::ret_t>(rt); } -Thread::ret_code client_proc( void * ) +Thread::ret_t client_proc( void * ) { - Thread::ret_code rt; - rt.iword = 0; + unsigned rt = 0; cnd.try_wait(); @@ -420,7 +418,7 @@ getline( sock, buf ); if ( !sock.is_open() || !sock.good() ) { - ++rt.iword; + ++rt; } EXAM_CHECK_ASYNC( buf == "hello" ); @@ -445,7 +443,7 @@ EXAM_MESSAGE_ASYNC( "Client end" ); - return rt; + return reinterpret_cast<Thread::ret_t>(rt); } int EXAM_IMPL(trivial_sockios_test::srv_close_connection) @@ -454,8 +452,8 @@ cnd_close.set( false ); Thread client( client_proc ); - EXAM_CHECK( client.join().iword == 0 ); - EXAM_CHECK( srv.join().iword == 0 ); + EXAM_CHECK( client.join() == 0 ); + EXAM_CHECK( srv.join() == 0 ); return EXAM_RESULT; } @@ -519,11 +517,8 @@ std::sockstream *psock = 0; -Thread::ret_code thread_entry_call( void * ) +Thread::ret_t thread_entry_call( void * ) { - Thread::ret_code rt; - rt.iword = 0; - cnd.set( true ); EXAM_MESSAGE_ASYNC( "Client start" ); @@ -536,7 +531,7 @@ cnd_close.set( true ); psock->read( &c, 1 ); - return rt; + return 0; } int EXAM_IMPL(trivial_sockios_test::client_close_socket) Modified: trunk/complement/explore/lib/sockios/ut/sockios_test.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios_test.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/sockios/ut/sockios_test.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/18 09:22:46 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 00:44:02 ptr> /* * @@ -177,12 +177,8 @@ { } -xmt::Thread::ret_code client_thr( void *p ) +xmt::Thread::ret_t client_thr( void *p ) { - xmt::Thread::ret_code ret; - - ret.iword = 0; - sockstream s( "localhost", port ); char buf[1024]; @@ -200,7 +196,7 @@ xmt::Thread::yield(); } - return ret; + return 0; } void sigpipe_handler( int sig, siginfo_t *si, void * ) @@ -459,9 +455,8 @@ // pr_lock.unlock(); } -xmt::Thread::ret_code thread_entry( void *par ) +xmt::Thread::ret_t thread_entry( void *par ) { - xmt::Thread::ret_code rt; xmt::condition& cnd = *reinterpret_cast<xmt::condition *>(par); // sem.wait(); // wait server for listen us @@ -475,8 +470,7 @@ EXAM_CHECK_ASYNC( buff == 1 ); // cerr << "Read pass" << endl; - rt.iword = 0; - return rt; + return 0; } int EXAM_IMPL(sockios_test::read0) @@ -531,6 +525,8 @@ catch ( xmt::shm_bad_alloc& err ) { EXAM_ERROR( err.what() ); } + + return EXAM_RESULT; } /* ************************************************************ */ Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/stem/ChangeLog 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,3 +1,11 @@ +2007-09-05 Petr Ovtchenkov <pt...@is...> + + * Cron.h, NetTransport.h, EvManager.h: looks like non-POD return + from thread is unstable, and should be avoided; replace union + rec_code by void * or long, depends upon operation environment; + + * Cron.cc, NetTransport.cc, EvManager.cc, ut/unit_test.cc: idem. + 2007-08-25 Petr Ovtchenkov <pt...@is...> * EvManager.h, NetTransport.cc: use ostream and trace flags Modified: trunk/complement/explore/lib/stem/Cron.cc =================================================================== --- trunk/complement/explore/lib/stem/Cron.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/stem/Cron.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/15 03:12:28 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 01:04:08 ptr> /* * Copyright (c) 1998, 2002, 2003, 2005, 2006 @@ -172,7 +172,7 @@ // do nothing } -xmt::Thread::ret_code Cron::_loop( void *p ) +xmt::Thread::ret_t Cron::_loop( void *p ) { // After creation cron loop (one per every Cron object), // this loop should exit in following cases: @@ -182,9 +182,6 @@ // after Add (Cron entry) event. Cron& me = *reinterpret_cast<Cron *>(p); - xmt::Thread::ret_code rt; - rt.iword = 0; - me.PushState( CRON_ST_STARTED ); timespec abstime; @@ -235,7 +232,7 @@ } } - return rt; + return 0; } Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/stem/EvManager.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/17 22:22:13 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 01:04:58 ptr> /* * @@ -75,11 +75,9 @@ return !_dispatch_stop; } -xmt::Thread::ret_code EvManager::_Dispatch( void *p ) +xmt::Thread::ret_t EvManager::_Dispatch( void *p ) { 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; @@ -102,7 +100,7 @@ } } - return rt; + return 0; } __FIT_DECLSPEC Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/03/12 17:25:23 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 01:06:19 ptr> /* * @@ -437,12 +437,10 @@ join(); } -xmt::Thread::ret_code NetTransportMgr::_loop( void *p ) +xmt::Thread::ret_t NetTransportMgr::_loop( void *p ) { NetTransportMgr& me = *reinterpret_cast<NetTransportMgr *>(p); Event ev; - xmt::Thread::ret_code rt; - rt.iword = 0; gaddr_type dst; gaddr_type src; @@ -501,10 +499,10 @@ catch ( ... ) { me.NetTransport_base::close(); // throw; - rt.iword = -1; + return reinterpret_cast<xmt::Thread::ret_t>(-1); } - return rt; + return 0; } __FIT_DECLSPEC Modified: trunk/complement/explore/lib/stem/ut/unit_test.cc =================================================================== --- trunk/complement/explore/lib/stem/ut/unit_test.cc 2007-09-04 07:29:28 UTC (rev 1721) +++ trunk/complement/explore/lib/stem/ut/unit_test.cc 2007-09-05 11:10:42 UTC (rev 1722) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/20 00:21:37 ptr> +// -*- C++ -*- Time-stamp: <07/09/05 01:08:18 ptr> /* * Copyright (c) 2002, 2003, 2006, 2007 @@ -62,8 +62,8 @@ int EXAM_DECL(boring_manager); int EXAM_DECL(convert); - static xmt::Thread::ret_code thr1( void * ); - static xmt::Thread::ret_code thr1new( void * ); + static xmt::Thread::ret_t thr1( void * ); + static xmt::Thread::ret_t thr1new( void * ); private: }; @@ -89,7 +89,7 @@ xmt::Thread t1( thr1 ); - EXAM_CHECK( t1.join().iword == 0 ); + EXAM_CHECK( t1.join() == 0 ); node.wait(); @@ -98,11 +98,8 @@ return EXAM_RESULT; } -xmt::Thread::ret_code stem_test::thr1( void * ) +xmt::Thread::ret_t stem_test::thr1( void * ) { - xmt::Thread::ret_code rt; - rt.iword = 0; - Node node( 2001 ); EDS::Event ev( NODE_EV1 ); @@ -110,7 +107,7 @@ ev.dest( 2000 ); node.Send( ev ); - return rt; + return 0; } int EXAM_IMPL(stem_test::basic1new) @@ -145,11 +142,8 @@ return EXAM_RESULT; } -xmt::Thread::ret_code stem_test::thr1new( void * ) +xmt::Thread::ret_t stem_test::thr1new( void * ) { - xmt::Thread::ret_code rt; - rt.iword = 0; - NewNode *node = new NewNode( 2001 ); EDS::Event ev( NODE_EV1 ); @@ -159,7 +153,7 @@ delete node; - return rt; + return 0; } int EXAM_IMPL(stem_test::dl) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-09-07 10:53:31
|
Revision: 1724 http://complement.svn.sourceforge.net/complement/?rev=1724&view=rev Author: complement Date: 2007-09-07 03:53:27 -0700 (Fri, 07 Sep 2007) Log Message: ----------- allow any name of functions for 'connect' and 'close' procedures in template parametric class Connect Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/lib/sockios/ChangeLog Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2007-09-07 10:52:21 UTC (rev 1723) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2007-09-07 10:53:27 UTC (rev 1724) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/05 00:54:04 ptr> +// -*- C++ -*- Time-stamp: <07/09/06 21:32:15 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -26,8 +26,8 @@ #ifndef __FIT_NO_POLL -template <class Connect> -void sockmgr_stream_MP<Connect>::_open( sock_base::stype t ) +template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > +void sockmgr_stream_MP<Connect,C,T>::_open( sock_base::stype t ) { xmt::scoped_lock lk(_fd_lck); if ( is_open_unsafe() ) { @@ -68,29 +68,29 @@ } } -template <class Connect> -void sockmgr_stream_MP<Connect>::open( const in_addr& addr, int port, sock_base::stype t ) +template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > +void sockmgr_stream_MP<Connect,C,T>::open( const in_addr& addr, int port, sock_base::stype t ) { basic_sockmgr::open( addr, port, t, sock_base::inet ); - sockmgr_stream_MP<Connect>::_open( t ); + sockmgr_stream_MP<Connect,C,T>::_open( t ); } -template <class Connect> -void sockmgr_stream_MP<Connect>::open( unsigned long addr, int port, sock_base::stype t ) +template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > +void sockmgr_stream_MP<Connect,C,T>::open( unsigned long addr, int port, sock_base::stype t ) { basic_sockmgr::open( addr, port, t, sock_base::inet ); - sockmgr_stream_MP<Connect>::_open( t ); + sockmgr_stream_MP<Connect,C,T>::_open( t ); } -template <class Connect> -void sockmgr_stream_MP<Connect>::open( int port, sock_base::stype t ) +template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > +void sockmgr_stream_MP<Connect,C,T>::open( int port, sock_base::stype t ) { basic_sockmgr::open( port, t, sock_base::inet ); - sockmgr_stream_MP<Connect>::_open( t ); + sockmgr_stream_MP<Connect,C,T>::_open( t ); } -template <class Connect> -bool sockmgr_stream_MP<Connect>::_shift_fd() +template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > +bool sockmgr_stream_MP<Connect,C,T>::_shift_fd() { bool ret = false; typename iterator_traits<typename _fd_sequence::iterator>::difference_type d; @@ -173,8 +173,8 @@ return ret; } -template <class Connect> -bool sockmgr_stream_MP<Connect>::accept_tcp() +template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > +bool sockmgr_stream_MP<Connect,C,T>::accept_tcp() { if ( !is_open() ) { return false; @@ -255,8 +255,8 @@ return true; // something was pushed in connection queue (by _shift_fd) } -template <class Connect> -bool sockmgr_stream_MP<Connect>::accept_udp() +template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > +bool sockmgr_stream_MP<Connect,C,T>::accept_udp() { if ( !is_open() ) { return false; @@ -359,8 +359,8 @@ return true /* cl */; } -template <class Connect> -void sockmgr_stream_MP<Connect>::_close_by_signal( int ) +template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > +void sockmgr_stream_MP<Connect,C,T>::_close_by_signal( int ) { #ifdef _PTHREADS void *_uw_save = *((void **)pthread_getspecific( xmt::Thread::mtkey() ) + _idx ); @@ -372,8 +372,8 @@ #endif } -template <class Connect> -xmt::Thread::ret_t sockmgr_stream_MP<Connect>::loop( void *p ) +template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > +xmt::Thread::ret_t sockmgr_stream_MP<Connect,C,T>::loop( void *p ) { _Self_type *me = static_cast<_Self_type *>(p); me->loop_id.pword( _idx ) = me; // push pointer to self for signal processing @@ -429,8 +429,8 @@ return rtc; } -template <class Connect> -xmt::Thread::ret_t sockmgr_stream_MP<Connect>::connect_processor( void *p ) +template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > +xmt::Thread::ret_t sockmgr_stream_MP<Connect,C,T>::connect_processor( void *p ) { _Self_type *me = static_cast<_Self_type *>(p); xmt::Thread::ret_t rtc = 0; @@ -454,7 +454,7 @@ if (_non_empty ) { sockstream& stream = c->s; if ( stream.is_open() ) { - c->_proc->connect( stream ); + (c->_proc->*C)( stream ); if ( stream.is_open() && stream.good() ) { if ( stream.rdbuf()->in_avail() > 0 ) { // socket has buffered data, push it back to queue @@ -509,8 +509,8 @@ return rtc; } -template <class Connect> -xmt::Thread::ret_t sockmgr_stream_MP<Connect>::observer( void *p ) +template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > +xmt::Thread::ret_t sockmgr_stream_MP<Connect,C,T>::observer( void *p ) { _Self_type *me = static_cast<_Self_type *>(p); xmt::Thread::ret_t rtc = 0; Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2007-09-07 10:52:21 UTC (rev 1723) +++ trunk/complement/explore/include/sockios/sockmgr.h 2007-09-07 10:53:27 UTC (rev 1724) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/05 00:45:19 ptr> +// -*- C++ -*- Time-stamp: <07/09/06 21:23:52 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -135,7 +135,7 @@ #ifndef __FIT_NO_POLL -template <class Connect> +template <class Connect, void (Connect::*C)( std::sockstream& ) = &Connect::connect, void (Connect::*T)() = &Connect::close > class sockmgr_stream_MP : public basic_sockmgr { @@ -195,8 +195,8 @@ { loop_id.join(); } private: - sockmgr_stream_MP( const sockmgr_stream_MP<Connect>& ); - sockmgr_stream_MP<Connect>& operator =( const sockmgr_stream_MP<Connect>& ); + sockmgr_stream_MP( const sockmgr_stream_MP<Connect,C,T>& ); + sockmgr_stream_MP<Connect,C,T>& operator =( const sockmgr_stream_MP<Connect,C,T>& ); public: void open( const in_addr& addr, int port, sock_base::stype t = sock_base::sock_stream ); @@ -237,7 +237,7 @@ { } ~_Connect() - { if ( _proc ) { s.close(); _proc->close(); } delete _proc; } + { if ( _proc ) { s.close(); (_proc->*T)(); } delete _proc; } void open( sock_base::socket_type st, const sockaddr& addr, sock_base::stype t = sock_base::sock_stream ) { s.open( st, addr, t ); _proc = new Connect( s ); } @@ -276,7 +276,7 @@ { return __x.fd == __y; } }; - typedef bool (sockmgr_stream_MP<Connect>::*accept_type)(); + typedef bool (sockmgr_stream_MP<Connect,C,T>::*accept_type)(); #if 0 accept_type _accept; @@ -292,7 +292,7 @@ xmt::Thread loop_id; protected: - typedef sockmgr_stream_MP<Connect> _Self_type; + typedef sockmgr_stream_MP<Connect,C,T> _Self_type; typedef fd_equal _Compare; typedef iaddr_equal _Compare_inet; typedef typename _Sequence::value_type value_type; Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2007-09-07 10:52:21 UTC (rev 1723) +++ trunk/complement/explore/lib/sockios/ChangeLog 2007-09-07 10:53:27 UTC (rev 1724) @@ -1,3 +1,8 @@ +2007-09-06 Petr Ovtchenkov <pt...@is...> + + * sockmgr.h, sockmgr.cc: allow any name of functions for 'connect' + and 'close' procedures in template parametric class Connect. + 2007-09-05 Petr Ovtchenkov <pt...@is...> * sockmgr.h, sockmgr.cc: looks like non-POD return from thread is This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-09-07 11:03:35
|
Revision: 1726 http://complement.svn.sourceforge.net/complement/?rev=1726&view=rev Author: complement Date: 2007-09-07 04:03:24 -0700 (Fri, 07 Sep 2007) Log Message: ----------- added macro EXAM_CHECK_ASYNC_F, EXAM_ERROR_ASYNC_F Modified Paths: -------------- trunk/complement/explore/include/exam/suite.h trunk/complement/explore/lib/exam/ChangeLog trunk/complement/explore/lib/mt/ut/mt_test.cc trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.cc Modified: trunk/complement/explore/include/exam/suite.h =================================================================== --- trunk/complement/explore/include/exam/suite.h 2007-09-07 10:54:55 UTC (rev 1725) +++ trunk/complement/explore/include/exam/suite.h 2007-09-07 11:03:24 UTC (rev 1726) @@ -324,24 +324,28 @@ # define EXAM_RESULT __exam_counter # define EXAM_CHECK(C) if ( !(C) ) { __exam_ts->report( __FILE__, __LINE__, false, #C ); __exam_counter |= 1; } else __exam_ts->report( __FILE__, __LINE__, true, #C ) # define EXAM_CHECK_ASYNC(C) if ( !(C) ) { exam::test_suite::report_async( __FILE__, __LINE__, false, #C ); } else exam::test_suite::report_async( __FILE__, __LINE__, true, #C ) +# define EXAM_CHECK_ASYNC_F(C,V) if ( !(C) ) { exam::test_suite::report_async( __FILE__, __LINE__, false, #C ); V |= 1; } else exam::test_suite::report_async( __FILE__, __LINE__, true, #C ) # define EXAM_MESSAGE(M) __exam_ts->report( __FILE__, __LINE__, true, M ) # define EXAM_MESSAGE_ASYNC(M) exam::test_suite::report_async( __FILE__, __LINE__, true, M ) # define EXAM_REQUIRE(C) if ( !(C) ) { __exam_ts->report( __FILE__, __LINE__, false, #C ); return 1; } else __exam_ts->report( __FILE__, __LINE__, true, #C ) # define EXAM_FAIL(M) __exam_ts->report( __FILE__, __LINE__, false, M ); return 1 # define EXAM_ERROR(M) __exam_ts->report( __FILE__, __LINE__, false, M ); __exam_counter |= 1 # define EXAM_ERROR_ASYNC(M) exam::test_suite::report_async( __FILE__, __LINE__, false, M ) +# define EXAM_ERROR_ASYNC_F(M,V) exam::test_suite::report_async( __FILE__, __LINE__, false, M ); V |= 1 #else # define EXAM_IMPL(F) F( exam::test_suite *, int ) # define EXAM_DECL(F) F( exam::test_suite *, int = 0 ) # define EXAM_RESULT 0 # define EXAM_CHECK(C) (C) # define EXAM_CHECK_ASYNC(C) (C) +# define EXAM_CHECK_ASYNC_F(C,V) (C) # define EXAM_MESSAGE(M) # define EXAM_MESSAGE_ASYNC(M) # define EXAM_REQUIRE(C) (C) # define EXAM_FAIL(M) # define EXAM_ERROR(M) # define EXAM_ERROR_ASYNC(M) +# define EXAM_ERROR_ASYNC_F(M,V) #endif Modified: trunk/complement/explore/lib/exam/ChangeLog =================================================================== --- trunk/complement/explore/lib/exam/ChangeLog 2007-09-07 10:54:55 UTC (rev 1725) +++ trunk/complement/explore/lib/exam/ChangeLog 2007-09-07 11:03:24 UTC (rev 1726) @@ -1,3 +1,10 @@ +2007-09-07 Petr Ovtchenkov <pt...@is...> + + * suite.h: added macro EXAM_CHECK_ASYNC_F, EXAM_ERROR_ASYNC_F + that useful to set passed value to non-zero; useful for non-zero + exit status after fork or thread [may be checked in parent process + or thread]. + 2007-09-04 Petr Ovtchenkov <pt...@is...> * logger.h, logger.cc: added trivial_time_logger for performance Modified: trunk/complement/explore/lib/mt/ut/mt_test.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test.cc 2007-09-07 10:54:55 UTC (rev 1725) +++ trunk/complement/explore/lib/mt/ut/mt_test.cc 2007-09-07 11:03:24 UTC (rev 1726) @@ -99,11 +99,12 @@ xmt::Thread::ret_t thread3_entry_call( void *p ) { + int flag = 0; xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); - EXAM_CHECK_ASYNC( xmt::Thread::yield() == 0 ); + EXAM_CHECK_ASYNC_F( xmt::Thread::yield() == 0, flag ); - return 0; + return reinterpret_cast<xmt::Thread::ret_t>(flag); } int EXAM_IMPL(mt_test::yield) @@ -133,24 +134,27 @@ xmt::Thread::ret_t thr1( void *p ) { + int flag = 0; + xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); m1.lock(); - EXAM_CHECK_ASYNC( x == 0 ); + EXAM_CHECK_ASYNC_F( x == 0, flag ); xmt::Thread::yield(); - EXAM_CHECK_ASYNC( x == 0 ); + EXAM_CHECK_ASYNC_F( x == 0, flag ); x = 1; m1.unlock(); - return 0; + return reinterpret_cast<xmt::Thread::ret_t>(flag); } xmt::Thread::ret_t thr2( void *p ) { + int flag = 0; xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); for ( int i = 0; i < 128; ++i ) { @@ -158,11 +162,11 @@ } m1.lock(); - EXAM_CHECK_ASYNC( x == 1 ); + EXAM_CHECK_ASYNC_F( x == 1, flag ); x = 2; m1.unlock(); - return 0; + return reinterpret_cast<xmt::Thread::ret_t>(flag); } int EXAM_IMPL(mt_test::mutex_test) @@ -173,8 +177,8 @@ xmt::Thread t1( thr1, &b ); xmt::Thread t2( thr2, &b ); - t1.join(); - t2.join(); + EXAM_CHECK( t1.join() == 0 ); + EXAM_CHECK( t2.join() == 0 ); EXAM_CHECK( x == 2 ); @@ -196,24 +200,26 @@ xmt::Thread::ret_t thr1s( void *p ) { + int flag = 0; xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); sl1.lock(); - EXAM_CHECK_ASYNC( x == 0 ); + EXAM_CHECK_ASYNC_F( x == 0, flag ); xmt::Thread::yield(); - EXAM_CHECK_ASYNC( x == 0 ); + EXAM_CHECK_ASYNC_F( x == 0, flag ); x = 1; sl1.unlock(); - return 0; + return reinterpret_cast<xmt::Thread::ret_t>(flag); } xmt::Thread::ret_t thr2s( void *p ) { + int flag = 0; xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); for ( int i = 0; i < 128; ++i ) { @@ -221,11 +227,11 @@ } sl1.lock(); - EXAM_CHECK_ASYNC( x == 1 ); + EXAM_CHECK_ASYNC_F( x == 1, flag ); x = 2; sl1.unlock(); - return 0; + return reinterpret_cast<xmt::Thread::ret_t>(flag); } #endif @@ -239,8 +245,8 @@ xmt::Thread t1( thr1s, &b ); xmt::Thread t2( thr2s, &b ); - t1.join(); - t2.join(); + EXAM_CHECK( t1.join() == 0 ); + EXAM_CHECK( t2.join() == 0 ); EXAM_CHECK( x == 2 ); #endif @@ -291,26 +297,28 @@ xmt::Thread::ret_t thr1r( void *p ) { + int flag = 0; xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); m2.lock(); - EXAM_CHECK_ASYNC( x == 0 ); + EXAM_CHECK_ASYNC_F( x == 0, flag ); x = 1; xmt::Thread::yield(); - EXAM_CHECK_ASYNC( x == 1 ); + EXAM_CHECK_ASYNC_F( x == 1, flag ); recursive(); - EXAM_CHECK_ASYNC( x == 2 ); + EXAM_CHECK_ASYNC_F( x == 2, flag ); x = 3; m2.unlock(); - return 0; + return reinterpret_cast<xmt::Thread::ret_t>(flag); } xmt::Thread::ret_t thr2r( void *p ) { + int flag = 0; xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); @@ -320,14 +328,14 @@ m2.lock(); - EXAM_CHECK_ASYNC( x == 3 ); + EXAM_CHECK_ASYNC_F( x == 3, flag ); xmt::Thread::yield(); recursive(); - EXAM_CHECK_ASYNC( x == 2 ); + EXAM_CHECK_ASYNC_F( x == 2, flag ); m2.unlock(); - return 0; + return reinterpret_cast<xmt::Thread::ret_t>(flag); } int EXAM_IMPL(mt_test::recursive_mutex_test) @@ -338,8 +346,8 @@ xmt::Thread t1( thr1r, &b ); xmt::Thread t2( thr2r, &b ); - t1.join(); - t2.join(); + EXAM_CHECK( t1.join() == 0 ); + EXAM_CHECK( t2.join() == 0 ); EXAM_CHECK( x == 2 ); @@ -388,8 +396,13 @@ fcnd.set( true ); - int stat; + int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + } else { + EXAM_ERROR( "child interrupted" ); + } } catch ( ... ) { } @@ -432,10 +445,12 @@ try { xmt::fork(); + int flag = 0; + try { // Child code - EXAM_CHECK_ASYNC( my_pid == xmt::getppid() ); + EXAM_CHECK_ASYNC_F( my_pid == xmt::getppid(), flag ); *reinterpret_cast<pid_t *>(static_cast<char *>(buf) + sizeof(xmt::__condition<true>)) = xmt::getpid(); fcnd.set( true ); @@ -444,7 +459,7 @@ catch ( ... ) { } - exit( 0 ); + exit( flag ); } catch ( xmt::fork_in_parent& child ) { try { @@ -454,8 +469,13 @@ EXAM_CHECK( *reinterpret_cast<pid_t *>(static_cast<char *>(buf) + sizeof(xmt::__condition<true>)) == child.pid() ); - int stat; + int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + } else { + EXAM_ERROR( "child interrupted" ); + } } catch ( ... ) { } @@ -656,8 +676,13 @@ fcnd.set( true ); - int stat; + int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + } else { + EXAM_ERROR( "child interrupted" ); + } } catch ( ... ) { } @@ -701,6 +726,8 @@ try { xmt::fork(); + int eflag = 0; + try { // Child code @@ -719,16 +746,16 @@ fcnd_ch.set( true ); } catch ( const xmt::shm_bad_alloc& err ) { - EXAM_ERROR_ASYNC( err.what() ); + EXAM_ERROR_ASYNC_F( err.what(), eflag ); } catch ( const std::invalid_argument& err ) { - EXAM_ERROR_ASYNC( err.what() ); + EXAM_ERROR_ASYNC_F( err.what(), eflag ); } catch ( ... ) { - EXAM_ERROR_ASYNC( "Fail in child" ); + EXAM_ERROR_ASYNC_F( "Fail in child", eflag ); } - exit( 0 ); + exit( eflag ); } catch ( xmt::fork_in_parent& child ) { try { @@ -736,8 +763,13 @@ fcnd.try_wait(); - int stat; + int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + } else { + EXAM_ERROR( "child interrupted" ); + } } catch ( ... ) { EXAM_ERROR( "Fail in parent" ); @@ -802,6 +834,8 @@ try { xmt::fork(); + int eflag = 0; + try { xmt::shm_name_mgr<1>& nm_ch = seg1.name_mgr(); xmt::allocator_shm<xmt::__condition<true>,1> shm_ch; @@ -810,14 +844,19 @@ nm_ch.release<xmt::__condition<true> >( ObjName ); } catch ( const std::invalid_argument& err ) { - EXAM_ERROR_ASYNC( err.what() ); + EXAM_ERROR_ASYNC_F( err.what(), eflag ); } - exit( 0 ); + exit( eflag ); } catch ( xmt::fork_in_parent& child ) { fcnd.try_wait(); - int stat; + int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + } else { + EXAM_ERROR( "child interrupted" ); + } } nm.release<xmt::__condition<true> >( ObjName ); // fcnd should be destroyed here @@ -828,6 +867,8 @@ try { xmt::fork(); + int eflag = 0; + try { xmt::shm_name_mgr<1>& nm_ch = seg1.name_mgr(); xmt::allocator_shm<xmt::__condition<true>,1> shm_ch; @@ -836,15 +877,20 @@ nm_ch.release<xmt::__condition<true> >( ObjName ); } catch ( const std::invalid_argument& err ) { - EXAM_ERROR_ASYNC( err.what() ); + EXAM_ERROR_ASYNC_F( err.what(), eflag ); } - exit( 0 ); + exit( eflag ); } catch ( xmt::fork_in_parent& child ) { fcnd1.try_wait(); - int stat; + int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + } else { + EXAM_ERROR( "child interrupted" ); + } } nm.release<xmt::__condition<true> >( ObjName ); // fcnd should be destroyed here @@ -856,6 +902,7 @@ try { xmt::fork(); + int eflag = 0; try { xmt::shm_name_mgr<1>& nm_ch = seg1.name_mgr(); xmt::allocator_shm<xmt::__barrier<true>,1> shm_ch; @@ -864,15 +911,20 @@ nm_ch.release<xmt::__barrier<true> >( ObjName ); } catch ( const std::invalid_argument& err ) { - EXAM_ERROR_ASYNC( err.what() ); + EXAM_ERROR_ASYNC_F( err.what(), eflag ); } - exit( 0 ); + exit( eflag ); } catch ( xmt::fork_in_parent& child ) { b.wait(); - int stat; + int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + } else { + EXAM_ERROR( "child interrupted" ); + } } nm.release<xmt::__barrier<true> >( ObjName ); // barrier should be destroyed here } Modified: trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.cc 2007-09-07 10:54:55 UTC (rev 1725) +++ trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.cc 2007-09-07 11:03:24 UTC (rev 1726) @@ -393,9 +393,7 @@ ::srv_p = &srv; - if ( !srv.is_open() || !srv.good() ) { - ++rt; - } + EXAM_CHECK_ASYNC_F( srv.is_open() && srv.good(), rt ); cnd.set( true ); @@ -417,11 +415,9 @@ getline( sock, buf ); - if ( !sock.is_open() || !sock.good() ) { - ++rt; - } + EXAM_CHECK_ASYNC_F( sock.is_open() && sock.good(), rt ); - EXAM_CHECK_ASYNC( buf == "hello" ); + EXAM_CHECK_ASYNC_F( buf == "hello", rt ); // xmt::delay( xmt::timespec( 5, 0 ) ); @@ -437,7 +433,7 @@ char a; sock.read( &a, 1 ); - EXAM_CHECK_ASYNC( !sock.good() ); + EXAM_CHECK_ASYNC_F( !sock.good(), rt ); srv_p->close(); @@ -519,19 +515,20 @@ Thread::ret_t thread_entry_call( void * ) { + int eflag = 0; cnd.set( true ); EXAM_MESSAGE_ASYNC( "Client start" ); - EXAM_CHECK_ASYNC( psock->good() ); + EXAM_CHECK_ASYNC_F( psock->good(), eflag ); char c = '0'; psock->read( &c, 1 ); - EXAM_CHECK_ASYNC( c == '1' ); + EXAM_CHECK_ASYNC_F( c == '1', eflag ); cnd_close.set( true ); psock->read( &c, 1 ); - return 0; + return reinterpret_cast<xmt::Thread::ret_t>(eflag); } int EXAM_IMPL(trivial_sockios_test::client_close_socket) @@ -555,7 +552,7 @@ // but call shutdown is what you want here: psock->rdbuf()->shutdown( sock_base::stop_in | sock_base::stop_out ); psock->close(); - thr.join(); + EXAM_CHECK( thr.join() == 0 ); delete psock; srv.close(); // close server, so we don't wait server termination on next line This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-09-07 12:49:01
|
Revision: 1728 http://complement.svn.sourceforge.net/complement/?rev=1728&view=rev Author: complement Date: 2007-09-07 05:48:58 -0700 (Fri, 07 Sep 2007) Log Message: ----------- prepare for __FIT_NONBLOCK_SOCKETS Modified Paths: -------------- trunk/complement/explore/include/sockios/sockstream trunk/complement/explore/include/sockios/sockstream.cc trunk/complement/explore/lib/sockios/ChangeLog Modified: trunk/complement/explore/include/sockios/sockstream =================================================================== --- trunk/complement/explore/include/sockios/sockstream 2007-09-07 11:07:26 UTC (rev 1727) +++ trunk/complement/explore/include/sockios/sockstream 2007-09-07 12:48:58 UTC (rev 1728) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/31 09:49:58 ptr> +// -*- C++ -*- Time-stamp: <07/09/06 23:42:19 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -18,6 +18,10 @@ #include <config/feature.h> #endif +#if !defined(__sun) && !defined(_WIN32) // i.e. __linux and __hpux +#include <sys/poll.h> // pollfd +#endif + #ifndef __XMT_H #include <mt/xmt.h> #endif @@ -538,23 +542,7 @@ return this; } - virtual int sync() - { - if ( !is_open() ) { - return -1; - } - - long count = this->pptr() - this->pbase(); - if ( count ) { - // _STLP_ASSERT( this->pbase() != 0 ); - if ( (this->*_xwrite)( this->pbase(), sizeof(charT) * count ) != count * sizeof(charT) ) - return -1; - setp( this->pbase(), this->epptr() ); // require: set pptr - } - - return 0; - } - + virtual int sync(); virtual streamsize xsputn(const char_type *s, streamsize n); public: @@ -565,9 +553,11 @@ charT* _ebuf; bool _allocated; // true, if _bbuf should be deallocated #ifdef __FIT_POLL + pollfd pfd; int _timeout; // milliseconds #endif #ifdef __FIT_SELECT + fd_set pfd; struct timeval _timeout; struct timeval *_timeout_ref; #endif Modified: trunk/complement/explore/include/sockios/sockstream.cc =================================================================== --- trunk/complement/explore/include/sockios/sockstream.cc 2007-09-07 11:07:26 UTC (rev 1727) +++ trunk/complement/explore/include/sockios/sockstream.cc 2007-09-07 12:48:58 UTC (rev 1728) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/08/21 23:58:48 ptr> +// -*- C++ -*- Time-stamp: <07/09/06 23:48:33 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -15,10 +15,6 @@ extern "C" int nanosleep(const struct timespec *, struct timespec *); #endif -#if !defined(__sun) && !defined(_WIN32) // i.e. __linux and __hpux -#include <sys/poll.h> // pollfd -#endif - #if defined(__unix) && !defined(__UCLIBC__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) # include <stropts.h> // for ioctl() call #endif @@ -103,6 +99,15 @@ throw std::length_error( "can't allocate block" ); } +#ifdef __FIT_NONBLOCK_SOCKETS + if ( fcntl( _fd, F_SETFL, fcntl( _fd, F_GETFL ) | O_NONBLOCK ) != 0 ) { + throw std::runtime_error( "can't establish nonblock mode" ); + } +#endif +#ifdef __FIT_POLL + pfd.fd = _fd; + pfd.events = POLLIN | POLLHUP | POLLRDNORM; +#endif setp( _bbuf, _bbuf + ((_ebuf - _bbuf)>>1) ); setg( this->epptr(), this->epptr(), this->epptr() ); @@ -217,6 +222,15 @@ throw std::length_error( "can't allocate block" ); } +#ifdef __FIT_NONBLOCK_SOCKETS + if ( fcntl( _fd, F_SETFL, fcntl( _fd, F_GETFL ) | O_NONBLOCK ) != 0 ) { + throw std::runtime_error( "can't establish nonblock mode" ); + } +#endif +#ifdef __FIT_POLL + pfd.fd = _fd; + pfd.events = POLLIN | POLLHUP | POLLRDNORM; +#endif setp( _bbuf, _bbuf + ((_ebuf - _bbuf)>>1) ); setg( this->epptr(), this->epptr(), this->epptr() ); @@ -334,6 +348,15 @@ return 0; } +#ifdef __FIT_NONBLOCK_SOCKETS + if ( fcntl( _fd, F_SETFL, fcntl( _fd, F_GETFL ) | O_NONBLOCK ) != 0 ) { + throw std::runtime_error( "can't establish nonblock mode" ); + } +#endif +#ifdef __FIT_POLL + pfd.fd = _fd; + pfd.events = POLLIN | POLLHUP | POLLRDNORM; +#endif setp( _bbuf, _bbuf + ((_ebuf - _bbuf)>>1) ); setg( this->epptr(), this->epptr(), this->epptr() ); @@ -424,8 +447,8 @@ if ( this->gptr() < this->egptr() ) return traits::to_int_type(*this->gptr()); -#ifdef __FIT_SELECT - fd_set pfd; +#ifndef __FIT_NONBLOCK_SOCKETS +# ifdef __FIT_SELECT FD_ZERO( &pfd ); FD_SET( fd(), &pfd ); @@ -436,16 +459,10 @@ } return traits::eof(); } -#endif // __FIT_SELECT -#ifdef __FIT_POLL - pollfd pfd; - pfd.fd = fd(); - pfd.events = POLLIN | POLLHUP | POLLRDNORM; +# endif // __FIT_SELECT +# ifdef __FIT_POLL pfd.revents = 0; - if ( !is_open() /* || (_state != ios_base::goodbit) */ ) { - return traits::eof(); - } while ( poll( &pfd, 1, _timeout ) <= 0 ) { // wait infinite if ( errno == EINTR ) { // may be interrupted, check and ignore errno = 0; @@ -457,17 +474,52 @@ // _state |= ios_base::failbit; return traits::eof(); } -#endif // __FIT_POLL +# endif // __FIT_POLL +#endif // !__FIT_NONBLOCK_SOCKETS + long offset = (this->*_xread)( this->eback(), sizeof(char_type) * (_ebuf - this->eback()) ); +#ifdef __FIT_NONBLOCK_SOCKETS + if ( offset < 0 && errno == EAGAIN ) { + errno = 0; +# ifdef __FIT_SELECT + FD_ZERO( &pfd ); + FD_SET( fd(), &pfd ); - // _STLP_ASSERT( this->eback() != 0 ); - // _STLP_ASSERT( _ebuf != 0 ); + while ( select( fd() + 1, &pfd, 0, 0, _timeout_ref ) <= 0 ) { + if ( errno == EINTR ) { // may be interrupted, check and ignore + errno = 0; + continue; + } + return traits::eof(); + } +# endif // __FIT_SELECT +# ifdef __FIT_POLL + pfd.revents = 0; - long offset = (this->*_xread)( this->eback(), sizeof(char_type) * (_ebuf - this->eback()) ); - // don't allow message of zero length: - // in conjunction with POLLIN in revent of poll above this designate that - // we receive FIN packet. - if ( offset <= 0 ) + while ( poll( &pfd, 1, _timeout ) <= 0 ) { // wait infinite + if ( errno == EINTR ) { // may be interrupted, check and ignore + errno = 0; + continue; + } + return traits::eof(); + } + if ( (pfd.revents & POLLERR) != 0 ) { + // _state |= ios_base::failbit; + return traits::eof(); + } +# endif // __FIT_POLL + offset = (this->*_xread)( this->eback(), sizeof(char_type) * (_ebuf - this->eback()) ); + } +#endif // __FIT_NONBLOCK_SOCKETS + // Without __FIT_NONBLOCK_SOCKETS: + // don't allow message of zero length: + // in conjunction with POLLIN in revent of poll above this designate that + // we receive FIN packet. + // With __FIT_NONBLOCK_SOCKETS: + // 0 is eof, < 0 --- second read also return < 0, but shouldn't + if ( offset <= 0 ) { return traits::eof(); + } + offset /= sizeof(charT); setg( this->eback(), this->eback(), this->eback() + offset ); @@ -490,8 +542,52 @@ long count = this->pptr() - this->pbase(); if ( count ) { - if ( (this->*_xwrite)( this->pbase(), sizeof(charT) * count ) != count * sizeof(charT) ) + count *= sizeof(charT); +#ifndef __FIT_NONBLOCK_SOCKETS + if ( (this->*_xwrite)( this->pbase(), count ) != count ) { return traits::eof(); + } +#else + long offset = (this->*_xwrite)( this->pbase(), count ); + if ( offset < 0 ) { + if ( errno == EAGAIN ) { + pollfd wpfd; + wpfd.fd = _fd; + wpfd.events = POLLOUT | POLLHUP | POLLWRNORM; + wpfd.revents = 0; + while ( poll( &wpfd, 1, _timeout ) <= 0 ) { // wait infinite + if ( errno == EINTR ) { // may be interrupted, check and ignore + errno = 0; + continue; + } + return traits::eof(); + } + if ( (wpfd.revents & POLLERR) != 0 ) { + return traits::eof(); + } + offset = (this->*_xwrite)( this->pbase(), count ); + if ( offset < 0 ) { + return traits::eof(); + } + } else { + return traits::eof(); + } + } + if ( offset < count ) { + // MUST BE: (offset % sizeof(char_traits)) == 0 ! + offset /= sizeof(char_traits); + count /= sizeof(char_traits); + traits::move( this->pbase(), this->pbase() + offset, count - offset ); + // std::copy_backword( this->pbase() + offset, this->pbase() + count, this->pbase() ); + setp( this->pbase(), this->epptr() ); // require: set pptr + this->pbump( count - offset ); + if( !traits::eq_int_type(c,traits::eof()) ) { + sputc( traits::to_char_type(c) ); + } + + return traits::not_eof(c); + } +#endif } setp( this->pbase(), this->epptr() ); // require: set pptr @@ -503,6 +599,59 @@ } template<class charT, class traits, class _Alloc> +int basic_sockbuf<charT, traits, _Alloc>::sync() +{ + if ( !is_open() ) { + return -1; + } + + long count = this->pptr() - this->pbase(); + if ( count ) { + // _STLP_ASSERT( this->pbase() != 0 ); + count *= sizeof(charT); +#ifndef __FIT_NONBLOCK_SOCKETS + if ( (this->*_xwrite)( this->pbase(), count ) != count ) { + return -1; + } +#else + long start = 0; + while ( count > 0 ) { + long offset = (this->*_xwrite)( this->pbase() + start, count ); + if ( offset < 0 ) { + if ( errno == EAGAIN ) { + pollfd wpfd; + wpfd.fd = _fd; + wpfd.events = POLLOUT | POLLHUP | POLLWRNORM; + wpfd.revents = 0; + while ( poll( &wpfd, 1, _timeout ) <= 0 ) { // wait infinite + if ( errno == EINTR ) { // may be interrupted, check and ignore + errno = 0; + continue; + } + return -1; + } + if ( (wpfd.revents & POLLERR) != 0 ) { + return -1; + } + offset = (this->*_xwrite)( this->pbase() + start, count ); + if ( offset < 0 ) { + return -1; + } + } else { + return -1; + } + } + count -= offset; + start += offset; + } +#endif + setp( this->pbase(), this->epptr() ); // require: set pptr + } + + return 0; +} + +template<class charT, class traits, class _Alloc> streamsize basic_sockbuf<charT, traits, _Alloc>:: xsputn( const char_type *s, streamsize n ) { Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2007-09-07 11:07:26 UTC (rev 1727) +++ trunk/complement/explore/lib/sockios/ChangeLog 2007-09-07 12:48:58 UTC (rev 1728) @@ -1,3 +1,7 @@ +2007-09-07 Petr Ovtchenkov <pt...@is...> + + * sockstream, sockstream.cc: prepare for __FIT_NONBLOCK_SOCKETS. + 2007-09-06 Petr Ovtchenkov <pt...@is...> * sockmgr.h, sockmgr.cc: allow any name of functions for 'connect' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-09-10 09:41:21
|
Revision: 1730 http://complement.svn.sourceforge.net/complement/?rev=1730&view=rev Author: complement Date: 2007-09-10 02:41:19 -0700 (Mon, 10 Sep 2007) Log Message: ----------- fix thread return type Modified Paths: -------------- trunk/complement/explore/include/DB/PgSQL.h trunk/complement/explore/lib/DB/PgSQL/PgSQL.cc Modified: trunk/complement/explore/include/DB/PgSQL.h =================================================================== --- trunk/complement/explore/include/DB/PgSQL.h 2007-09-10 09:14:38 UTC (rev 1729) +++ trunk/complement/explore/include/DB/PgSQL.h 2007-09-10 09:41:19 UTC (rev 1730) @@ -68,7 +68,7 @@ virtual std::string IS_NOT_NULL() const; private: - static xmt::Thread::ret_code conn_proc( void * ); + static xmt::Thread::ret_t conn_proc( void * ); DBconn *_conn; xmt::Thread thr; Modified: trunk/complement/explore/lib/DB/PgSQL/PgSQL.cc =================================================================== --- trunk/complement/explore/lib/DB/PgSQL/PgSQL.cc 2007-09-10 09:14:38 UTC (rev 1729) +++ trunk/complement/explore/lib/DB/PgSQL/PgSQL.cc 2007-09-10 09:41:19 UTC (rev 1730) @@ -77,11 +77,9 @@ //} } -xmt::Thread::ret_code DataBase::conn_proc( void *p ) +xmt::Thread::ret_t DataBase::conn_proc( void *p ) { DataBase *me = reinterpret_cast<DataBase *>(p); - xmt::Thread::ret_code ret; - ret.iword = 0; me->_conn = PQsetdbLogin( me->_dbhost.length() > 0 ? me->_dbhost.c_str() : 0, 0 /* _dbport */, me->_dbopt.length() > 0 ? me->_dbopt.c_str() : 0, @@ -100,7 +98,7 @@ } me->con_cond.set( true ); - return ret; + return 0; } void DataBase::reconnect() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-09-18 09:21:47
|
Revision: 1737 http://complement.svn.sourceforge.net/complement/?rev=1737&view=rev Author: complement Date: 2007-09-18 02:21:45 -0700 (Tue, 18 Sep 2007) Log Message: ----------- removed intermediate _xcall, use direct call of _call as thread function; add locker for _rip_id---it may be changed from different threads in case of fast termination of thread; libxmt: version 1.13.0 Modified Paths: -------------- trunk/complement/explore/include/mt/xmt.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/xmt.cc Modified: trunk/complement/explore/include/mt/xmt.h =================================================================== --- trunk/complement/explore/include/mt/xmt.h 2007-09-14 10:08:15 UTC (rev 1736) +++ trunk/complement/explore/include/mt/xmt.h 2007-09-18 09:21:45 UTC (rev 1737) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/03 09:47:08 ptr> +// -*- C++ -*- Time-stamp: <07/09/15 10:03:40 ptr> /* * Copyright (c) 1997-1999, 2002-2007 @@ -144,12 +144,12 @@ // extern __FIT_DECLSPEC void signal_throw( int sig ) throw( int ); // extern __FIT_DECLSPEC void signal_thread_exit( int sig ); -#ifdef __unix -extern "C" void *_xcall( void * ); // forward declaration -#endif -#ifdef WIN32 -extern "C" unsigned long __stdcall _xcall( void *p ); // forward declaration -#endif +// #ifdef __unix +// extern "C" void *_xcall( void * ); // forward declaration +// #endif +// #ifdef WIN32 +// extern "C" unsigned long __stdcall _xcall( void *p ); // forward declaration +// #endif #ifndef WIN32 // using std::size_t; @@ -1463,7 +1463,7 @@ bool bad() const { /* Locker lk( _llock ); */ return (_id == bad_thread_id); } bool is_join_req() const // if true, you can (and should) use join() - { /* Locker lk( _llock ); */ return (_rip_id != bad_thread_id) && ((_flags & (daemon | detached)) == 0); } + { scoped_lock lk( _rip_id_lock ); return (_rip_id != bad_thread_id) && ((_flags & (daemon | detached)) == 0); } __FIT_DECLSPEC bool is_self(); @@ -1494,7 +1494,11 @@ bool _not_run() const { /* Locker lk( _llock ); */ return _id == bad_thread_id; } void _create( const void *p, size_t psz ) throw( std::runtime_error); + static void *_call( void *p ); +#ifdef WIN32 + statuc unsigned long __stdcall _call( void *p ); +#endif static void unexpected(); static void terminate(); @@ -1518,6 +1522,7 @@ thread_id_type _id; thread_id_type _rip_id; + mutex _rip_id_lock; #ifdef _PTHREADS # ifndef __hpux // sorry, POSIX threads don't have suspend/resume calls, so it should @@ -1536,12 +1541,12 @@ // mutex _llock; friend class Init; // extern "C", wrap for thread_create -#ifdef __unix - friend void *_xcall( void * ); -#endif -#ifdef __FIT_WIN32THREADS - friend unsigned long __stdcall _xcall( void *p ); -#endif +// #ifdef __unix +// friend void *_xcall( void * ); +// #endif +// #ifdef __FIT_WIN32THREADS +// friend unsigned long __stdcall _xcall( void *p ); +// #endif }; template <bool SCOPE> Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-09-14 10:08:15 UTC (rev 1736) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-09-18 09:21:45 UTC (rev 1737) @@ -1,3 +1,13 @@ +2007-09-18 Petr Ovtchenkov <pt...@is...> + + * xmt.h, xmt.cc: removed intermediate _xcall, use direct call of _call + as thread function; + + * xmt.h, xmt.cc: add locker for _rip_id---it may be changed from different + threads in case of fast termination of thread; + + * libxmt: version 1.13.0 + 2007-09-05 Petr Ovtchenkov <pt...@is...> * xmt.h, xmt.cc: looks like non-POD return from thread is unstable, Modified: trunk/complement/explore/lib/mt/xmt.cc =================================================================== --- trunk/complement/explore/lib/mt/xmt.cc 2007-09-14 10:08:15 UTC (rev 1736) +++ trunk/complement/explore/lib/mt/xmt.cc 2007-09-18 09:21:45 UTC (rev 1737) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/06/14 10:10:54 ptr> +// -*- C++ -*- Time-stamp: <07/09/15 10:16:39 ptr> /* * Copyright (c) 1997-1999, 2002-2007 @@ -419,6 +419,7 @@ thr_join( _rip_id, 0, &rt ); # endif // Locker lk( _llock ); + scoped_lock lk( _rip_id_lock ); _rip_id = bad_thread_id; } #endif // __FIT_UITHREADS || PTHREADS @@ -544,7 +545,7 @@ // follow part of _call if ( (me->_flags & (daemon | detached)) != 0 ) { // otherwise join expected - // Locker lk( me->_llock ); // !!!!??? in the signal handler? + // scoped_lock lk( _rip_id_lock ); // !!!!??? in the signal handler? me->_rip_id = me->_id = bad_thread_id; } else { me->_id = bad_thread_id; @@ -718,21 +719,23 @@ // pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED ); // pthread_attr_setschedpolicy(&attr,SCHED_OTHER); } - err = pthread_create( &_id, _flags != 0 || _stack_sz != 0 ? &attr : 0, _xcall, this ); + scoped_lock lk( _rip_id_lock ); + err = pthread_create( &_id, _flags != 0 || _stack_sz != 0 ? &attr : 0, _call, this ); if ( err != 0 ) { _rip_id = _id = bad_thread_id; } else { _rip_id = _id; } + lk.unlock(); if ( _flags != 0 || _stack_sz != 0 ) { pthread_attr_destroy( &attr ); } #endif #ifdef __FIT_UITHREADS - err = thr_create( 0, 0, _xcall, this, _flags, &_id ); + err = thr_create( 0, 0, _call, this, _flags, &_id ); #endif #ifdef __FIT_WIN32THREADS - _rip_id = _id = CreateThread( 0, 0, _xcall, this, (_flags & suspended), &_thr_id ); + _rip_id = _id = CreateThread( 0, 0, _call, this, (_flags & suspended), &_thr_id ); err = GetLastError(); #endif @@ -750,28 +753,12 @@ #pragma warning( disable : 4101 ) #endif -extern "C" { #ifdef __unix - void *_xcall( void *p ) - { - return Thread::_call( p ); - } +void *Thread::_call( void *p ) #endif #ifdef WIN32 - unsigned long __stdcall _xcall( void *p ) - { - return (unsigned long)Thread::_call( p ); - } +unsigned long __stdcall Thread::_call( void *p ) #endif -#ifdef __FIT_NETWARE - void _xcall( void *p ) - { - Thread::_call( p ); - } -#endif -} // extern "C" - -void *Thread::_call( void *p ) { Thread *me = static_cast<Thread *>(p); @@ -816,6 +803,7 @@ #ifdef __FIT_WIN32THREADS CloseHandle( me->_id ); #endif + scoped_lock lk( me->_rip_id_lock ); me->_id = bad_thread_id; me->_rip_id = bad_thread_id; } else { @@ -830,6 +818,7 @@ #ifdef __FIT_WIN32THREADS CloseHandle( me->_id ); #endif + scoped_lock lk( me->_rip_id_lock ); me->_id = bad_thread_id; me->_rip_id = bad_thread_id; } else { @@ -848,6 +837,7 @@ #ifdef __FIT_WIN32THREADS CloseHandle( me->_id ); #endif + scoped_lock lk( me->_rip_id_lock ); me->_id = bad_thread_id; me->_rip_id = bad_thread_id; } else { @@ -868,6 +858,7 @@ #ifdef __FIT_WIN32THREADS CloseHandle( me->_id ); #endif + scoped_lock lk( me->_rip_id_lock ); me->_id = bad_thread_id; me->_rip_id = bad_thread_id; } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-09-24 18:49:16
|
Revision: 1740 http://complement.svn.sourceforge.net/complement/?rev=1740&view=rev Author: complement Date: 2007-09-24 11:49:09 -0700 (Mon, 24 Sep 2007) Log Message: ----------- print call stack to ostream, initial implementation; store call stack when thread created; useful for debugging; macro to force store call stack when thread created; recompilation required when changed; bfd library required for call stack printing; initial test for call stack output; libxmt: version 1.14.0 Modified Paths: -------------- trunk/complement/explore/include/config/feature.h trunk/complement/explore/include/mt/xmt.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/ut/mt_test.cc trunk/complement/explore/lib/mt/ut/mt_test.h trunk/complement/explore/lib/mt/ut/mt_test_suite.cc trunk/complement/explore/lib/mt/xmt.cc Added Paths: ----------- trunk/complement/explore/include/mt/callstack.h trunk/complement/explore/lib/mt/callstack.cc Modified: trunk/complement/explore/include/config/feature.h =================================================================== --- trunk/complement/explore/include/config/feature.h 2007-09-18 09:31:26 UTC (rev 1739) +++ trunk/complement/explore/include/config/feature.h 2007-09-24 18:49:09 UTC (rev 1740) @@ -112,4 +112,11 @@ # define __FIT_TYPENAME_ARG #endif /* __FIT_NEED_TYPENAME_IN_ARGS_BUG */ +/* + Store information about stack before create thread in xmt::Thread; + useful for debugging. +*/ + +#define __FIT_CREATE_THREAD_STACK_INFO + #endif /* __config_feature_h */ Added: trunk/complement/explore/include/mt/callstack.h =================================================================== --- trunk/complement/explore/include/mt/callstack.h (rev 0) +++ trunk/complement/explore/include/mt/callstack.h 2007-09-24 18:49:09 UTC (rev 1740) @@ -0,0 +1,22 @@ +// -*- C++ -*- Time-stamp: <07/08/03 09:47:53 ptr> + +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License version 3.0 + * + */ + +#ifndef __mt_callstack_h +#define __mt_callstack_h + +#include <ostream> + +namespace xmt { + +void callstack( std::ostream& ); + +} // namespace xmt + +#endif Modified: trunk/complement/explore/include/mt/xmt.h =================================================================== --- trunk/complement/explore/include/mt/xmt.h 2007-09-18 09:31:26 UTC (rev 1739) +++ trunk/complement/explore/include/mt/xmt.h 2007-09-24 18:49:09 UTC (rev 1740) @@ -1538,7 +1538,9 @@ size_t _param_sz; unsigned _flags; size_t _stack_sz; // stack size, if not 0 - // mutex _llock; +#ifdef __FIT_CREATE_THREAD_STACK_INFO + std::string _stack_on_create; +#endif friend class Init; // extern "C", wrap for thread_create // #ifdef __unix Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-09-18 09:31:26 UTC (rev 1739) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-09-24 18:49:09 UTC (rev 1740) @@ -1,3 +1,21 @@ +2007-09-24 Petr Ovtchenkov <pt...@is...> + + * callstack.h, callstack.cc: print call stack to ostream, initial + implementation; + + * xmt.h, xmt.cc: store call stack when thread created; useful for + debugging; + + * config/feature.h: macro to force store call stack when thread + created; recompilation required when changed; + + * Makefile: bfd library required for call stack printing; + + * ut/mt_test.cc, ut/mt_test.h, ut/mt_test_suite.cc: initial test for + call stack output. + + * libxmt: version 1.14.0 + 2007-09-18 Petr Ovtchenkov <pt...@is...> * xmt.h, xmt.cc: removed intermediate _xcall, use direct call of _call Modified: trunk/complement/explore/lib/mt/Makefile =================================================================== --- trunk/complement/explore/lib/mt/Makefile 2007-09-18 09:31:26 UTC (rev 1739) +++ trunk/complement/explore/lib/mt/Makefile 2007-09-24 18:49:09 UTC (rev 1740) @@ -8,6 +8,8 @@ INCLUDES += -I$(SRCROOT)/include HEADERS_BASE = $(SRCROOT)/include/mt $(SRCROOT)/include/config $(SRCROOT)/include/misc +LDLIBS += -ldl -lbfd + check: all-shared $(MAKE) -C ut all-shared (cd ut; ${OUTPUT_DIR}/mt_ut) || exit 1 Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2007-09-18 09:31:26 UTC (rev 1739) +++ trunk/complement/explore/lib/mt/Makefile.inc 2007-09-24 18:49:09 UTC (rev 1740) @@ -2,7 +2,7 @@ LIBNAME = xmt MAJOR = 1 -MINOR = 13 +MINOR = 14 PATCH = 0 -SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc +SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc callstack.cc SRC_C = fl.c Added: trunk/complement/explore/lib/mt/callstack.cc =================================================================== --- trunk/complement/explore/lib/mt/callstack.cc (rev 0) +++ trunk/complement/explore/lib/mt/callstack.cc 2007-09-24 18:49:09 UTC (rev 1740) @@ -0,0 +1,304 @@ +// -*- C++ -*- Time-stamp: <07/09/21 22:45:51 ptr> + +/* + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License version 3.0 + * + */ + +/** + * Derived from: + * http://www.tlug.org.za/wiki/index.php/Obtaining_a_stack_trace_in_C_upon_SIGSEGV + * + * This code is in the public domain. Use it as you see fit, some credit + * would be appreciated, but is not a prerequisite for usage. Feedback + * on it's use would encourage further development and maintenance. + * + * Author: Jaco Kroon <ja...@kr...> + * + * Copyright (C) 2005 - 2006 Jaco Kroon + */ + +#include <config/feature.h> + +// #define _GNU_SOURCE +// #include <memory.h> +// #include <stdlib.h> +// #include <stdio.h> + +#include <bfd.h> +#include <signal.h> +#include <ucontext.h> +#include <dlfcn.h> +#include <execinfo.h> + +#ifdef __FIT_CPP_DEMANGLE +# include <cxxabi.h> +#endif + +#if 1 +#if defined(REG_RIP) +# define SIGSEGV_STACK_IA64 +// # define REGFORMAT "%016lx" +#elif defined(REG_EIP) +# define SIGSEGV_STACK_X86 +// # define REGFORMAT "%08x" +#else +# define SIGSEGV_STACK_GENERIC +// # define REGFORMAT "%x" +#endif +#endif + +#include <cstring> + +#include <mt/callstack.h> +#include <iomanip> +#include <string> +#include <sstream> + +namespace xmt { + +using namespace std; + +class BFD_Init +{ + public: + BFD_Init() + { + bfd_init(); + bfd_set_default_target( "i686-pc-linux-gnu" ); + } +}; + +BFD_Init init; + +struct params_collect +{ + bfd_boolean found; + bfd_vma pc; + asymbol **syms; + const char *fname; + const char *funcname; + unsigned line; +}; + +void find_address_in_section( bfd *abfd, asection *section, void *data ) +{ + bfd_boolean& found = static_cast<params_collect *>(data)->found; + + if ( found ) { + return; + } + + if ( (bfd_get_section_flags(abfd, section) & SEC_ALLOC) == 0 ) { + return; + } + + bfd_vma vma = bfd_get_section_vma( abfd, section ); + bfd_vma& pc = static_cast<params_collect *>(data)->pc; + if ( pc < vma ) { + return; + } + + bfd_size_type size = bfd_get_section_size( section ); + if ( pc >= vma + size ) { + return; + } + + found = bfd_find_nearest_line( abfd, section, + static_cast<params_collect *>(data)->syms, pc - vma, + &static_cast<params_collect *>(data)->fname, + &static_cast<params_collect *>(data)->funcname, + &static_cast<params_collect *>(data)->line ); +} + +int extract_info( const char *fname, void *addr, string& file, unsigned& line ) +{ + bfd *abfd = bfd_openr( fname, 0 ); + if ( abfd == 0 ) { + return -1; + } + + char **matching; + if ( !bfd_check_format_matches( abfd, bfd_object, &matching ) ) { + // free (matching); + return -2; + } + + // slurp_symtab (abfd); + asymbol **syms = 0; // Symbol table + + if ( ( bfd_get_file_flags(abfd) & HAS_SYMS ) != 0 ) { + long symcount; + unsigned int size; + + symcount = bfd_read_minisymbols( abfd, 0, (void **)&syms, &size ); + if ( symcount == 0 ) { + symcount = bfd_read_minisymbols( abfd, 1, (void **)&syms, &size ); + } + + if ( symcount < 0 ) { + if ( syms != 0 ) { + free( syms ); + } + bfd_close( abfd ); + return -3; + } + } + + params_collect pars; + pars.found = 0; + pars.syms = syms; + + // translate_addresses (abfd, 0); + + // for ( ; ; ) { + pars.pc = reinterpret_cast<bfd_vma>(addr); + bfd_map_over_sections( abfd, find_address_in_section, reinterpret_cast<void *>(&pars) ); + if ( pars.found == 0 ) { + if ( syms != 0 ) { + free( syms ); + } + bfd_close( abfd ); + return -4; + } + + file = pars.fname; + line = pars.line; + + // } + if ( syms != 0 ) { + free( syms ); + } + + bfd_close( abfd ); + + return 0; +} + +void callstack( std::ostream& s ) +{ + // s.clear(); + +#if defined(SIGSEGV_STACK_X86) || defined(SIGSEGV_STACK_IA64) + ucontext_t ucontext; + + getcontext( &ucontext ); + + int f = 0; + Dl_info dlinfo; + void **bp = 0; + void *ip = 0; +# if defined(SIGSEGV_STACK_IA64) + ip = (void*)ucontext.uc_mcontext.gregs[REG_RIP]; + bp = (void**)ucontext.uc_mcontext.gregs[REG_RBP]; +# elif defined(SIGSEGV_STACK_X86) + ip = (void*)ucontext.uc_mcontext.gregs[REG_EIP]; + bp = (void**)ucontext.uc_mcontext.gregs[REG_EBP]; +# endif + string file; + unsigned line; + + while ( bp && ip ) { + if ( !dladdr( ip, &dlinfo ) ) { + break; + } + + const char *symname = dlinfo.dli_sname; +#ifdef __FIT_CPP_DEMANGLE + int status = 0; + char *tmp = symname == 0 ? 0 : __cxxabiv1::__cxa_demangle( symname, 0, 0, &status ); + + if ( status == 0 && tmp != 0 ) { + symname = tmp; + } +#endif + + // int res; + + // if ( string( "obj/gcc/so_g/mt_ut" ) == dlinfo.dli_fname ) { + if ( /* (res = extract_info( dlinfo.dli_fname, ip, file, line )) != 0 */ false ) { + file = "??"; + line = 0; + // s << "*** " << res << " " << dlinfo.dli_fname << endl; + } else { + file = "??"; + line = 0; + } + // } else { + // file = "??"; + // line = 0; + // } + + s << '#' << setw(2) << setiosflags(ios_base::left) << f++ << " " << ip + << " in " << (symname == 0 ? "?" : symname ) + << " at " << /* "...\n" */ file << ":" << line << '\n'; + // << "+" << (static_cast<char *>(ip) - static_cast<char *>(dlinfo.dli_saddr)) + // << "> (" << dlinfo.dli_fname << ")\n"; +#ifdef __FIT_CPP_DEMANGLE + if ( tmp ) { + free(tmp); + } +#endif + + if ( dlinfo.dli_sname && !strcmp( dlinfo.dli_sname, "main" ) ) { + break; + } + + ip = bp[1]; + bp = (void**)bp[0]; + } +#else + const int btsz = 50; + void *bt[btsz]; + + size_t sz = backtrace( bt, btsz ); + char **line = backtrace_symbols( bt, sz ); + + Dl_info dlinfo; + // string file; + // unsigned line; + + for ( int i = 0; i < sz; ++i ) { + stringstream ss( line[i] ); + // s << line[i] << '\n'; + string nm; + void *addr; + char c; + ss >> nm >> c >> hex >> addr; + + if ( !dladdr( addr, &dlinfo ) ) { + continue; + } + + const char *symname = dlinfo.dli_sname; +#ifdef __FIT_CPP_DEMANGLE + int status = 0; + char *tmp = symname == 0 ? 0 : __cxxabiv1::__cxa_demangle( symname, 0, 0, &status ); + + if ( status == 0 && tmp != 0 ) { + symname = tmp; + } +#endif + + // int res = extract_info(); + + s << '#' << setw(2) << setiosflags(ios_base::left) << i << " " << addr + << " in " << (symname == 0 ? "..." : symname) + << " at " << "...\n"; + // s << "== " << nm << " / '" << c << "' " << addr << "\n"; +#ifdef __FIT_CPP_DEMANGLE + if ( tmp ) { + free(tmp); + } +#endif + } + + free( line ); +#endif +} + +} // namespace xmt + Modified: trunk/complement/explore/lib/mt/ut/mt_test.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test.cc 2007-09-18 09:31:26 UTC (rev 1739) +++ trunk/complement/explore/lib/mt/ut/mt_test.cc 2007-09-24 18:49:09 UTC (rev 1740) @@ -13,6 +13,7 @@ #include <mt/xmt.h> #include <mt/shm.h> #include <mt/thr_mgr.h> +#include <mt/callstack.h> #include <sys/shm.h> #include <sys/wait.h> @@ -27,6 +28,13 @@ using namespace std; namespace fs = boost::filesystem; +int EXAM_IMPL(mt_test::callstack) +{ + xmt::callstack( cerr ); + + return EXAM_RESULT; +} + /* ****************************************************** * Degenerate case: check that one thread pass throw * own barrier. Modified: trunk/complement/explore/lib/mt/ut/mt_test.h =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test.h 2007-09-18 09:31:26 UTC (rev 1739) +++ trunk/complement/explore/lib/mt/ut/mt_test.h 2007-09-24 18:49:09 UTC (rev 1740) @@ -19,6 +19,7 @@ class mt_test { public: + int EXAM_DECL(callstack); int EXAM_DECL(barrier); int EXAM_DECL(join_test); int EXAM_DECL(barrier2); Modified: trunk/complement/explore/lib/mt/ut/mt_test_suite.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2007-09-18 09:31:26 UTC (rev 1739) +++ trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2007-09-24 18:49:09 UTC (rev 1740) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/05 00:29:06 ptr> +// -*- C++ -*- Time-stamp: <07/09/21 22:41:08 ptr> /* * Copyright (c) 2006, 2007 @@ -27,6 +27,7 @@ exam::test_suite t( "libxmt test" ); mt_test test; +#if 0 t.add( timespec_diff, "timespec_diff" ); t.add( signal_1_test, "signal_1_test" ); // You can't throw exception from signal handler @@ -34,9 +35,12 @@ // by this reason next test is commented: // t.add( signal_2_test, "signal_2_test" ); t.add( signal_3_test, "signal_3_test" ); +#endif exam::test_suite::test_case_type tc[3]; + // t.add( &mt_test::callstack, test, "callstack" ); + tc[0] = t.add( &mt_test::barrier, test, "mt_test::barrier" ); tc[1] = t.add( &mt_test::join_test, test, "mt_test::join_test" ); tc[2] = t.add( &mt_test::yield, test, "mt_test::yield", Modified: trunk/complement/explore/lib/mt/xmt.cc =================================================================== --- trunk/complement/explore/lib/mt/xmt.cc 2007-09-18 09:31:26 UTC (rev 1739) +++ trunk/complement/explore/lib/mt/xmt.cc 2007-09-24 18:49:09 UTC (rev 1740) @@ -20,6 +20,7 @@ #include <fcntl.h> #include <mt/xmt.h> +#include <mt/callstack.h> #include <cstring> #ifndef _WIN32 @@ -359,7 +360,13 @@ if ( (_flags & (daemon | detached)) != 0 ) { // not joinable // Locker lk( _llock ); if ( _id != bad_thread_id ) { // still run? - cerr << "Crash on daemon thread exit expected, threas id " << _id << endl; + cerr << "Suspected crash of daemon thread, threas id " << _id << endl; +#ifdef __FIT_CREATE_THREAD_STACK_INFO + cerr << "Stack when thread was created:\n" << _stack_on_create << endl; +#endif + std::stringstream s; + callstack( s ); + cerr << "Current stack is:\n" << s.str() << endl; } } @@ -701,6 +708,15 @@ _param_sz = psz; int err = 0; +#ifdef __FIT_CREATE_THREAD_STACK_INFO + // _stack_on_create + { + std::stringstream s; + callstack( s ); + _stack_on_create = s.str(); + } +#endif + #ifdef _PTHREADS pthread_attr_t attr; if ( _flags != 0 || _stack_sz != 0 ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-09-24 19:04:29
|
Revision: 1742 http://complement.svn.sourceforge.net/complement/?rev=1742&view=rev Author: complement Date: 2007-09-24 12:04:25 -0700 (Mon, 24 Sep 2007) Log Message: ----------- rename loop_id to loop_thr, for correct interpretation; clean main loop of connection_processor; initialize buffer; reduce number of iterations for test; libsockios: Version 1.13.0. Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/lib/sockios/ChangeLog trunk/complement/explore/lib/sockios/Makefile.inc trunk/complement/explore/lib/sockios/ut/sockios_test.cc trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2007-09-24 18:50:50 UTC (rev 1741) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2007-09-24 19:04:25 UTC (rev 1742) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/13 23:10:08 ptr> +// -*- C++ -*- Time-stamp: <07/09/19 11:43:21 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -63,7 +63,7 @@ } _loop_cnd.set( false ); - loop_id.launch( loop, this, 0, PTHREAD_STACK_MIN * 2 ); + loop_thr.launch( loop, this, 0, PTHREAD_STACK_MIN * 2 ); _loop_cnd.try_wait(); } } @@ -376,7 +376,7 @@ xmt::Thread::ret_t sockmgr_stream_MP<Connect,C,T>::loop( void *p ) { _Self_type *me = static_cast<_Self_type *>(p); - me->loop_id.pword( _idx ) = me; // push pointer to self for signal processing + me->loop_thr.pword( _idx ) = me; // push pointer to self for signal processing xmt::Thread::ret_t rtc = 0; xmt::Thread::ret_t rtc_observer = 0; @@ -387,7 +387,7 @@ me->_follow = true; - while ( (me->*me->_accept)() ) { + while ( (me->*me->_accept)() /* && me->_is_follow() */ ) { if ( thr_observer.bad() ) { if ( thr_observer.is_join_req() ) { rtc_observer = thr_observer.join(); @@ -421,6 +421,7 @@ // me->_c_lock.unlock(); rtc_observer = thr_observer.join(); + xmt::scoped_lock _l( me->_c_lock ); me->_M_c.clear(); // FIN still may not come yet; force close if ( rtc_observer != 0 && rtc == 0 ) { rtc = reinterpret_cast<xmt::Thread::ret_t>(-2); // there was connect_processor that was killed @@ -436,75 +437,74 @@ try { timespec idle( me->_idle ); + typename _Sequence::iterator c; - me->_dlock.lock(); - typename _Sequence::iterator c; - bool _non_empty = false; - if ( me->_conn_pool.size() != 0 ) { + { + xmt::scoped_lock lk(me->_dlock); + if ( me->_conn_pool.empty() ) { + me->_pool_cnd.set( false ); + me->_observer_cnd.set( false ); + return 0; + } c = me->_conn_pool.front(); me->_conn_pool.pop_front(); - _non_empty = true; xmt::gettime( &me->_tpop ); } - me->_dlock.unlock(); do { - if ( _non_empty ) { - sockstream& stream = c->s; - if ( stream.is_open() ) { - (c->_proc->*C)( stream ); - if ( stream.is_open() && stream.good() ) { - if ( stream.rdbuf()->in_avail() > 0 ) { - // socket has buffered data, push it back to queue - xmt::scoped_lock lk(me->_dlock); - me->_conn_pool.push_back( c ); - me->_observer_cnd.set( true ); - me->_pool_cnd.set( true ); - if ( !me->_follow ) { - break; - } - c = me->_conn_pool.front(); - me->_conn_pool.pop_front(); - xmt::gettime( &me->_tpop ); - // xmt::Thread::gettime( &me->_tpush ); - continue; - } else { // no buffered data, return socket to poll - sock_base::socket_type rfd = stream.rdbuf()->fd(); - ::write( me->_cfd, reinterpret_cast<const char *>(&rfd), sizeof(sock_base::socket_type) ); + sockstream& stream = c->s; + if ( stream.is_open() ) { + (c->_proc->*C)( stream ); + if ( stream.is_open() && stream.good() ) { + if ( stream.rdbuf()->in_avail() > 0 ) { + // socket has buffered data, push it back to queue + xmt::scoped_lock lk(me->_dlock); + me->_conn_pool.push_back( c ); + me->_observer_cnd.set( true ); + me->_pool_cnd.set( true ); + if ( !me->_follow ) { + break; } - } else { - me->_dlock.lock(); - me->_conn_pool.erase( std::remove( me->_conn_pool.begin(), me->_conn_pool.end(), c ), me->_conn_pool.end() ); - me->_dlock.unlock(); + c = me->_conn_pool.front(); + me->_conn_pool.pop_front(); + xmt::gettime( &me->_tpop ); + // xmt::Thread::gettime( &me->_tpush ); + continue; + } else { // no buffered data, return socket to poll + sock_base::socket_type rfd = stream.rdbuf()->fd(); + ::write( me->_cfd, reinterpret_cast<const char *>(&rfd), sizeof(sock_base::socket_type) ); + } + } else { + me->_dlock.lock(); + me->_conn_pool.erase( std::remove( me->_conn_pool.begin(), me->_conn_pool.end(), c ), me->_conn_pool.end() ); + me->_dlock.unlock(); - xmt::scoped_lock _l( me->_c_lock ); - me->_M_c.erase( c ); - } + xmt::scoped_lock _l( me->_c_lock ); + me->_M_c.erase( c ); } } - _non_empty = false; - - if ( me->_pool_cnd.try_wait_delay( &idle ) == 0 ) { + { xmt::scoped_lock lk(me->_dlock); - if ( !me->_follow ) { - return 0; + if ( me->_conn_pool.empty() ) { + lk.unlock(); + if ( me->_pool_cnd.try_wait_delay( &idle ) != 0 ) { + lk.lock(); + me->_pool_cnd.set( false ); + me->_observer_cnd.set( false ); + return 0; + } + if ( !me->_is_follow() ) { // before _conn_pool.front() + return 0; + } + lk.lock(); + if ( me->_conn_pool.empty() ) { + return 0; + } } - if ( me->_conn_pool.size() != 0 ) { - c = me->_conn_pool.front(); - me->_conn_pool.pop_front(); - _non_empty = true; - xmt::gettime( &me->_tpop ); - } else { - me->_pool_cnd.set( false ); - me->_observer_cnd.set( false ); - return 0; - } - } else { - xmt::scoped_lock lk(me->_dlock); - me->_pool_cnd.set( false ); - me->_observer_cnd.set( false ); - return 0; + c = me->_conn_pool.front(); + me->_conn_pool.pop_front(); + xmt::gettime( &me->_tpop ); } } while ( me->_is_follow() ); } @@ -610,7 +610,7 @@ FD_SET( fd_unsafe(), &_pfde ); _fdmax = fd_unsafe(); - loop_id.launch( loop, this, 0, PTHREAD_STACK_MIN * 2 ); + loop_thr.launch( loop, this, 0, PTHREAD_STACK_MIN * 2 ); } } Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2007-09-24 18:50:50 UTC (rev 1741) +++ trunk/complement/explore/include/sockios/sockmgr.h 2007-09-24 19:04:25 UTC (rev 1742) @@ -192,7 +192,7 @@ } ~sockmgr_stream_MP() - { loop_id.join(); } + { loop_thr.join(); } private: sockmgr_stream_MP( const sockmgr_stream_MP<Connect,C,T>& ); @@ -207,7 +207,7 @@ { basic_sockmgr::close(); } void wait() - { loop_id.join(); } + { loop_thr.join(); } void detach( sockstream& ) // remove sockstream from polling in manager { } @@ -237,7 +237,7 @@ { } ~_Connect() - { if ( _proc ) { s.close(); (_proc->*T)(); } delete _proc; } + { if ( _proc ) { s.close(); (_proc->*T)(); delete _proc; _proc = 0; } } void open( sock_base::socket_type st, const sockaddr& addr, sock_base::stype t = sock_base::sock_stream ) { s.open( st, addr, t ); _proc = new Connect( s ); } @@ -289,7 +289,7 @@ bool accept_udp(); private: - xmt::Thread loop_id; + xmt::Thread loop_thr; protected: typedef sockmgr_stream_MP<Connect,C,T> _Self_type; Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2007-09-24 18:50:50 UTC (rev 1741) +++ trunk/complement/explore/lib/sockios/ChangeLog 2007-09-24 19:04:25 UTC (rev 1742) @@ -1,3 +1,13 @@ +2007-09-24 Petr Ovtchenkov <pt...@is...> + + * sockios/sockmgr.h, sockios/sockmgr.cc: rename loop_id to loop_thr, + for correct interpretation; clean main loop of connection_processor; + + * ut/sockios_test.cc: initialize buffer; reduce number of iterations + for test; + + * libsockios: Version 1.13.0. + 2007-09-07 Petr Ovtchenkov <pt...@is...> * sockstream, sockstream.cc: prepare for __FIT_NONBLOCK_SOCKETS. Modified: trunk/complement/explore/lib/sockios/Makefile.inc =================================================================== --- trunk/complement/explore/lib/sockios/Makefile.inc 2007-09-24 18:50:50 UTC (rev 1741) +++ trunk/complement/explore/lib/sockios/Makefile.inc 2007-09-24 19:04:25 UTC (rev 1742) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <07/07/12 00:53:38 ptr> +# -*- Makefile -*- Time-stamp: <07/09/24 22:52:43 ptr> LIBNAME = sockios MAJOR = 1 -MINOR = 12 -PATCH = 1 +MINOR = 13 +PATCH = 0 SRC_CC = _sockstream.cc _sockmgr.cc SRC_C = freebsd/getaddrinfo.c \ freebsd/ns_parse.c \ Modified: trunk/complement/explore/lib/sockios/ut/sockios_test.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios_test.cc 2007-09-24 18:50:50 UTC (rev 1741) +++ trunk/complement/explore/lib/sockios/ut/sockios_test.cc 2007-09-24 19:04:25 UTC (rev 1742) @@ -664,7 +664,7 @@ char buf[1024]; int count = 0; - for ( int i = 0; i < 1024 * 1024; ++i ) { + for ( int i = 0; i < 128 * 1024; ++i ) { s.read( buf, 1024 ); } cnd.set( true ); @@ -693,7 +693,9 @@ char buf[1024]; - for ( int i = 0; i < 1024 * 1024; ++i ) { + fill( buf, buf + 1024, ' ' ); + + for ( int i = 0; i < 128 * 1024; ++i ) { s.write( buf, 1024 ); } s.flush(); Modified: trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc 2007-09-24 18:50:50 UTC (rev 1741) +++ trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc 2007-09-24 19:04:25 UTC (rev 1742) @@ -36,6 +36,8 @@ exam::test_suite t( "libsockios test" ); + // t.flags( t.flags() | exam::base_logger::trace ); + trivial_sockios_test trivial_test; tc[0] = t.add( &trivial_sockios_test::simple, trivial_test, "trivial_sockios_test::simple" ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-09-25 14:25:18
|
Revision: 1744 http://complement.svn.sourceforge.net/complement/?rev=1744&view=rev Author: complement Date: 2007-09-25 07:25:16 -0700 (Tue, 25 Sep 2007) Log Message: ----------- try to connect to well-known hosts and/or become a server to establish virtual synchrony net; libjanus: version 0.4.0 Modified Paths: -------------- trunk/complement/explore/include/janus/vshostmgr.h trunk/complement/explore/lib/janus/ChangeLog trunk/complement/explore/lib/janus/Makefile trunk/complement/explore/lib/janus/Makefile.inc trunk/complement/explore/lib/janus/ut/unit_test.cc trunk/complement/explore/lib/janus/ut/vt_operations.h trunk/complement/explore/lib/janus/ut/vt_remote.cc trunk/complement/explore/lib/janus/vshostmgr.cc Modified: trunk/complement/explore/include/janus/vshostmgr.h =================================================================== --- trunk/complement/explore/include/janus/vshostmgr.h 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/include/janus/vshostmgr.h 2007-09-25 14:25:16 UTC (rev 1744) @@ -39,12 +39,15 @@ // typedef std::list<stem::gaddr_type> vshost_container_t; #if defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) typedef std::tr1::unordered_set<stem::gaddr_type> vshost_container_t; + typedef std::tr1::unordered_set<std::string> vs_wellknown_hosts_container_t; #endif #ifdef __USE_STD_HASH typedef __gnu_cxx::hash_set<stem::gaddr_type> vshost_container_t; + typedef __gnu_cxx::hash_set<std::string> vs_wellknown_hosts_container_t; #endif #ifdef __USE_STLPORT_HASH typedef std::hash_set<stem::gaddr_type> vshost_container_t; + typedef std::hash_set<std::string> vs_wellknown_hosts_container_t; #endif public: @@ -60,9 +63,15 @@ void VSOutMember( const stem::Event_base<VSsync_rq>& ); void VSsync_time( const stem::Event_base<VSsync>& ev ); - void connect( const char *, int ); - void serve( int ); + static void add_wellknown( const char *nm ); + static void add_wellknown( const std::string& nm ); + static void rm_wellknown( const char *nm ); + static void rm_wellknown( const std::string& nm ); + static void add_srvport( int ); + int connect( const char *, int ); + int serve( int ); + size_type vs_known_processes() const { xmt::recursive_scoped_lock lk( this->_theHistory_lock ); @@ -102,6 +111,10 @@ Finalizer finalizer; + static xmt::mutex _wknh_lock; + static vs_wellknown_hosts_container_t _wknhosts; + static int _srvport; + // DECLARE_RESPONSE_TABLE( VSHostMgr, janus::VTHandler ); }; Modified: trunk/complement/explore/lib/janus/ChangeLog =================================================================== --- trunk/complement/explore/lib/janus/ChangeLog 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/lib/janus/ChangeLog 2007-09-25 14:25:16 UTC (rev 1744) @@ -1,3 +1,15 @@ +2007-09-25 Petr Ovtchenkov <pt...@is...> + + * vshostmgr.h, vshostmgr.cc: try to connect to well-known hosts + and/or become a server to establish virtual synchrony net; + + * ut/unit_test.cc: test for well-known hosts [nodes of virtual + synchrony net]; + + * lib/janus/ut/vt_operations.h, lib/janus/ut/vt_remote.cc: ditto; + + * libjanus: version 0.4.0. + 2007-08-27 Petr Ovtchenkov <pt...@is...> * janus.h, janus.cc: hide methods, intended for internal Modified: trunk/complement/explore/lib/janus/Makefile =================================================================== --- trunk/complement/explore/lib/janus/Makefile 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/lib/janus/Makefile 2007-09-25 14:25:16 UTC (rev 1744) @@ -21,11 +21,11 @@ dbg-shared : LDLIBS = -lxmtg -lsockiosg -lstemg check: all-shared - $(MAKE) -C test - (cd test; ${OUTPUT_DIR}/ut_vtime) || exit 1 - (cd test; ${OUTPUT_DIR_DBG}/ut_vtime) || exit 1 + $(MAKE) -C ut + (cd ut; ${OUTPUT_DIR}/ut_vtime) || exit 1 + (cd ut; ${OUTPUT_DIR_DBG}/ut_vtime) || exit 1 ifndef WITHOUT_STLPORT - (cd test; ${OUTPUT_DIR_STLDBG}/ut_vt) || exit 1 + (cd ut; ${OUTPUT_DIR_STLDBG}/ut_vt) || exit 1 endif check-release-shared: release-shared @@ -43,7 +43,7 @@ endif depend:: - $(MAKE) -C test depend + $(MAKE) -C ut depend # dbg-shared: DEFS += -DDEBUG Modified: trunk/complement/explore/lib/janus/Makefile.inc =================================================================== --- trunk/complement/explore/lib/janus/Makefile.inc 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/lib/janus/Makefile.inc 2007-09-25 14:25:16 UTC (rev 1744) @@ -2,6 +2,6 @@ LIBNAME = janus MAJOR = 0 -MINOR = 3 +MINOR = 4 PATCH = 0 SRC_CC = vtime.cc janus.cc vshostmgr.cc Modified: trunk/complement/explore/lib/janus/ut/unit_test.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/unit_test.cc 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/lib/janus/ut/unit_test.cc 2007-09-25 14:25:16 UTC (rev 1744) @@ -8,7 +8,7 @@ { using namespace janus; - exam::test_suite::test_case_type tc[3]; + exam::test_suite::test_case_type tc[4]; exam::test_suite t( "virtual time operations" ); @@ -23,7 +23,7 @@ tc[2] = t.add( &vtime_operations::gvt_add, vt_oper, "Group VT add", tc[1] ) ); t.add( &vtime_operations::mgroups, vt_oper, "mgroups", - t.add( &vtime_operations::remote, vt_oper, "remote", + tc[3] = 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", @@ -34,6 +34,8 @@ t.add( &vtime_operations::VTDispatch1, vt_oper, "VTDispatch1", t.add( &vtime_operations::vt_object, vt_oper, "VT order", tc[2] )))))))))) ); + t.add( &vtime_operations::wellknownhost, vt_oper, "well-known host", tc[3] ); + return t.girdle(); } Modified: trunk/complement/explore/lib/janus/ut/vt_operations.h =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_operations.h 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/lib/janus/ut/vt_operations.h 2007-09-25 14:25:16 UTC (rev 1744) @@ -33,6 +33,7 @@ int EXAM_DECL(remote); int EXAM_DECL(mgroups); + int EXAM_DECL(wellknownhost); }; } // namespace janus Modified: trunk/complement/explore/lib/janus/ut/vt_remote.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_remote.cc 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/lib/janus/ut/vt_remote.cc 2007-09-25 14:25:16 UTC (rev 1744) @@ -430,4 +430,92 @@ return EXAM_RESULT; } +int EXAM_IMPL(vtime_operations::wellknownhost) +{ + 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>(); + + VSHostMgr::add_wellknown( "localhost:6980" ); + VSHostMgr::add_srvport( 6980 ); + + try { + xmt::fork(); + + long res_flag = 0; + + b.wait(); + + { + YaRemote obj1( "obj client" ); + + obj1.JoinGroup( janus::vs_base::first_user_group ); + + obj1.wait_greeting(); + } + + exit( res_flag ); + } + catch ( xmt::fork_in_parent& child ) { + YaRemote obj1( "obj srv" ); + + // obj1.vtdispatcher()->settrf( janus::Janus::tracenet | janus::Janus::tracedispatch | janus::Janus::tracefault | janus::Janus::tracedelayed | janus::Janus::tracegroup ); + // obj1.vtdispatcher()->settrs( &std::cerr ); + + // obj1.vtdispatcher()->serve( 6980 ); + + obj1.JoinGroup( janus::vs_base::first_user_group ); + + b.wait(); + + // while ( obj1.vtdispatcher()->vs_known_processes() < 2 ) { + // xmt::delay( xmt::timespec( 0, 1000000 ) ); + // } + + obj1.wait_greeting(); + + stem::Event ev( VS_DUMMY_MESS ); + ev.dest( janus::vs_base::first_user_group ); + ev.value() = "hello"; + + obj1.JaSend( ev ); + + EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 2 ); + EXAM_CHECK( obj1.count == 1 ); + + // obj1.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch ); + // obj1.manager()->settrs( &std::cerr ); + + int stat = -1; + EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + } else { + EXAM_ERROR( "child interrupted" ); + } + + EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 1 ); + + EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 1 ); + // cerr << obj1.vtdispatcher()->vs_known_processes() << endl; + } + + (&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; +} + } // namespace janus Modified: trunk/complement/explore/lib/janus/vshostmgr.cc =================================================================== --- trunk/complement/explore/lib/janus/vshostmgr.cc 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/lib/janus/vshostmgr.cc 2007-09-25 14:25:16 UTC (rev 1744) @@ -48,6 +48,30 @@ vshost.insert( gaddr_type( stem::janus_addr ) ); JoinGroup( vshosts_group ); + + bool is_connected = false; + + xmt::scoped_lock lk( _wknh_lock ); + for ( vs_wellknown_hosts_container_t::const_iterator i = _wknhosts.begin(); i != _wknhosts.end(); ++i ) { + string s( *i ); + string::size_type p = s.find( ':' ); + if ( p != string::npos ) { + s.replace( p, 1, 1, ' ' ); + stringstream ss( s ); + int port = 0; + ss >> s >> port; + if ( !ss.fail() ) { + if ( connect( s.c_str(), port ) != 0 ) { + continue; + } + is_connected = true; + break; + } + } + } + if ( !is_connected && _srvport != 0 ) { + serve( _srvport ); + } } VSHostMgr::~VSHostMgr() @@ -141,12 +165,19 @@ VTHandler::VSsync_time(ev); } -void VSHostMgr::connect( const char *host, int port ) +int VSHostMgr::connect( const char *host, int port ) { - _clients.push_back( new NetTransportMgr() ); + NetTransportMgr *mgr = new NetTransportMgr(); - addr_type zero = _clients.back()->open( host, port ); + addr_type zero = mgr->open( host, port ); + if ( zero == stem::badaddr ) { + delete mgr; + return -1; + } + + _clients.push_back( mgr ); + gaddr_type ga = manager()->reflect( zero ); if ( ga != gaddr_type() ) { ga.addr = stem::janus_addr; @@ -171,6 +202,7 @@ catch ( ... ) { } #endif // __FIT_VS_TRACE + return 0; } #ifdef __FIT_VS_TRACE else { @@ -184,27 +216,40 @@ } } #endif // __FIT_VS_TRACE + + delete _clients.back(); + _clients.pop_back(); + return -2; } -void VSHostMgr::serve( int port ) +int VSHostMgr::serve( int port ) { - _servers.push_back( new sockmgr_stream_MP<NetTransport>( port ) ); + sockmgr_stream_MP<NetTransport> *mgr = new sockmgr_stream_MP<NetTransport>( port ); + #ifdef __FIT_VS_TRACE try { scoped_lock lk(vtdispatcher()->_lock_tr); if ( vtdispatcher()->_trs != 0 && vtdispatcher()->_trs->good() && (vtdispatcher()->_trflags & Janus::tracenet) ) { *vtdispatcher()->_trs << "serve " << port - << (_servers.back()->good() ? " ok" : " fail" ) - << endl; + << (mgr->good() ? " ok" : " fail" ) << endl; } } catch ( ... ) { } #endif // __FIT_VS_TRACE + if ( !mgr->good() ) { + delete mgr; + return -2; + } + _servers.push_back( mgr ); + return 0; } void VSHostMgr::Subscribe( stem::addr_type addr, group_type grp ) { + if ( vshost.empty() ) { + return; + } try { manager()->transport( addr ); } @@ -226,16 +271,56 @@ *vtdispatcher()->_trs << " -> VS_NEW_REMOTE_MEMBER G" << grp << " " << hex << showbase << ev.src() << " -> " << ev.dest() << dec << endl; - } - } - catch ( ... ) { - } + } + } + catch ( ... ) { + } #endif // __FIT_VS_TRACE } } } } +xmt::mutex VSHostMgr::_wknh_lock; +VSHostMgr::vs_wellknown_hosts_container_t VSHostMgr::_wknhosts; +int VSHostMgr::_srvport = 0; + +void VSHostMgr::add_wellknown( const char *nm ) +{ + xmt::scoped_lock lk( _wknh_lock ); + _wknhosts.insert( string(nm) ); +} + +void VSHostMgr::add_wellknown( const std::string& nm ) +{ + xmt::scoped_lock lk( _wknh_lock ); + _wknhosts.insert( nm ); +} + +void VSHostMgr::rm_wellknown( const char *nm ) +{ + xmt::scoped_lock lk( _wknh_lock ); + vs_wellknown_hosts_container_t::iterator i = _wknhosts.find( string(nm) ); + if ( i != _wknhosts.end() ) { + _wknhosts.erase( i ); + } +} + +void VSHostMgr::rm_wellknown( const std::string& nm ) +{ + xmt::scoped_lock lk( _wknh_lock ); + vs_wellknown_hosts_container_t::iterator i = _wknhosts.find( nm ); + if ( i != _wknhosts.end() ) { + _wknhosts.erase( i ); + } +} + +void VSHostMgr::add_srvport( int p ) +{ + xmt::scoped_lock lk( _wknh_lock ); + _srvport = p; +} + // DEFINE_RESPONSE_TABLE( VSHostMgr ) // EV_Event_base_T_( ST_NULL, VS_NEW_REMOTE_MEMBER, VSNewRemoteMemberDirect, VSsync_rq ) // EV_Event_base_T_( ST_NULL, VS_NEW_MEMBER_RV, VSNewRemoteMemberRevert, VSsync_rq ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-10-01 09:13:24
|
Revision: 1752 http://complement.svn.sourceforge.net/complement/?rev=1752&view=rev Author: complement Date: 2007-10-01 02:13:22 -0700 (Mon, 01 Oct 2007) Log Message: ----------- comment NetTransportMP, looks it useless; add trace for NetTransport [server part]; library version 4.6.4 Modified Paths: -------------- trunk/complement/explore/include/stem/NetTransport.h trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/Makefile.inc trunk/complement/explore/lib/stem/NetTransport.cc Modified: trunk/complement/explore/include/stem/NetTransport.h =================================================================== --- trunk/complement/explore/include/stem/NetTransport.h 2007-09-28 11:03:56 UTC (rev 1751) +++ trunk/complement/explore/include/stem/NetTransport.h 2007-10-01 09:13:22 UTC (rev 1752) @@ -112,6 +112,7 @@ std::sockstream _channel; }; +#if 0 class NetTransportMP : public NetTransport_base { @@ -123,6 +124,7 @@ __FIT_DECLSPEC void connect( std::sockstream& ); }; +#endif } // namespace stem Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2007-09-28 11:03:56 UTC (rev 1751) +++ trunk/complement/explore/lib/stem/ChangeLog 2007-10-01 09:13:22 UTC (rev 1752) @@ -1,3 +1,10 @@ +2007-10-01 Petr Ovtchenkov <pt...@is...> + + * NetTransport.h, NetTransport.cc: comment NetTransportMP, + looks it useless; add trace for NetTransport [server part]; + + * libstem: library version 4.6.4 + 2007-09-05 Petr Ovtchenkov <pt...@is...> * Cron.h, NetTransport.h, EvManager.h: looks like non-POD return Modified: trunk/complement/explore/lib/stem/Makefile.inc =================================================================== --- trunk/complement/explore/lib/stem/Makefile.inc 2007-09-28 11:03:56 UTC (rev 1751) +++ trunk/complement/explore/lib/stem/Makefile.inc 2007-10-01 09:13:22 UTC (rev 1752) @@ -3,7 +3,7 @@ LIBNAME = stem MAJOR = 4 MINOR = 6 -PATCH = 3 +PATCH = 4 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-09-28 11:03:56 UTC (rev 1751) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2007-10-01 09:13:22 UTC (rev 1752) @@ -303,8 +303,33 @@ gaddr_type src; if ( pop( ev, dst, src ) ) { +#ifdef __FIT_STEM_TRACE + try { + xmt::scoped_lock lk(manager()->_lock_tr); + 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; + } + } + catch ( ... ) { + } +#endif // __FIT_STEM_TRACE addr_type xdst = manager()->reflect( dst ); if ( xdst == badaddr ) { +#ifdef __FIT_STEM_TRACE + try { + xmt::scoped_lock lk(manager()->_lock_tr); + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & (EvManager::tracefault)) ) { + *manager()->_trs << __FILE__ << ":" << __LINE__ + << " (" + << xmt::getpid() << "/" << xmt::getppid() << ") " + << "Unknown destination\n"; + manager()->dump( *manager()->_trs ) << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_STEM_TRACE return; } ev.dest( xdst ); @@ -314,6 +339,16 @@ } else { ev.src( xsrc ); } +#ifdef __FIT_STEM_TRACE + try { + xmt::scoped_lock lk(manager()->_lock_tr); + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & (EvManager::tracenet)) ) { + *manager()->_trs << __FILE__ << ":" << __LINE__ << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_STEM_TRACE manager()->push( ev ); } } @@ -505,6 +540,7 @@ return 0; } +#if 0 __FIT_DECLSPEC void NetTransportMP::connect( sockstream& s ) { @@ -514,8 +550,35 @@ try { if ( pop( ev, dst, src ) ) { +#ifdef __FIT_STEM_TRACE + try { + xmt::scoped_lock lk(manager()->_lock_tr); + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & E +vManager::tracenet) ) { + *manager()->_trs << "Pid/ppid: " << xmt::getpid() << "/" << xmt::getppid() << +"\n"; + manager()->dump( *manager()->_trs ) << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_STEM_TRACE addr_type xdst = manager()->reflect( dst ); if ( xdst == badaddr ) { +#ifdef __FIT_STEM_TRACE + try { + xmt::scoped_lock lk(manager()->_lock_tr); + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & (EvManager::tracefault)) ) { + *manager()->_trs << __FILE__ << ":" << __LINE__ + << " (" + << xmt::getpid() << "/" << xmt::getppid() << ") " + << "Unknown destination\n"; + manager()->dump( *manager()->_trs ) << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_STEM_TRACE return; } ev.dest( xdst ); @@ -526,6 +589,16 @@ } else { ev.src( xsrc ); } +#ifdef __FIT_STEM_TRACE + try { + xmt::scoped_lock lk(manager()->_lock_tr); + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & (EvManager::tracenet)) ) { + *manager()->_trs << __FILE__ << ":" << __LINE__ << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_STEM_TRACE manager()->push( ev ); } if ( !s.good() ) { @@ -538,4 +611,6 @@ } } +#endif + } // namespace stem This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-10-05 10:01:13
|
Revision: 1757 http://complement.svn.sourceforge.net/complement/?rev=1757&view=rev Author: complement Date: 2007-10-05 03:01:09 -0700 (Fri, 05 Oct 2007) Log Message: ----------- cover use-case with syncronization of same group in different VS nodes during connection [VS_MERGE_GROUP, VS_SYNC_GROUP_TIME]; Janus::VSRemoteMemberRevert hasn't send VS_NEW_MEMBER; fix test. version 0.5.0; Modified Paths: -------------- trunk/complement/explore/include/janus/janus.h trunk/complement/explore/include/janus/vtime.h trunk/complement/explore/lib/janus/ChangeLog trunk/complement/explore/lib/janus/Makefile.inc trunk/complement/explore/lib/janus/janus.cc trunk/complement/explore/lib/janus/ut/Makefile trunk/complement/explore/lib/janus/ut/Makefile.inc trunk/complement/explore/lib/janus/ut/vt_remote.cc trunk/complement/explore/lib/janus/vshostmgr.cc trunk/complement/explore/lib/janus/vtime.cc Modified: trunk/complement/explore/include/janus/janus.h =================================================================== --- trunk/complement/explore/include/janus/janus.h 2007-10-01 16:33:28 UTC (rev 1756) +++ trunk/complement/explore/include/janus/janus.h 2007-10-05 10:01:09 UTC (rev 1757) @@ -42,16 +42,19 @@ typedef std::hash_map<oid_type, detail::vtime_obj_rec> vt_map_type; typedef std::hash_multimap<group_type, oid_type> gid_map_type; typedef std::hash_set<stem::addr_type> addr_cache_t; + typedef std::hash_set<group_type> group_cache_t; #endif #ifdef __USE_STD_HASH typedef __gnu_cxx::hash_map<oid_type, detail::vtime_obj_rec> vt_map_type; typedef __gnu_cxx::hash_multimap<group_type, oid_type> gid_map_type; typedef __gnu_cxx::hash_set<stem::addr_type> addr_cache_t; + typedef __gnu_cxx::hash_set<group_type> group_cache_t; #endif #if defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) typedef std::tr1::unordered_map<oid_type, detail::vtime_obj_rec> vt_map_type; typedef std::tr1::unordered_multimap<group_type, oid_type> gid_map_type; typedef std::tr1::unordered_set<stem::addr_type> addr_cache_t; + typedef std::tr1::unordered_set<group_type> group_cache_t; #endif public: @@ -104,8 +107,8 @@ unsigned trflags() const; void settrs( std::ostream * ); - void connect( const char *, int ); - void serve( int ); + int connect( const char *, int ); + int serve( int ); size_t vs_known_processes() const; difference_type group_size( group_type ) const; @@ -147,6 +150,9 @@ void VSNewRemoteMemberRevert( const stem::Event_base<VSsync_rq>& e ); void VSOutMember( const stem::Event_base<VSsync_rq>& e ); + void VSMergeRemoteGroup( const stem::Event_base<VSsync_rq>& e ); + void VSsync_group_time( const stem::Event_base<VSsync>& ev ); + DECLARE_RESPONSE_TABLE( Janus, stem::EventHandler ); }; Modified: trunk/complement/explore/include/janus/vtime.h =================================================================== --- trunk/complement/explore/include/janus/vtime.h 2007-10-01 16:33:28 UTC (rev 1756) +++ trunk/complement/explore/include/janus/vtime.h 2007-10-05 10:01:09 UTC (rev 1757) @@ -372,8 +372,8 @@ virtual void VSNewMember( const stem::Event_base<VSsync_rq>& e ); virtual void VSOutMember( const stem::Event_base<VSsync_rq>& e ); virtual void VSsync_time( const stem::Event_base<VSsync>& ); + virtual void VSMergeRemoteGroup( const stem::Event_base<VSsync_rq>& e ); - // template <class D> // void JaSend( const stem::Event_base<D>& e ) // { VTHandler::JaSend( stem::Event_convert<D>()( e ) ); } @@ -384,7 +384,9 @@ protected: void Unsubscribe(); void VSNewMember_data( const stem::Event_base<VSsync_rq>&, const std::string& data ); + void VSMergeRemoteGroup_data( const stem::Event_base<VSsync_rq>& e, const std::string& data ); + void get_gvtime( group_type g, gvtime_type& gvt ); private: @@ -401,6 +403,8 @@ #define VS_NEW_REMOTE_MEMBER 0x304 #define VS_NEW_MEMBER_RV 0x305 #define VS_HOST_MGR_FINAL 0x306 +#define VS_MERGE_GROUP 0x307 +#define VS_SYNC_GROUP_TIME 0x308 #ifdef __USE_STLPORT_HASH # undef __USE_STLPORT_HASH Modified: trunk/complement/explore/lib/janus/ChangeLog =================================================================== --- trunk/complement/explore/lib/janus/ChangeLog 2007-10-01 16:33:28 UTC (rev 1756) +++ trunk/complement/explore/lib/janus/ChangeLog 2007-10-05 10:01:09 UTC (rev 1757) @@ -1,3 +1,14 @@ +2007-10-05 Petr Ovtchenkov <pt...@is...> + + * janus.h, janus.cc, vtime.h, vtime.cc: cover use-case + with syncronization of same group in different VS nodes + during connection [VS_MERGE_GROUP, VS_SYNC_GROUP_TIME]; + Janus::VSRemoteMemberRevert hasn't send VS_NEW_MEMBER; + + * vt_remote.cc: fix test. + + * libjanus: version 0.5.0; + 2007-10-01 Petr Ovtchenkov <pt...@is...> * janus.cc, vshostmgr.cc: more trace prints; Modified: trunk/complement/explore/lib/janus/Makefile.inc =================================================================== --- trunk/complement/explore/lib/janus/Makefile.inc 2007-10-01 16:33:28 UTC (rev 1756) +++ trunk/complement/explore/lib/janus/Makefile.inc 2007-10-05 10:01:09 UTC (rev 1757) @@ -2,6 +2,6 @@ LIBNAME = janus MAJOR = 0 -MINOR = 4 +MINOR = 5 PATCH = 0 SRC_CC = vtime.cc janus.cc vshostmgr.cc Modified: trunk/complement/explore/lib/janus/janus.cc =================================================================== --- trunk/complement/explore/lib/janus/janus.cc 2007-10-01 16:33:28 UTC (rev 1756) +++ trunk/complement/explore/lib/janus/janus.cc 2007-10-05 10:01:09 UTC (rev 1757) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/26 12:44:25 ptr> +// -*- C++ -*- Time-stamp: <07/10/04 01:04:14 ptr> #include <janus/janus.h> #include <janus/vshostmgr.h> @@ -174,6 +174,8 @@ } while ( more ); } +// Send VS event within group grp: + void Janus::JaSend( const stem::Event& e, group_type grp ) { // This method not called from Dispatch, but work on the same level and in the same @@ -213,6 +215,7 @@ // if remote, forward it to foreign VTDispatcher? try { /* const transport tr = */ manager()->transport( k->second.stem_addr() ); + // remote delivery gaddr_type ga = manager()->reflect( k->second.stem_addr() ); if ( ga != gaddr_type() ) { ga.addr = stem::janus_addr; @@ -226,6 +229,7 @@ } } catch ( const range_error& ) { + // local delivery check_and_send( k->second, m ); vt.base_advance(g->second); // store last send VT to obj } @@ -538,13 +542,12 @@ void Janus::VSNewMember( const stem::Event_base<VSsync_rq>& ev ) { - if ( ev.value().grp == vshosts_group ) { - ev.dest( _hostmgr->self_id() ); + if ( ev.value().grp != vshosts_group ) { // shouldn't happens, only trace #ifdef __FIT_VS_TRACE try { scoped_lock lk(_lock_tr); - if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { - *_trs << "<-> VS_NEW_MEMBER G" << vshosts_group << " " + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) && (_trflags & tracefault) ) { + *_trs << "Unexpected VS_NEW_MEMBER on Janus: G" << ev.value().grp << " " << hex << showbase << ev.src() << " -> " << ev.dest() << dec << endl; } @@ -552,113 +555,121 @@ catch ( ... ) { } #endif // __FIT_VS_TRACE - Forward( ev ); - gaddr_type ga = manager()->reflect( ev.src() ); - addr_type janus_addr = badaddr; - if ( ga != gaddr_type() ) { - ga.addr = stem::janus_addr; - janus_addr = manager()->reflect( ga ); - if ( janus_addr == badaddr ) { - janus_addr = manager()->SubscribeRemote( ga, "janus" ); - } - } - stem::Event_base<VSsync_rq> evr( VS_NEW_MEMBER_RV ); - evr.dest( janus_addr ); - evr.value().grp = vshosts_group; + return; + } + // special group + // Forward info about remote VS node to VSHostMgr + ev.dest( _hostmgr->self_id() ); #ifdef __FIT_VS_TRACE - try { - scoped_lock lk(_lock_tr); - if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { - *_trs << " -> VS_NEW_MEMBER_RV G" << vshosts_group << " " - << hex << showbase - << self_id() << " -> " << evr.dest() << dec << endl; - } + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << "<-> VS_NEW_MEMBER G" << vshosts_group << " " + << hex << showbase + << ev.src() << " -> " << ev.dest() << dec << endl; } - catch ( ... ) { + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + Forward( ev ); + + // Return info about me (VS node) back to remote VS node + gaddr_type ga = manager()->reflect( ev.src() ); + addr_type janus_addr = badaddr; + if ( ga != gaddr_type() ) { + ga.addr = stem::janus_addr; + janus_addr = manager()->reflect( ga ); + if ( janus_addr == badaddr ) { + janus_addr = manager()->SubscribeRemote( ga, "janus" ); } -#endif // __FIT_VS_TRACE - Send( evr ); } + stem::Event_base<VSsync_rq> evr( VS_NEW_MEMBER_RV ); + evr.dest( janus_addr ); + evr.value().grp = vshosts_group; #ifdef __FIT_VS_TRACE - else { - try { - scoped_lock lk(_lock_tr); - if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { - *_trs << "Unexpected VS_NEW_MEMBER on Janus: G" << ev.value().grp << " " - << hex << showbase - << ev.src() << " -> " << ev.dest() << dec << endl; - } + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << " -> VS_NEW_MEMBER_RV G" << vshosts_group << " " + << hex << showbase + << self_id() << " -> " << evr.dest() << dec << endl; } - catch ( ... ) { - } } + catch ( ... ) { + } #endif // __FIT_VS_TRACE + Send( evr ); } void Janus::VSNewRemoteMemberDirect( const stem::Event_base<VSsync_rq>& ev ) { - if ( ev.value().grp != vshosts_group ) { - group_type grp = ev.value().grp; - pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( grp ); - if ( range.first != range.second ) { // we have local? member within this group - const addr_type addr = ev.src(); - gaddr_type ga = manager()->reflect( addr ); - addr_type janus_addr = badaddr; - if ( ga != gaddr_type() ) { - ga.addr = stem::janus_addr; - janus_addr = manager()->reflect( ga ); - if ( janus_addr == badaddr ) { - janus_addr = manager()->SubscribeRemote( ga, "janus" ); + if ( ev.value().grp == vshosts_group ) { // special group, and this shouldn't happens + return; + } + group_type grp = ev.value().grp; + pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( grp ); + if ( range.first == range.second ) { // no local (?) member within this group + return; + } + + const addr_type addr = ev.src(); + gaddr_type ga = manager()->reflect( addr ); + addr_type janus_addr = badaddr; + if ( ga != gaddr_type() ) { + ga.addr = stem::janus_addr; + janus_addr = manager()->reflect( ga ); + if ( janus_addr == badaddr ) { + janus_addr = manager()->SubscribeRemote( ga, "janus" ); + } + } + for ( ; range.first != range.second; ++range.first ) { + vt_map_type::iterator i = vtmap.find( range.first->second ); + if ( i != vtmap.end() ) { + // Inform local (?) object about new remote group member + stem::Event_base<VSsync_rq> evs( VS_NEW_MEMBER ); + evs.dest( i->second.stem_addr() ); + evs.src( addr ); + evs.value().grp = grp; +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << " -> VS_NEW_MEMBER (remote) G" << grp << " " + << hex << showbase + << evs.src() << " -> " << evs.dest() << dec << endl; } } - for ( ; range.first != range.second; ++range.first ) { - vt_map_type::iterator i = vtmap.find( range.first->second ); - if ( i != vtmap.end() ) { - stem::Event_base<VSsync_rq> evs( VS_NEW_MEMBER ); - evs.dest( i->second.stem_addr() ); - evs.src( addr ); - evs.value().grp = grp; -#ifdef __FIT_VS_TRACE - try { - scoped_lock lk(_lock_tr); - if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { - *_trs << " -> VS_NEW_MEMBER (remote) G" << grp << " " - << hex << showbase - << evs.src() << " -> " << evs.dest() << dec << endl; - } - } - catch ( ... ) { - } + catch ( ... ) { + } #endif // __FIT_VS_TRACE - Forward( evs ); - stem::Event_base<VSsync_rq> evr( VS_NEW_MEMBER_RV ); - evr.dest( janus_addr ); - evr.src( i->second.stem_addr() ); - evr.value().grp = grp; + Forward( evs ); + // Inform remote object about local (?) group member + stem::Event_base<VSsync_rq> evr( VS_NEW_MEMBER_RV ); + evr.dest( janus_addr ); + evr.src( i->second.stem_addr() ); + evr.value().grp = grp; #ifdef __FIT_VS_TRACE - try { - scoped_lock lk(_lock_tr); - if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { - *_trs << " -> VS_NEW_MEMBER_RV G" << grp << " " - << hex << showbase - << evr.src() << " -> " << evr.dest() << dec << endl; - } - } - catch ( ... ) { - } -#endif // __FIT_VS_TRACE - Forward( evr ); + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + *_trs << " -> VS_NEW_MEMBER_RV G" << grp << " " + << hex << showbase + << evr.src() << " -> " << evr.dest() << dec << endl; } } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + Forward( evr ); + } + } - const gaddr_type oid = manager()->reflect( addr ); // ???? oid == gaddr + const gaddr_type oid = manager()->reflect( addr ); // ???? oid == gaddr - vtmap[oid].add( addr, grp ); - grmap.insert( make_pair(grp,oid) ); - // cerr << "**** " << grp << " " << xmt::getpid() << endl; - } - } + vtmap[oid].add( addr, grp ); + grmap.insert( make_pair(grp,oid) ); } void Janus::VSNewRemoteMemberRevert( const stem::Event_base<VSsync_rq>& ev ) @@ -668,34 +679,48 @@ pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( grp ); if ( range.first != range.second ) { // we have local? member within this group const addr_type addr = ev.src(); - for ( ; range.first != range.second; ++range.first ) { - vt_map_type::iterator i = vtmap.find( range.first->second ); - if ( i != vtmap.end() && ((i->second.stem_addr() & stem::extbit) == 0 )) { - stem::Event_base<VSsync_rq> evs( VS_NEW_MEMBER ); - evs.dest( i->second.stem_addr() ); - evs.src( addr ); - evs.value().grp = grp; + const gaddr_type oid = manager()->reflect( addr ); // ???? oid == gaddr #ifdef __FIT_VS_TRACE - try { - scoped_lock lk(_lock_tr); - if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { - *_trs << " -> VS_NEW_MEMBER (remote revert) G" << grp << " " - << hex << showbase - << evs.src() << " -> " << evs.dest() << dec << endl; - } - } - catch ( ... ) { - } -#endif // __FIT_VS_TRACE - Forward( evs ); + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + int f = _trs->flags(); + *_trs << " VS add remote object " << hex << showbase << oid + << dec << " G" << grp << endl; +#ifdef STLPORT + _trs->flags( f ); +#else + _trs->flags( static_cast<std::_Ios_Fmtflags>(f) ); +#endif } } - - const gaddr_type oid = manager()->reflect( addr ); // ???? oid == gaddr + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + // add remote memer of group grp vtmap[oid].add( addr, grp ); grmap.insert( make_pair(grp,oid) ); - // cerr << "**** " << grp << " " << xmt::getpid() << endl; } +#ifdef __FIT_VS_TRACE + else { + // this VS node has no group grp, so do nothing + // except trace info + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) && (_trflags & tracefault) ) { + int f = _trs->flags(); + *_trs << " VS node don't has such group, ignore G" << grp << endl; +#ifdef STLPORT + _trs->flags( f ); +#else + _trs->flags( static_cast<std::_Ios_Fmtflags>(f) ); +#endif + } + } + catch ( ... ) { + } + } +#endif // __FIT_VS_TRACE } else { const addr_type addr = ev.src(); const gaddr_type oid = manager()->reflect( ev.src() ); // ???? oid == gaddr @@ -719,7 +744,20 @@ vtmap[oid].add( addr, vshosts_group ); grmap.insert( make_pair(static_cast<group_type>(vshosts_group),oid) ); - // cerr << "**** " << vshosts_group << " " << xmt::getpid() << endl; + + // send request for sync all groups, that present in this VS node: + stem::Event_base<VSsync_rq> e( VS_MERGE_GROUP ); + e.dest( ev.src() ); + group_cache_t gcache; + for ( gid_map_type::const_iterator i = grmap.begin(); i != grmap.end(); ++i ) { + // for all groups, except vshosts_group, + // and only once for earch group + if ( (i->first != vshosts_group) && (gcache.find( i->first) != gcache.end()) ) { + e.value().grp = i->first; + Send( e ); + gcache.insert( i->first ); + } + } } } @@ -784,14 +822,14 @@ } } -void Janus::connect( const char *host, int port ) +int Janus::connect( const char *host, int port ) { - _hostmgr->connect( host, port ); + return _hostmgr->connect( host, port ); } -void Janus::serve( int port ) +int Janus::serve( int port ) { - _hostmgr->serve( port ); + return _hostmgr->serve( port ); } size_t Janus::vs_known_processes() const @@ -809,12 +847,108 @@ return distance( range.first, range.second ); } +void Janus::VSMergeRemoteGroup( const stem::Event_base<VSsync_rq>& e ) +{ + const group_type grp = e.value().grp; +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + int f = _trs->flags(); + *_trs << " VS merge remote group request G" << grp << endl; +#ifdef STLPORT + _trs->flags( f ); +#else + _trs->flags( static_cast<std::_Ios_Fmtflags>(f) ); +#endif + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( grp ); + if ( range.first != range.second ) { // we have local? member within this group + // const addr_type addr = e.src(); + // expected that addr correspond to remote Janus + + // gaddr_type ga = manager()->reflect( addr ); + // addr_type janus_addr = badaddr; + // if ( ga != gaddr_type() ) { + // ga.addr = stem::janus_addr; + // janus_addr = manager()->reflect( ga ); + // if ( janus_addr == badaddr ) { + // janus_addr = manager()->SubscribeRemote( ga, "janus" ); + // } + // } + + // select VS object with latest time, and forward request to it + + // gvtime_type gvt; + // gvtime_type gvt_last; + // stem::addr_type addr = stem::badaddr; + for ( ; range.first != range.second; ++range.first ) { + vt_map_type::iterator i = vtmap.find( range.first->second ); + if ( i != vtmap.end() && ((i->second.stem_addr() & stem::extbit) == 0 )) { + // i->second.get_gvt( gvt ); + // if ( gvt_last < gvt ) { + // swap( gvt_last, gvt ); + // addr = i->second.stem_addr(); + // } + e.dest( i->second.stem_addr() ); + Forward( e ); + return; + } + } + // e.dest( addr ); + // Forward( e ); + } +} + +void Janus::VSsync_group_time( const stem::Event_base<VSsync>& ev ) +{ + const group_type grp = ev.value().grp; +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + int f = _trs->flags(); + *_trs << " VS sync remote group time G" << grp << endl; +#ifdef STLPORT + _trs->flags( f ); +#else + _trs->flags( static_cast<std::_Ios_Fmtflags>(f) ); +#endif + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + + // find all local group members and forward data as VS_SYNC_TIME + pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( grp ); + stem::Event_base<VSsync> e( VS_SYNC_TIME ); + e.src( ev.src() ); + e.value().grp = ev.value().grp; + e.value().gvt.gvt = ev.value().gvt.gvt; + e.value().mess = ev.value().mess; + + for ( ; range.first != range.second; ++range.first ) { + vt_map_type::iterator i = vtmap.find( range.first->second ); + if ( i != vtmap.end() && ((i->second.stem_addr() & stem::extbit) == 0 )) { + e.dest( i->second.stem_addr() ); + Forward( e ); + } + } +} + DEFINE_RESPONSE_TABLE( Janus ) EV_Event_base_T_( ST_NULL, VS_MESS, JaDispatch, VSmess ) EV_Event_base_T_( ST_NULL, VS_NEW_MEMBER, VSNewMember, VSsync_rq ) EV_Event_base_T_( ST_NULL, VS_NEW_REMOTE_MEMBER, VSNewRemoteMemberDirect, VSsync_rq ) EV_Event_base_T_( ST_NULL, VS_NEW_MEMBER_RV, VSNewRemoteMemberRevert, VSsync_rq ) EV_Event_base_T_( ST_NULL, VS_OUT_MEMBER, VSOutMember, VSsync_rq ) + EV_Event_base_T_( ST_NULL, VS_MERGE_GROUP, VSMergeRemoteGroup, VSsync_rq ) + EV_Event_base_T_( ST_NULL, VS_SYNC_GROUP_TIME, VSsync_group_time, VSsync ) END_RESPONSE_TABLE } // namespace janus Modified: trunk/complement/explore/lib/janus/ut/Makefile =================================================================== --- trunk/complement/explore/lib/janus/ut/Makefile 2007-10-01 16:33:28 UTC (rev 1756) +++ trunk/complement/explore/lib/janus/ut/Makefile 2007-10-05 10:01:09 UTC (rev 1757) @@ -16,23 +16,24 @@ LIBXMT_DIR = ${CoMT_DIR}/lib/mt LIBSOCKIOS_DIR = ${CoMT_DIR}/lib/sockios LIBSTEM_DIR = ${CoMT_DIR}/lib/stem +LIBJANUS_DIR = ${CoMT_DIR}/lib/janus ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L$(LIBXMT_DIR)/${OUTPUT_DIR} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR} -L$(LIBSTEM_DIR)/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:$(LIBXMT_DIR)/${OUTPUT_DIR}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L$(LIBXMT_DIR)/${OUTPUT_DIR} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR} -L$(LIBSTEM_DIR)/${OUTPUT_DIR} -L$(LIBJANUS_DIR)/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:$(LIBXMT_DIR)/${OUTPUT_DIR}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBJANUS_DIR}${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_DBG} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR_DBG} -L$(LIBSTEM_DIR)/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_DBG}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_DBG} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR_DBG} -L$(LIBSTEM_DIR)/${OUTPUT_DIR_DBG} -L$(LIBJANUS_DIR)/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_DBG}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBJANUS_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBSTEM_DIR)/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBSTEM_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBJANUS_DIR)/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBJANUS_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif -release-shared: PROJECT_LIBS = -lxmt -lsockios -lstem -lexam -dbg-shared: PROJECT_LIBS = -lxmtg -lsockiosg -lstemg -lexamg +release-shared: PROJECT_LIBS = -lxmt -lsockios -lstem -lexam -ljanus +dbg-shared: PROJECT_LIBS = -lxmtg -lsockiosg -lstemg -lexamg -ljanusg ifndef WITHOUT_STLPORT -stldbg-shared: PROJECT_LIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lexamstlg +stldbg-shared: PROJECT_LIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lexamstlg -ljanusstlg endif dbg-shared: DEFS += -D__FIT_VS_TRACE Modified: trunk/complement/explore/lib/janus/ut/Makefile.inc =================================================================== --- trunk/complement/explore/lib/janus/ut/Makefile.inc 2007-10-01 16:33:28 UTC (rev 1756) +++ trunk/complement/explore/lib/janus/ut/Makefile.inc 2007-10-05 10:01:09 UTC (rev 1757) @@ -2,10 +2,7 @@ PRGNAME = ut_vtime -SRC_CC = ../vtime.cc \ - ../janus.cc \ - ../vshostmgr.cc \ - unit_test.cc \ +SRC_CC = unit_test.cc \ vt_operations.cc \ VTmess_core.cc \ vt_object.cc \ Modified: trunk/complement/explore/lib/janus/ut/vt_remote.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_remote.cc 2007-10-01 16:33:28 UTC (rev 1756) +++ trunk/complement/explore/lib/janus/ut/vt_remote.cc 2007-10-05 10:01:09 UTC (rev 1757) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/26 12:54:05 ptr> +// -*- C++ -*- Time-stamp: <07/10/04 10:11:26 ptr> #include "vt_operations.h" @@ -28,9 +28,7 @@ using namespace xmt; #define VS_DUMMY_MESS 0x1203 -#define VS_DUMMY_GREETING 0x1204 -#define VS_DUMMY_GREETING2 0x1205 -#define VS_DUMMY_MESS2 0x1206 +#define VS_DUMMY_MESS2 0x1204 class YaRemote : public janus::VTHandler @@ -43,11 +41,10 @@ void handler( const stem::Event& ); void handler2( const stem::Event& ); - void VSNewMember( const stem::Event_base<VSsync_rq>& ); - void VSOutMember( const stem::Event_base<VSsync_rq>& ); - void greeting(); - void greeting2(); + virtual void VSNewMember( const stem::Event_base<VSsync_rq>& ); + virtual void VSOutMember( const stem::Event_base<VSsync_rq>& ); + virtual void VSsync_time( const stem::Event_base<VSsync>& ); void wait(); void wait2(); @@ -131,20 +128,16 @@ void YaRemote::VSNewMember( const stem::Event_base<VSsync_rq>& ev ) { - // cerr << "Hello " << xmt::getpid() << endl; + // cerr << "VSNewMember " << xmt::getpid() << endl; ++count; // VTNewMember_data( ev, "" ); VTHandler::VSNewMember( ev ); if ( ev.value().grp == janus::vs_base::first_user_group ) { - stem::EventVoid gr_ev( VS_DUMMY_GREETING ); - gr_ev.dest( ev.src() ); - Send( gr_ev ); + gr.set( true ); } else if ( ev.value().grp == (janus::vs_base::first_user_group + 1) ) { - stem::EventVoid gr_ev( VS_DUMMY_GREETING2 ); - gr_ev.dest( ev.src() ); - Send( gr_ev ); + gr2.set( true ); } } @@ -153,6 +146,18 @@ ++ocount; } +void YaRemote::VSsync_time( const stem::Event_base<VSsync>& ev ) +{ + // cerr << "VSsync_time " << xmt::getpid() << endl; + ++count; + VTHandler::VSsync_time( ev ); + if ( ev.value().grp == janus::vs_base::first_user_group ) { + gr.set( true ); + } else if ( ev.value().grp == (janus::vs_base::first_user_group + 1) ) { + gr2.set( true ); + } +} + void YaRemote::wait() { cnd.try_wait(); @@ -167,21 +172,9 @@ cnd2.set( false ); } -void YaRemote::greeting() -{ - gr.set( true ); -} - -void YaRemote::greeting2() -{ - gr2.set( true ); -} - DEFINE_RESPONSE_TABLE( YaRemote ) EV_EDS( ST_NULL, VS_DUMMY_MESS, handler ) EV_EDS( ST_NULL, VS_DUMMY_MESS2, handler2 ) - EV_VOID( ST_NULL, VS_DUMMY_GREETING, greeting ) - EV_VOID( ST_NULL, VS_DUMMY_GREETING2, greeting2 ) END_RESPONSE_TABLE int EXAM_IMPL(vtime_operations::remote) @@ -239,7 +232,7 @@ // cerr << obj1.vtdispatcher()->vs_known_processes() << endl; - EXAM_CHECK_ASYNC_F( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 2, res_flag ); + // EXAM_CHECK_ASYNC_F( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 2, res_flag ); // cerr << obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) << endl; obj1.JoinGroup( janus::vs_base::first_user_group ); @@ -248,7 +241,7 @@ EXAM_CHECK_ASYNC_F( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 2, res_flag ); EXAM_CHECK_ASYNC_F( obj1.count == 1, res_flag ); - // cerr << "* " << obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) << endl; + // cerr << "* " << obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) << " " << obj1.count << " " << xmt::getpid() << endl; obj1.wait(); // obj1.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch ); @@ -303,6 +296,7 @@ EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 1 ); // cerr << obj1.vtdispatcher()->vs_known_processes() << endl; + EXAM_CHECK( obj1.ocount == 1 ); } (&b)->~__barrier<true>(); @@ -410,11 +404,14 @@ EXAM_ERROR( "child interrupted" ); } - EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 1 ); - EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group + 1) == 1 ); - // cerr << obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group + 1) << endl; + // EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 1 ); + // EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group + 1) == 1 ); + cerr << obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) << endl; + cerr << obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group + 1) << endl; - EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 1 ); + // EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 1 ); + // EXAM_CHECK( obj1.ocount == 2 ); + cerr << obj1.ocount << endl; } (&b)->~__barrier<true>(); Modified: trunk/complement/explore/lib/janus/vshostmgr.cc =================================================================== --- trunk/complement/explore/lib/janus/vshostmgr.cc 2007-10-01 16:33:28 UTC (rev 1756) +++ trunk/complement/explore/lib/janus/vshostmgr.cc 2007-10-05 10:01:09 UTC (rev 1757) @@ -222,6 +222,8 @@ } #endif // __FIT_VS_TRACE Send( ev ); + + // conn_cnd.try_wait_delay( timeout ); return 0; } #ifdef __FIT_VS_TRACE Modified: trunk/complement/explore/lib/janus/vtime.cc =================================================================== --- trunk/complement/explore/lib/janus/vtime.cc 2007-10-01 16:33:28 UTC (rev 1756) +++ trunk/complement/explore/lib/janus/vtime.cc 2007-10-05 10:01:09 UTC (rev 1757) @@ -727,10 +727,55 @@ } } +void VTHandler::VSMergeRemoteGroup( const stem::Event_base<VSsync_rq>& e ) +{ + stem::Event_base<VSsync> out_ev( VS_SYNC_GROUP_TIME ); + out_ev.dest( e.src() ); + out_ev.value().grp = e.value().grp; + get_gvtime( e.value().grp, out_ev.value().gvt.gvt ); +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_vtdsp->_lock_tr); + if ( _vtdsp->_trs != 0 && _vtdsp->_trs->good() && (_vtdsp->_trflags & Janus::tracegroup) ) { + *_vtdsp->_trs << " -> VS_SYNC_GROUP_TIME G" << e.value().grp << " " + << hex << showbase + << self_id() << " -> " << out_ev.dest() << dec << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + Send( out_ev ); +} + +void VTHandler::VSMergeRemoteGroup_data( const stem::Event_base<VSsync_rq>& e, const string& data ) +{ + stem::Event_base<VSsync> out_ev( VS_SYNC_GROUP_TIME ); + out_ev.dest( e.src() ); + out_ev.value().grp = e.value().grp; + get_gvtime( e.value().grp, out_ev.value().gvt.gvt ); + out_ev.value().mess = data; +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_vtdsp->_lock_tr); + if ( _vtdsp->_trs != 0 && _vtdsp->_trs->good() && (_vtdsp->_trflags & Janus::tracegroup) ) { + *_vtdsp->_trs << " -> VS_SYNC_GROUP_TIME (data) G" << e.value().grp << " " + << hex << showbase + << self_id() << " -> " << out_ev.dest() << dec << endl; + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + Send( out_ev ); +} + + DEFINE_RESPONSE_TABLE( VTHandler ) EV_Event_base_T_( ST_NULL, VS_NEW_MEMBER, VSNewMember, VSsync_rq ) EV_Event_base_T_( ST_NULL, VS_OUT_MEMBER, VSOutMember, VSsync_rq ) EV_Event_base_T_( ST_NULL, VS_SYNC_TIME, VSsync_time, VSsync ) + EV_Event_base_T_( ST_NULL, VS_MERGE_GROUP, VSMergeRemoteGroup, VSsync_rq ) END_RESPONSE_TABLE } // namespace vt This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-10-05 17:28:46
|
Revision: 1758 http://complement.svn.sourceforge.net/complement/?rev=1758&view=rev Author: complement Date: 2007-10-05 10:28:42 -0700 (Fri, 05 Oct 2007) Log Message: ----------- test may throw skip_exception to signal that it skipped Modified Paths: -------------- trunk/complement/explore/include/exam/suite.h trunk/complement/explore/lib/exam/ChangeLog trunk/complement/explore/lib/exam/Makefile.inc trunk/complement/explore/lib/exam/suite.cc trunk/complement/explore/lib/janus/ut/vt_operations.cc trunk/complement/explore/lib/janus/ut/vt_operations.h trunk/complement/explore/lib/janus/ut/vt_remote.cc Modified: trunk/complement/explore/include/exam/suite.h =================================================================== --- trunk/complement/explore/include/exam/suite.h 2007-10-05 10:01:09 UTC (rev 1757) +++ trunk/complement/explore/include/exam/suite.h 2007-10-05 17:28:42 UTC (rev 1758) @@ -159,6 +159,11 @@ { }; +class skip_exception : + public std::exception +{ +}; + class test_suite { private: Modified: trunk/complement/explore/lib/exam/ChangeLog =================================================================== --- trunk/complement/explore/lib/exam/ChangeLog 2007-10-05 10:01:09 UTC (rev 1757) +++ trunk/complement/explore/lib/exam/ChangeLog 2007-10-05 17:28:42 UTC (rev 1758) @@ -1,3 +1,10 @@ +2007-10-05 Petr Ovtchenkov <pt...@is...> + + * suite.h, suite.cc: test may throw skip_exception to signal + that it skipped. + + * libexam: version 0.4.0. + 2007-09-07 Petr Ovtchenkov <pt...@is...> * suite.h: added macro EXAM_CHECK_ASYNC_F, EXAM_ERROR_ASYNC_F Modified: trunk/complement/explore/lib/exam/Makefile.inc =================================================================== --- trunk/complement/explore/lib/exam/Makefile.inc 2007-10-05 10:01:09 UTC (rev 1757) +++ trunk/complement/explore/lib/exam/Makefile.inc 2007-10-05 17:28:42 UTC (rev 1758) @@ -2,6 +2,6 @@ LIBNAME = exam MAJOR = 0 -MINOR = 3 +MINOR = 4 PATCH = 0 SRC_CC = logger.cc suite.cc Modified: trunk/complement/explore/lib/exam/suite.cc =================================================================== --- trunk/complement/explore/lib/exam/suite.cc 2007-10-05 10:01:09 UTC (rev 1757) +++ trunk/complement/explore/lib/exam/suite.cc 2007-10-05 17:28:42 UTC (rev 1758) @@ -245,6 +245,14 @@ local_logger->tc( base_logger::skip, _test[v].name ); } } + catch ( skip_exception& ) { + _lock_ll.lock(); + local_logger->tc_break(); + _lock_ll.unlock(); + ++_stat.skipped; + scoped_lock lk( _lock_ll ); + local_logger->tc( base_logger::skip, _test[v].name ); + } catch ( init_exception& ) { _lock_ll.lock(); local_logger->tc_break(); Modified: trunk/complement/explore/lib/janus/ut/vt_operations.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_operations.cc 2007-10-05 10:01:09 UTC (rev 1757) +++ trunk/complement/explore/lib/janus/ut/vt_operations.cc 2007-10-05 17:28:42 UTC (rev 1758) @@ -9,6 +9,29 @@ using namespace std; +vtime_operations::vtime_operations() : + fname( "/tmp/yanus_test.shm" ) +{ + try { + seg.allocate( fname, 4*4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0600 ); + b2 = new ( shm_b.allocate( 1 ) ) xmt::__barrier<true>(); + } + catch ( const xmt::shm_bad_alloc& err ) { + b2 = 0; + // err.what(); + } +} + +vtime_operations::~vtime_operations() +{ + if ( b2 ) { + b2->~__barrier<true>(); + shm_b.deallocate( b2, 1 ); + } + seg.deallocate(); + unlink( fname ); +} + int EXAM_IMPL(vtime_operations::vt_compare) { const oid_type t0(0); Modified: trunk/complement/explore/lib/janus/ut/vt_operations.h =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_operations.h 2007-10-05 10:01:09 UTC (rev 1757) +++ trunk/complement/explore/lib/janus/ut/vt_operations.h 2007-10-05 17:28:42 UTC (rev 1758) @@ -4,36 +4,49 @@ #define __vt_operations_h #include <exam/suite.h> +#include <mt/xmt.h> +#include <mt/shm.h> namespace janus { -struct vtime_operations +class vtime_operations { - int EXAM_DECL(vt_compare); - int EXAM_DECL(vt_add); - int EXAM_DECL(vt_diff); - int EXAM_DECL(vt_max); + public: + vtime_operations(); + ~vtime_operations(); - int EXAM_DECL(gvt_add); + int EXAM_DECL(vt_compare); + int EXAM_DECL(vt_add); + int EXAM_DECL(vt_diff); + int EXAM_DECL(vt_max); - int EXAM_DECL(VTMess_core); + int EXAM_DECL(gvt_add); - int EXAM_DECL(vt_object); + int EXAM_DECL(VTMess_core); - int EXAM_DECL(VTDispatch1); - int EXAM_DECL(VTDispatch2); + int EXAM_DECL(vt_object); - int EXAM_DECL(VTHandler1); - int EXAM_DECL(VTHandler2); + int EXAM_DECL(VTDispatch1); + int EXAM_DECL(VTDispatch2); - int EXAM_DECL(VTSubscription); - int EXAM_DECL(VTEntryIntoGroup); - int EXAM_DECL(VTEntryIntoGroup2); - int EXAM_DECL(VTEntryIntoGroup3); + int EXAM_DECL(VTHandler1); + int EXAM_DECL(VTHandler2); - int EXAM_DECL(remote); - int EXAM_DECL(mgroups); - int EXAM_DECL(wellknownhost); + int EXAM_DECL(VTSubscription); + int EXAM_DECL(VTEntryIntoGroup); + int EXAM_DECL(VTEntryIntoGroup2); + int EXAM_DECL(VTEntryIntoGroup3); + + int EXAM_DECL(remote); + int EXAM_DECL(mgroups); + int EXAM_DECL(wellknownhost); + + private: + const char *fname; + xmt::shm_alloc<0> seg; + xmt::allocator_shm<xmt::__condition<true>,0> shm_cnd; + xmt::allocator_shm<xmt::__barrier<true>,0> shm_b; + xmt::__barrier<true> *b2; }; } // namespace janus Modified: trunk/complement/explore/lib/janus/ut/vt_remote.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_remote.cc 2007-10-05 10:01:09 UTC (rev 1757) +++ trunk/complement/explore/lib/janus/ut/vt_remote.cc 2007-10-05 17:28:42 UTC (rev 1758) @@ -179,21 +179,24 @@ 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; + if ( b2 == 0 ) { + throw exam::skip_exception(); + } + // 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>(); + // 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(); long res_flag = 0; - b.wait(); + b2->wait(); { VTHandler obj0; // this need to keep VSHostMgr after YaRemote exit @@ -264,7 +267,7 @@ obj1.JoinGroup( janus::vs_base::first_user_group ); - b.wait(); + b2->wait(); // while ( obj1.vtdispatcher()->vs_known_processes() < 2 ) { // xmt::delay( xmt::timespec( 0, 1000000 ) ); @@ -299,36 +302,39 @@ EXAM_CHECK( obj1.ocount == 1 ); } - (&b)->~__barrier<true>(); - shm_b.deallocate( &b, 1 ); + // (&b)->~__barrier<true>(); + // shm_b.deallocate( &b, 1 ); } catch ( const xmt::shm_bad_alloc& err ) { EXAM_ERROR( err.what() ); } - seg.deallocate(); - unlink( fname ); + // seg.deallocate(); + // unlink( fname ); return EXAM_RESULT; } int EXAM_IMPL(vtime_operations::mgroups) { - 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; + if ( b2 == 0 ) { + throw exam::skip_exception(); + } + // 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>(); + // 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(); long res_flag = 0; - b.wait(); + b2->wait(); { VTHandler obj0; // this need to keep VSHostMgr after YaRemote exit @@ -379,7 +385,7 @@ obj1.JoinGroup( janus::vs_base::first_user_group ); obj1.JoinGroup( janus::vs_base::first_user_group + 1); - b.wait(); + b2->wait(); obj1.wait_greeting(); obj1.wait_greeting2(); @@ -414,29 +420,33 @@ cerr << obj1.ocount << endl; } - (&b)->~__barrier<true>(); - shm_b.deallocate( &b, 1 ); + // (&b)->~__barrier<true>(); + // shm_b.deallocate( &b, 1 ); } catch ( const xmt::shm_bad_alloc& err ) { EXAM_ERROR( err.what() ); } - seg.deallocate(); - unlink( fname ); + // seg.deallocate(); + // unlink( fname ); return EXAM_RESULT; } int EXAM_IMPL(vtime_operations::wellknownhost) { - 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; + if ( b2 == 0 ) { + throw exam::skip_exception(); + } + // 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>(); + // 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>(); VSHostMgr::add_wellknown( "localhost:6980" ); VSHostMgr::add_srvport( 6980 ); @@ -446,7 +456,7 @@ long res_flag = 0; - b.wait(); + b2->wait(); { YaRemote obj1( "obj client" ); @@ -468,7 +478,7 @@ obj1.JoinGroup( janus::vs_base::first_user_group ); - b.wait(); + b2->wait(); // while ( obj1.vtdispatcher()->vs_known_processes() < 2 ) { // xmt::delay( xmt::timespec( 0, 1000000 ) ); @@ -502,15 +512,15 @@ // cerr << obj1.vtdispatcher()->vs_known_processes() << endl; } - (&b)->~__barrier<true>(); - shm_b.deallocate( &b, 1 ); + // (&b)->~__barrier<true>(); + // shm_b.deallocate( &b, 1 ); } catch ( const xmt::shm_bad_alloc& err ) { EXAM_ERROR( err.what() ); } - seg.deallocate(); - unlink( fname ); + // seg.deallocate(); + // unlink( fname ); return EXAM_RESULT; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-10-09 11:30:05
|
Revision: 1761 http://complement.svn.sourceforge.net/complement/?rev=1761&view=rev Author: complement Date: 2007-10-09 04:29:47 -0700 (Tue, 09 Oct 2007) Log Message: ----------- send notification about group members as response to VS_MERGE_GROUP event [via VS_OLD_MEMBER_RV]; libjanus: version 0.6.0. Modified Paths: -------------- trunk/complement/explore/include/janus/janus.h trunk/complement/explore/include/janus/vtime.h trunk/complement/explore/lib/janus/ChangeLog trunk/complement/explore/lib/janus/Makefile.inc trunk/complement/explore/lib/janus/janus.cc trunk/complement/explore/lib/janus/samples/point1/point1.cc Modified: trunk/complement/explore/include/janus/janus.h =================================================================== --- trunk/complement/explore/include/janus/janus.h 2007-10-08 13:04:57 UTC (rev 1760) +++ trunk/complement/explore/include/janus/janus.h 2007-10-09 11:29:47 UTC (rev 1761) @@ -148,6 +148,7 @@ void VSNewMember( const stem::Event_base<VSsync_rq>& e ); void VSNewRemoteMemberDirect( const stem::Event_base<VSsync_rq>& e ); void VSNewRemoteMemberRevert( const stem::Event_base<VSsync_rq>& e ); + void VSOldRemoteMemberRevert( const stem::Event_base<VSsync_rq>& e ); void VSOutMember( const stem::Event_base<VSsync_rq>& e ); void VSMergeRemoteGroup( const stem::Event_base<VSsync_rq>& e ); Modified: trunk/complement/explore/include/janus/vtime.h =================================================================== --- trunk/complement/explore/include/janus/vtime.h 2007-10-08 13:04:57 UTC (rev 1760) +++ trunk/complement/explore/include/janus/vtime.h 2007-10-09 11:29:47 UTC (rev 1761) @@ -402,9 +402,10 @@ #define VS_SYNC_TIME 0x303 #define VS_NEW_REMOTE_MEMBER 0x304 #define VS_NEW_MEMBER_RV 0x305 -#define VS_HOST_MGR_FINAL 0x306 -#define VS_MERGE_GROUP 0x307 -#define VS_SYNC_GROUP_TIME 0x308 +#define VS_OLD_MEMBER_RV 0x306 +#define VS_HOST_MGR_FINAL 0x307 +#define VS_MERGE_GROUP 0x308 +#define VS_SYNC_GROUP_TIME 0x309 #ifdef __USE_STLPORT_HASH # undef __USE_STLPORT_HASH Modified: trunk/complement/explore/lib/janus/ChangeLog =================================================================== --- trunk/complement/explore/lib/janus/ChangeLog 2007-10-08 13:04:57 UTC (rev 1760) +++ trunk/complement/explore/lib/janus/ChangeLog 2007-10-09 11:29:47 UTC (rev 1761) @@ -1,3 +1,11 @@ +2007-10-09 Petr Ovtchenkov <pt...@is...> + + * janus.h, janus.cc, vtime.h: send notification about + group members as response to VS_MERGE_GROUP event + [via VS_OLD_MEMBER_RV]; + + * libjanus: version 0.6.0. + 2007-10-05 Petr Ovtchenkov <pt...@is...> * janus.h, janus.cc, vtime.h, vtime.cc: cover use-case Modified: trunk/complement/explore/lib/janus/Makefile.inc =================================================================== --- trunk/complement/explore/lib/janus/Makefile.inc 2007-10-08 13:04:57 UTC (rev 1760) +++ trunk/complement/explore/lib/janus/Makefile.inc 2007-10-09 11:29:47 UTC (rev 1761) @@ -2,6 +2,6 @@ LIBNAME = janus MAJOR = 0 -MINOR = 5 +MINOR = 6 PATCH = 0 SRC_CC = vtime.cc janus.cc vshostmgr.cc Modified: trunk/complement/explore/lib/janus/janus.cc =================================================================== --- trunk/complement/explore/lib/janus/janus.cc 2007-10-08 13:04:57 UTC (rev 1760) +++ trunk/complement/explore/lib/janus/janus.cc 2007-10-09 11:29:47 UTC (rev 1761) @@ -886,17 +886,30 @@ // gvtime_type gvt; // gvtime_type gvt_last; // stem::addr_type addr = stem::badaddr; + stem::Event_base<VSsync_rq> e_rv( VS_OLD_MEMBER_RV ); + e_rv.dest( e.src() ); + e_rv.value().grp = grp; + + bool sync = false; + for ( ; range.first != range.second; ++range.first ) { vt_map_type::iterator i = vtmap.find( range.first->second ); - if ( i != vtmap.end() && ((i->second.stem_addr() & stem::extbit) == 0 )) { - // i->second.get_gvt( gvt ); - // if ( gvt_last < gvt ) { - // swap( gvt_last, gvt ); - // addr = i->second.stem_addr(); - // } - e.dest( i->second.stem_addr() ); - Forward( e ); - return; + if ( i != vtmap.end() ) { + if ( (i->second.stem_addr() & stem::extbit) == 0 ) { + e_rv.src( i->second.stem_addr() ); + Forward( e_rv ); + if ( !sync ) { + // i->second.get_gvt( gvt ); + // if ( gvt_last < gvt ) { + // swap( gvt_last, gvt ); + // addr = i->second.stem_addr(); + // } + e.dest( i->second.stem_addr() ); + Forward( e ); + // return; + sync = true; + } + } } } // e.dest( addr ); @@ -907,12 +920,14 @@ void Janus::VSsync_group_time( const stem::Event_base<VSsync>& ev ) { const group_type grp = ev.value().grp; + const addr_type addr = ev.src(); #ifdef __FIT_VS_TRACE try { scoped_lock lk(_lock_tr); if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { int f = _trs->flags(); - *_trs << " VS sync remote group time G" << grp << endl; + *_trs << " VS sync group time from " << hex << showbase << addr + << dec << " G" << grp << endl; #ifdef STLPORT _trs->flags( f ); #else @@ -924,11 +939,17 @@ } #endif // __FIT_VS_TRACE + // const gaddr_type oid = manager()->reflect( addr ); // ???? oid == gaddr + + // add remote memer of group grp + // vtmap[oid].add( addr, grp ); + // grmap.insert( make_pair(grp,oid) ); + // find all local group members and forward data as VS_SYNC_TIME pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( grp ); stem::Event_base<VSsync> e( VS_SYNC_TIME ); - e.src( ev.src() ); - e.value().grp = ev.value().grp; + e.src( addr ); + e.value().grp = grp; e.value().gvt.gvt = ev.value().gvt.gvt; e.value().mess = ev.value().mess; @@ -941,11 +962,41 @@ } } +void Janus::VSOldRemoteMemberRevert( const stem::Event_base<VSsync_rq>& ev ) +{ + const group_type grp = ev.value().grp; + const addr_type addr = ev.src(); + const gaddr_type oid = manager()->reflect( addr ); // ???? oid == gaddr +#ifdef __FIT_VS_TRACE + try { + scoped_lock lk(_lock_tr); + if ( _trs != 0 && _trs->good() && (_trflags & tracegroup) ) { + int f = _trs->flags(); + *_trs << " VS remote " << hex << showbase << addr + << " (" << oid << ") " + << dec << " G" << grp << endl; +#ifdef STLPORT + _trs->flags( f ); +#else + _trs->flags( static_cast<std::_Ios_Fmtflags>(f) ); +#endif + } + } + catch ( ... ) { + } +#endif // __FIT_VS_TRACE + // add remote memer of group grp + vtmap[oid].add( addr, grp ); + grmap.insert( make_pair(grp,oid) ); +} + + DEFINE_RESPONSE_TABLE( Janus ) EV_Event_base_T_( ST_NULL, VS_MESS, JaDispatch, VSmess ) EV_Event_base_T_( ST_NULL, VS_NEW_MEMBER, VSNewMember, VSsync_rq ) EV_Event_base_T_( ST_NULL, VS_NEW_REMOTE_MEMBER, VSNewRemoteMemberDirect, VSsync_rq ) EV_Event_base_T_( ST_NULL, VS_NEW_MEMBER_RV, VSNewRemoteMemberRevert, VSsync_rq ) + EV_Event_base_T_( ST_NULL, VS_OLD_MEMBER_RV, VSOldRemoteMemberRevert, VSsync_rq ) EV_Event_base_T_( ST_NULL, VS_OUT_MEMBER, VSOutMember, VSsync_rq ) EV_Event_base_T_( ST_NULL, VS_MERGE_GROUP, VSMergeRemoteGroup, VSsync_rq ) EV_Event_base_T_( ST_NULL, VS_SYNC_GROUP_TIME, VSsync_group_time, VSsync ) Modified: trunk/complement/explore/lib/janus/samples/point1/point1.cc =================================================================== --- trunk/complement/explore/lib/janus/samples/point1/point1.cc 2007-10-08 13:04:57 UTC (rev 1760) +++ trunk/complement/explore/lib/janus/samples/point1/point1.cc 2007-10-09 11:29:47 UTC (rev 1761) @@ -108,8 +108,14 @@ while ( cin.good() ) { cin >> line; if ( !cin.fail() ) { + cerr << "local: " << line << endl; ev.value() = line; - sample.JaSend( ev ); + try { + sample.JaSend( ev ); + } + catch ( std::domain_error& err ) { + cerr << err.what() << endl; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-10-09 12:51:54
|
Revision: 1762 http://complement.svn.sourceforge.net/complement/?rev=1762&view=rev Author: complement Date: 2007-10-09 05:51:51 -0700 (Tue, 09 Oct 2007) Log Message: ----------- preserve and restore format flags during trace; libstem: library version 4.6.5. Modified Paths: -------------- trunk/complement/explore/include/stem/EventHandler.h trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/Makefile.inc Modified: trunk/complement/explore/include/stem/EventHandler.h =================================================================== --- trunk/complement/explore/include/stem/EventHandler.h 2007-10-09 11:29:47 UTC (rev 1761) +++ trunk/complement/explore/include/stem/EventHandler.h 2007-10-09 12:51:51 UTC (rev 1762) @@ -472,15 +472,26 @@ } stem::code_type code = event.code(); __AnyPMFentry *entry; + int f = out.flags(); while ( first != last ) { if ( table.get( code, *first, entry ) ) { - out << "\tMessage 0x" << std::hex << code << std::dec << " catcher " + out << "\tMessage " << std::hex << std::showbase << code << std::dec << " catcher " << entry->pmf_name << " (state " << *first << ")"; +#ifdef STLPORT + out.flags( f ); +#else + out.flags( static_cast<std::_Ios_Fmtflags>(f) ); +#endif return true; } ++first; } - out << "\tCatcher not found for message 0x" << std::hex << code << std::dec; + out << "\tCatcher not found for message " << std::hex << std::showbase << code; +#ifdef STLPORT + out.flags( f ); +#else + out.flags( static_cast<std::_Ios_Fmtflags>(f) ); +#endif return false; } @@ -492,10 +503,11 @@ } __AnyPMFentry *entry; typename table_type::const_iterator1 i1 = table.begin(); + int f = out.flags(); while ( i1 != table.end() ) { stem::code_type key1 = table.key1st(*i1); typename table_type::const_iterator2 i2 = table.begin( i1 ); - out << "\tMessage: " << std::hex << key1 << std::dec << std::endl; + out << "\tMessage: " << std::hex << std::showbase << key1 << std::dec << std::endl; while ( i2 != table.end( i1 ) ) { state_type key2 = table.key2nd(*i2++); table.get( key1, key2, entry ); @@ -503,6 +515,11 @@ } ++i1; } +#ifdef STLPORT + out.flags( f ); +#else + out.flags( static_cast<std::_Ios_Fmtflags>(f) ); +#endif } typedef std::list<state_type> HistoryContainer; Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2007-10-09 11:29:47 UTC (rev 1761) +++ trunk/complement/explore/lib/stem/ChangeLog 2007-10-09 12:51:51 UTC (rev 1762) @@ -1,3 +1,10 @@ +2007-10-09 Petr Ovtchenkov <pt...@is...> + + * EventHandler.h: preserve and restore format flags during + trace; + + * libstem: library version 4.6.5. + 2007-10-01 Petr Ovtchenkov <pt...@is...> * NetTransport.h, NetTransport.cc: comment NetTransportMP, Modified: trunk/complement/explore/lib/stem/Makefile.inc =================================================================== --- trunk/complement/explore/lib/stem/Makefile.inc 2007-10-09 11:29:47 UTC (rev 1761) +++ trunk/complement/explore/lib/stem/Makefile.inc 2007-10-09 12:51:51 UTC (rev 1762) @@ -3,7 +3,7 @@ LIBNAME = stem MAJOR = 4 MINOR = 6 -PATCH = 4 +PATCH = 5 SRC_CC = _EventHandler.cc NetTransport.cc EvManager.cc EvPack.cc crc.cc \ Names.cc Cron.cc This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-10-16 08:03:31
|
Revision: 1766 http://complement.svn.sourceforge.net/complement/?rev=1766&view=rev Author: complement Date: 2007-10-16 01:03:28 -0700 (Tue, 16 Oct 2007) Log Message: ----------- use hash instead of map, this save ~10 bytes per stem object; in gaddr_type structure use 32-bit integer for pid, most systems has max(pid) < 2^15, 64-bit Linuxes max(pid) < 4*1024*1024, but some other unixes may has larger numbers... check it; this save ~24 bytes per stem object; libstem: library version 4.7.0 Modified Paths: -------------- trunk/complement/explore/include/janus/vtime.h trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/include/stem/Event.h trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/EvPack.cc trunk/complement/explore/lib/stem/Makefile.inc Modified: trunk/complement/explore/include/janus/vtime.h =================================================================== --- trunk/complement/explore/include/janus/vtime.h 2007-10-09 13:14:54 UTC (rev 1765) +++ trunk/complement/explore/include/janus/vtime.h 2007-10-16 08:03:28 UTC (rev 1766) @@ -6,6 +6,16 @@ #include <algorithm> #include <list> #include <vector> +#include <iterator> +#include <istream> +#include <ostream> +#include <stdexcept> + +#include <stem/Event.h> +#include <stem/EventHandler.h> + +#include <mt/time.h> + #ifdef STLPORT # include <unordered_map> # include <unordered_set> @@ -24,16 +34,8 @@ # define __USE_STD_TR1 # endif #endif -#include <iterator> -#include <istream> -#include <ostream> -#include <stdexcept> -#include <stem/Event.h> -#include <stem/EventHandler.h> -#include <mt/time.h> - namespace janus { // typedef stem::addr_type oid_type; @@ -41,6 +43,7 @@ } // namespace janus +#if 0 #if defined(__USE_STLPORT_HASH) || defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) # define __HASH_NAMESPACE std #endif @@ -68,6 +71,7 @@ } // namespace __HASH_NAMESPACE #undef __HASH_NAMESPACE +#endif namespace janus { Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2007-10-09 13:14:54 UTC (rev 1765) +++ trunk/complement/explore/include/stem/EvManager.h 2007-10-16 08:03:28 UTC (rev 1766) @@ -21,7 +21,7 @@ #include <stdint.h> #include <string> -#include <map> +// #include <map> #include <deque> #include <mt/xmt.h> @@ -31,6 +31,25 @@ #include <stem/EventHandler.h> #include <ostream> +#ifdef STLPORT +# include <unordered_map> +# include <unordered_set> +// # include <hash_map> +// # include <hash_set> +// # define __USE_STLPORT_HASH +# define __USE_STLPORT_TR1 +#else +# if defined(__GNUC__) && (__GNUC__ < 4) +# include <ext/hash_map> +# include <ext/hash_set> +# define __USE_STD_HASH +# else +# include <tr1/unordered_map> +# include <tr1/unordered_set> +# define __USE_STD_TR1 +# endif +#endif + namespace stem { namespace detail { @@ -76,6 +95,35 @@ class EvManager { private: +#ifdef __USE_STLPORT_HASH + typedef std::hash_map<addr_type,EventHandler *> local_heap_type; + typedef std::hash_map<addr_type,std::string> info_heap_type; + + typedef std::hash_map<addr_type,gaddr_type> ext_uuid_heap_type; + + typedef std::hash_multimap<gaddr_type,std::pair<addr_type,detail::transport> > uuid_tr_heap_type; + typedef std::hash_multimap<detail::transport_entry,gaddr_type> tr_uuid_heap_type; +#endif +#ifdef __USE_STD_HASH + typedef __gnu_cxx::hash_map<addr_type,EventHandler *> local_heap_type; + typedef __gnu_cxx::hash_map<addr_type,std::string> info_heap_type; + + typedef __gnu_cxx::hash_map<addr_type,gaddr_type> ext_uuid_heap_type; + + typedef __gnu_cxx::hash_multimap<gaddr_type,std::pair<addr_type,detail::transport> > uuid_tr_heap_type; + typedef __gnu_cxx::hash_multimap<detail::transport_entry,gaddr_type> tr_uuid_heap_type; +#endif +#if defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) + typedef std::tr1::unordered_map<addr_type,EventHandler *> local_heap_type; + typedef std::tr1::unordered_map<addr_type,std::string> info_heap_type; + + typedef std::tr1::unordered_map<addr_type,gaddr_type> ext_uuid_heap_type; + + typedef std::tr1::unordered_multimap<gaddr_type,std::pair<addr_type,detail::transport> > uuid_tr_heap_type; + typedef std::tr1::unordered_multimap<detail::transport_entry,gaddr_type> tr_uuid_heap_type; +#endif + +#if 0 typedef std::map<addr_type,EventHandler *> local_heap_type; typedef std::map<addr_type,std::string> info_heap_type; @@ -83,6 +131,7 @@ typedef std::multimap<gaddr_type,std::pair<addr_type,detail::transport> > uuid_tr_heap_type; typedef std::multimap<detail::transport_entry,gaddr_type> tr_uuid_heap_type; +#endif static bool tr_compare( const std::pair<gaddr_type,std::pair<addr_type,detail::transport> >& l, const std::pair<gaddr_type,std::pair<addr_type,detail::transport> >& r ) { return l.second.second < r.second.second; } @@ -268,4 +317,17 @@ } // namespace stem +#ifdef __USE_STLPORT_HASH +# undef __USE_STLPORT_HASH +#endif +#ifdef __USE_STD_HASH +# undef __USE_STD_HASH +#endif +#ifdef __USE_STLPORT_TR1 +# undef __USE_STLPORT_TR1 +#endif +#ifdef __USE_STD_TR1 +# undef __USE_STD_TR1 +#endif + #endif // __stem_EvManager_h Modified: trunk/complement/explore/include/stem/Event.h =================================================================== --- trunk/complement/explore/include/stem/Event.h 2007-10-09 13:14:54 UTC (rev 1765) +++ trunk/complement/explore/include/stem/Event.h 2007-10-16 08:03:28 UTC (rev 1766) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/17 22:15:41 ptr> +// -*- C++ -*- Time-stamp: <07/10/15 22:41:17 ptr> /* * @@ -31,6 +31,25 @@ #include <mt/uid.h> #include <mt/xmt.h> +#ifdef STLPORT +# include <unordered_map> +# include <unordered_set> +// # include <hash_map> +// # include <hash_set> +// # define __USE_STLPORT_HASH +# define __USE_STLPORT_TR1 +#else +# if defined(__GNUC__) && (__GNUC__ < 4) +# include <ext/hash_map> +# include <ext/hash_set> +# define __USE_STD_HASH +# else +# include <tr1/unordered_map> +# include <tr1/unordered_set> +# define __USE_STD_TR1 +# endif +#endif + namespace stem { typedef uint32_t addr_type; @@ -77,7 +96,10 @@ { } xmt::uuid_type hid; - int64_t pid; // pid_t defined as int, so it may be int64_t + // int64_t pid; // pid_t defined as int, so it may be int64_t + // most systems has max(pid) < 2^15, 64-bit Linuxes max(pid) < 4 *1024 *1024 + // but some other unixes may has larger numbers... check it + uint32_t pid; stem::addr_type addr; __FIT_DECLSPEC virtual void pack( std::ostream& ) const; @@ -618,4 +640,45 @@ namespace EDS = stem; +#if defined(__USE_STLPORT_HASH) || defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) +# define __HASH_NAMESPACE std #endif +#if defined(__USE_STD_HASH) +# define __HASH_NAMESPACE __gnu_cxx +#endif + +namespace __HASH_NAMESPACE { + +#ifdef __USE_STD_TR1 +namespace tr1 { +#endif + +template <> +struct hash<stem::gaddr_type> +{ + size_t operator()(const stem::gaddr_type& __x) const + { return __x.addr | (__x.pid << 23); } +}; + +#ifdef __USE_STD_TR1 +} +#endif + +} // namespace __HASH_NAMESPACE + +#undef __HASH_NAMESPACE + +#ifdef __USE_STLPORT_HASH +# undef __USE_STLPORT_HASH +#endif +#ifdef __USE_STD_HASH +# undef __USE_STD_HASH +#endif +#ifdef __USE_STLPORT_TR1 +# undef __USE_STLPORT_TR1 +#endif +#ifdef __USE_STD_TR1 +# undef __USE_STD_TR1 +#endif + +#endif // __stem_Event_h Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2007-10-09 13:14:54 UTC (rev 1765) +++ trunk/complement/explore/lib/stem/ChangeLog 2007-10-16 08:03:28 UTC (rev 1766) @@ -1,3 +1,16 @@ +2007-10-16 Petr Ovtchenkov <pt...@is...> + + * Event.h, EvManager.h: use hash instead of map, this save + ~10 bytes per stem object; + + * Event.h, EvPack.cc: in gaddr_type structure use 32-bit + integer for pid, most systems has max(pid) < 2^15, 64-bit + Linuxes max(pid) < 4*1024*1024, but some other unixes may + has larger numbers... check it; this save ~24 bytes per + stem object; + + * libstem: library version 4.7.0 + 2007-10-09 Petr Ovtchenkov <pt...@is...> * EventHandler.h: preserve and restore format flags during Modified: trunk/complement/explore/lib/stem/EvPack.cc =================================================================== --- trunk/complement/explore/lib/stem/EvPack.cc 2007-10-09 13:14:54 UTC (rev 1765) +++ trunk/complement/explore/lib/stem/EvPack.cc 2007-10-16 08:03:28 UTC (rev 1766) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/03 09:22:05 ptr> +// -*- C++ -*- Time-stamp: <07/10/15 22:35:41 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -143,7 +143,7 @@ __FIT_DECLSPEC void gaddr_type::_xnet_pack( char *buf ) const { - uint64_t _pid = to_net( pid ); + /* uint64_t */ uint32_t _pid = to_net( pid ); addr_type _addr = to_net( addr ); // copy( (char *)hid.u.b, (char *)hid.u.b + 16, buf ); Modified: trunk/complement/explore/lib/stem/Makefile.inc =================================================================== --- trunk/complement/explore/lib/stem/Makefile.inc 2007-10-09 13:14:54 UTC (rev 1765) +++ trunk/complement/explore/lib/stem/Makefile.inc 2007-10-16 08:03:28 UTC (rev 1766) @@ -2,8 +2,8 @@ LIBNAME = stem MAJOR = 4 -MINOR = 6 -PATCH = 5 +MINOR = 7 +PATCH = 0 SRC_CC = _EventHandler.cc NetTransport.cc EvManager.cc EvPack.cc crc.cc \ Names.cc Cron.cc This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-10-24 14:25:15
|
Revision: 1767 http://complement.svn.sourceforge.net/complement/?rev=1767&view=rev Author: complement Date: 2007-10-24 07:25:11 -0700 (Wed, 24 Oct 2007) Log Message: ----------- allow build without BFD; libxmt 1.14.1 Modified Paths: -------------- trunk/complement/explore/include/config/_linux.h trunk/complement/explore/include/config/feature.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/callstack.cc Modified: trunk/complement/explore/include/config/_linux.h =================================================================== --- trunk/complement/explore/include/config/_linux.h 2007-10-16 08:03:28 UTC (rev 1766) +++ trunk/complement/explore/include/config/_linux.h 2007-10-24 14:25:11 UTC (rev 1767) @@ -82,4 +82,12 @@ #define __FIT_EPOLL */ +/* + * Normally, in Linux present BFD mechanism + */ + +#ifndef __FIT_DISABLE_BFD +# define __FIT_PRESENT_BFD +#endif + #endif /* __config__linux_h */ Modified: trunk/complement/explore/include/config/feature.h =================================================================== --- trunk/complement/explore/include/config/feature.h 2007-10-16 08:03:28 UTC (rev 1766) +++ trunk/complement/explore/include/config/feature.h 2007-10-24 14:25:11 UTC (rev 1767) @@ -114,9 +114,27 @@ /* Store information about stack before create thread in xmt::Thread; - useful for debugging. + useful for debugging. Real implementation require BFD. */ +/* #define __FIT_CREATE_THREAD_STACK_INFO +*/ +/* + Don't use bfd, even if it available on platform; printing stack + impossible without BFD (Binary File Descriptor). +*/ + +#define __FIT_DISABLE_BFD + +#if 0 +#ifdef __FIT_DISABLE_BFD +/* Without BFD we can't take info about stack */ +# ifdef __FIT_CREATE_THREAD_STACK_INFO +# undef __FIT_CREATE_THREAD_STACK_INFO +# endif +#endif +#endif + #endif /* __config_feature_h */ Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-10-16 08:03:28 UTC (rev 1766) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-10-24 14:25:11 UTC (rev 1767) @@ -1,3 +1,11 @@ +2007-10-24 Petr Ovtchenkov <pt...@is...> + + * config/feature.h, config/_linux.h: allow build without BFD; + + * callstack.cc: suggest dummy call, if no BFD available; + + * libxmt: version 1.14.1 + 2007-09-24 Petr Ovtchenkov <pt...@is...> * callstack.h, callstack.cc: print call stack to ostream, initial Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2007-10-16 08:03:28 UTC (rev 1766) +++ trunk/complement/explore/lib/mt/Makefile.inc 2007-10-24 14:25:11 UTC (rev 1767) @@ -3,6 +3,6 @@ LIBNAME = xmt MAJOR = 1 MINOR = 14 -PATCH = 0 +PATCH = 1 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc callstack.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/callstack.cc =================================================================== --- trunk/complement/explore/lib/mt/callstack.cc 2007-10-16 08:03:28 UTC (rev 1766) +++ trunk/complement/explore/lib/mt/callstack.cc 2007-10-24 14:25:11 UTC (rev 1767) @@ -28,6 +28,23 @@ // #include <stdlib.h> // #include <stdio.h> +#ifndef __FIT_PRESENT_BFD + +#include <mt/callstack.h> + +namespace xmt { + +using namespace std; + +void callstack( std::ostream& s ) +{ + s << "Sorry, compiled without BFD\n"; +} + +} // namespace xmt + +#else // __FIT_PRESENT_BFD + #include <bfd.h> #include <signal.h> #include <ucontext.h> @@ -302,3 +319,4 @@ } // namespace xmt +#endif // __FIT_PRESENT_BFD This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |