complement-svn Mailing List for Complement (Page 2)
Status: Pre-Alpha
Brought to you by:
complement
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(61) |
Nov
(76) |
Dec
(39) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(33) |
Feb
(41) |
Mar
(16) |
Apr
|
May
(22) |
Jun
(14) |
Jul
(64) |
Aug
(60) |
Sep
(35) |
Oct
(34) |
Nov
(10) |
Dec
(5) |
2008 |
Jan
(4) |
Feb
(24) |
Mar
(10) |
Apr
(30) |
May
(15) |
Jun
(50) |
Jul
(20) |
Aug
(7) |
Sep
(8) |
Oct
(10) |
Nov
|
Dec
|
From: <com...@us...> - 2008-07-30 17:27:09
|
Revision: 1953 http://complement.svn.sourceforge.net/complement/?rev=1953&view=rev Author: complement Date: 2008-07-30 17:27:06 +0000 (Wed, 30 Jul 2008) Log Message: ----------- throw system_error when problem detected in mutexes and conditions fix barrier::wait: pthread_barrier_wait return PTHREAD_BARRIER_SERIAL_THREAD for one thread and 0 for others; fix error processing in semaphore: sem_* functions report error via errno, not via return value. Modified Paths: -------------- trunk/complement/explore/include/mt/condition_variable trunk/complement/explore/include/mt/mutex trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc Modified: trunk/complement/explore/include/mt/condition_variable =================================================================== --- trunk/complement/explore/include/mt/condition_variable 2008-07-30 17:26:23 UTC (rev 1952) +++ trunk/complement/explore/include/mt/condition_variable 2008-07-30 17:27:06 UTC (rev 1953) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/26 10:18:13 ptr> +// -*- C++ -*- Time-stamp: <08/07/30 20:49:38 ptr> /* * Copyright (c) 1997-1999, 2002-2008 @@ -27,8 +27,8 @@ #ifdef __FIT_PTHREADS # include <semaphore.h> #endif +#include <mt/system_error> - namespace std { namespace tr2 { @@ -104,7 +104,7 @@ int ret = pthread_cond_wait( &_cond, const_cast<pthread_mutex_t *>(&lock.m->_M_lock) ); if ( ret ) { lock.lock(); - // throw system_error + throw std::system_error( ret, std::get_posix_category() ); } #endif } @@ -128,7 +128,7 @@ if ( ret == ETIMEDOUT ) { return false; } - // throw system_error + throw std::system_error( ret, std::get_posix_category() ); } #endif return true; @@ -259,7 +259,7 @@ int ret = pthread_cond_wait( &_cond, lock.native_handle() ); if ( ret ) { lock.lock(); - // throw system_error + throw std::system_error( ret, std::get_posix_category() ); } #endif } @@ -284,7 +284,7 @@ if ( ret == ETIMEDOUT ) { return false; } - // throw system_error + throw std::system_error( ret, std::get_posix_category() ); } #endif #ifdef __FIT_WIN32THREADS @@ -424,8 +424,9 @@ SetEvent( _cond ); #endif #ifdef __FIT_PTHREADS - if ( pthread_cond_signal( &_cond ) ) { - // throw system_error + int ret = pthread_cond_signal( &_cond ); + if ( ret ) { + throw std::system_error( ret, std::get_posix_category() ); } #endif } @@ -448,8 +449,9 @@ } #endif #ifdef __FIT_PTHREADS - if ( pthread_cond_broadcast( &_cond ) ) { - // throw system_error + int ret = pthread_cond_broadcast( &_cond ); + if ( ret ) { + throw std::system_error( ret, std::get_posix_category() ); } #endif } @@ -478,7 +480,7 @@ while ( !_val ) { ret = pthread_cond_wait( &_cond, &_lock._M_lock ); if ( ret ) { - // throw system_error + throw std::system_error( ret, std::get_posix_category() ); } } #endif @@ -498,7 +500,7 @@ if ( ret == ETIMEDOUT ) { return _val; } - // throw system_error + throw std::system_error( ret, std::get_posix_category() ); } } #endif @@ -601,9 +603,8 @@ } #endif #ifdef __FIT_PTHREADS - int ret = sem_wait( &_sem ); - if ( ret != 0 ) { - // throw system_error + if ( sem_wait( &_sem ) ) { + throw std::system_error( errno, std::get_posix_category() ); } #endif } @@ -614,12 +615,11 @@ return _cnt > 0 ? (--_cnt, this->wait()) : -1; #endif #ifdef __FIT_PTHREADS - int ret = sem_trywait( &_sem ); - if ( ret != 0 ) { - if ( ret == EBUSY ) { + if ( sem_trywait( &_sem ) ) { + if ( errno == std::posix_error::resource_unavailable_try_again ) { return false; } - // throw system_error + throw std::system_error( errno, std::get_posix_category() ); } return true; #endif @@ -632,12 +632,11 @@ t.tv_sec = abs_time.seconds_since_epoch(); t.tv_nsec = static_cast<long>( abs_time.nanoseconds_since_epoch().count() % nanoseconds::ticks_per_second ); # if !(defined(__FreeBSD__) || defined(__OpenBSD__)) - int ret = sem_timedwait( &_sem, &t ); - if ( ret != 0 ) { - if ( ret == ETIMEDOUT ) { + if ( sem_timedwait( &_sem, &t ) ) { + if ( errno == std::posix_error::timed_out ) { return false; } - // throw system_error + throw std::system_error( errno, std::get_posix_category() ); } # endif #endif @@ -690,9 +689,8 @@ } #endif #ifdef __FIT_PTHREADS - int ret = sem_post( &_sem ); - if ( ret != 0 ) { - // throw system_error + if ( sem_post( &_sem ) ) { + throw std::system_error( errno, std::get_posix_category() ); } #endif } @@ -704,9 +702,8 @@ #endif #ifdef __FIT_PTHREADS int v; - int e = sem_getvalue( &_sem, &v ); - if ( e != 0 ) { - // throw system_error + if ( sem_getvalue( &_sem, &v ) ) { + throw std::system_error( errno, std::get_posix_category() ); } return v; @@ -755,8 +752,8 @@ { #ifdef __FIT_PTHREADS int ret = pthread_barrier_wait( &_barr ); - if ( ret != 0 ) { - // throw system_error + if ( ret != PTHREAD_BARRIER_SERIAL_THREAD && ret != 0 ) { + throw std::system_error( ret, std::get_posix_category() ); } #endif } Modified: trunk/complement/explore/include/mt/mutex =================================================================== --- trunk/complement/explore/include/mt/mutex 2008-07-30 17:26:23 UTC (rev 1952) +++ trunk/complement/explore/include/mt/mutex 2008-07-30 17:27:06 UTC (rev 1953) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/26 10:20:36 ptr> +// -*- C++ -*- Time-stamp: <08/07/30 19:44:33 ptr> /* * Copyright (c) 1997-1999, 2002-2008 @@ -98,15 +98,17 @@ pthread_mutexattr_init( &att ); # ifdef __FIT_PSHARED_MUTEX if ( SCOPE ) { - if ( pthread_mutexattr_setpshared( &att, PTHREAD_PROCESS_SHARED ) != 0 ) { - throw std::invalid_argument( detail::_notpshared ); + int ret = pthread_mutexattr_setpshared( &att, PTHREAD_PROCESS_SHARED ); + if ( ret != 0 ) { + throw std::system_error( ret, std::get_posix_category(), detail::_notpshared ); } } # endif // __FIT_PSHARED_MUTEX # ifdef __FIT_XSI_THR // Unix 98 or X/Open System Interfaces Extention if ( RECURSIVE_SAFE ) { - if ( pthread_mutexattr_settype( &att, PTHREAD_MUTEX_RECURSIVE ) != 0 ) { - throw std::invalid_argument( detail::_notrecursive ); + int ret = pthread_mutexattr_settype( &att, PTHREAD_MUTEX_RECURSIVE ); + if ( ret != 0 ) { + throw std::system_error( ret, std::get_posix_category(), detail::_notrecursive ); } } # endif @@ -218,9 +220,9 @@ void lock() { #ifdef __FIT_PTHREADS - int /* std::error_catalog::value_type */ e = pthread_mutex_lock( &this->_M_lock ); + int e = pthread_mutex_lock( &this->_M_lock ); if ( e ) { - // throw std::system_error( e, native_catalog ); + throw std::system_error( e, std::get_posix_category() ); } #endif #ifdef __FIT_WIN32THREADS @@ -514,8 +516,9 @@ pthread_rwlockattr_t att; pthread_rwlockattr_init( &att ); # ifdef __FIT_PSHARED_MUTEX - if ( pthread_rwlockattr_setpshared( &att, PTHREAD_PROCESS_SHARED ) != 0 ) { - throw std::invalid_argument( std::tr2::detail::_notpshared ); + int ret = pthread_rwlockattr_setpshared( &att, PTHREAD_PROCESS_SHARED ); + if ( ret != 0 ) { + throw std::system_error( ret, std::get_posix_category(), std::tr2::detail::_notpshared ); } # endif // __FIT_PSHARED_MUTEX pthread_rwlock_init( &_M_lock, &att ); Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-07-30 17:26:23 UTC (rev 1952) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-07-30 17:27:06 UTC (rev 1953) @@ -1,5 +1,12 @@ 2008-07-30 Petr Ovtchenkov <pt...@is...> + * condition_variable: throw system_error when problem detected; + fix barrier::wait---PTHREAD_BARRIER_SERIAL_THREAD is also + normal return value; fix error processing in semaphore---sem_* + functions indicate error via errno, not via return; + + * mutex: throw system_error when problem detected; + * uid.cc: use system_error for detailed report about problem; * libxmt: bump revision to 2.0.9. Modified: trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-30 17:26:23 UTC (rev 1952) +++ trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-30 17:27:06 UTC (rev 1953) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/07 14:23:07 yeti> +// -*- C++ -*- Time-stamp: <08/07/30 20:51:24 ptr> /* * Copyright (c) 2006-2008 @@ -137,13 +137,18 @@ void thread_func3() { - EXAM_CHECK_ASYNC( val == 0 ); + try { + EXAM_CHECK_ASYNC( val == 0 ); - bar.wait(); + bar.wait(); - std::tr2::lock_guard<std::tr2::mutex> lock( lk ); + std::tr2::lock_guard<std::tr2::mutex> lock( lk ); - ++val; + ++val; + } + catch ( std::runtime_error& err ) { + EXAM_ERROR_ASYNC( err.what() ); + } } int EXAM_IMPL(mt_test_wg21::barrier) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-30 17:26:26
|
Revision: 1952 http://complement.svn.sourceforge.net/complement/?rev=1952&view=rev Author: complement Date: 2008-07-30 17:26:23 +0000 (Wed, 30 Jul 2008) Log Message: ----------- in uid implementation use system_error for detailed report about problem libxmt: revision 2.0.9. save errno instead of just fail flag; throw system error with errno---details about problem Revision Links: -------------- http://complement.svn.sourceforge.net/complement/?rev=2&view=rev Modified Paths: -------------- trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/uid.cc Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-07-25 06:35:15 UTC (rev 1951) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-07-30 17:26:23 UTC (rev 1952) @@ -1,3 +1,9 @@ +2008-07-30 Petr Ovtchenkov <pt...@is...> + + * uid.cc: use system_error for detailed report about problem; + + * libxmt: bump revision to 2.0.9. + 2008-07-25 Petr Ovtchenkov <pt...@is...> * system_error, system_error.cc: basic functionality Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2008-07-25 06:35:15 UTC (rev 1951) +++ trunk/complement/explore/lib/mt/Makefile.inc 2008-07-30 17:26:23 UTC (rev 1952) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <08/07/25 10:25:30 ptr> +# -*- Makefile -*- Time-stamp: <08/07/30 19:12:30 ptr> LIBNAME = xmt MAJOR = 2 MINOR = 0 -PATCH = 8 +PATCH = 9 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc callstack.cc system_error.cc thread.cc \ date_time.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2008-07-25 06:35:15 UTC (rev 1951) +++ trunk/complement/explore/lib/mt/uid.cc 2008-07-30 17:26:23 UTC (rev 1952) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/07 14:19:23 yeti> +// -*- C++ -*- Time-stamp: <08/07/30 19:12:12 ptr> /* * Copyright (c) 2006, 2008 @@ -16,6 +16,7 @@ #include <unistd.h> #include <fcntl.h> #include <stdexcept> +#include <mt/system_error> #include <iostream> @@ -62,21 +63,24 @@ static uuid_type _host_id; char _host_id_str[48]; // 37 really - bool fail; + int err; }; uuid_type __uid_init::_host_id; +static const char boot_id[] = "/proc/sys/kernel/random/boot_id"; +static const char uu_id[] = "/proc/sys/kernel/random/uuid"; + __uid_init::__uid_init() : - fail( false ) + err( 0 ) { - int fd = ::open( "/proc/sys/kernel/random/boot_id", O_RDONLY ); + int fd = ::open( boot_id, O_RDONLY ); if ( (fd < 0) || (::read( fd, _host_id_str, 36 ) != 36 )) { + err = errno; if ( fd >= 0 ) { ::close( fd ); } - fail = true; } else { _host_id_str[36] = '\0'; ::close( fd ); @@ -142,8 +146,8 @@ const char *hostid_str() throw (runtime_error) { static detail::__uid_init _uid; - if ( _uid.fail ) { - throw runtime_error( "can't read hostid" ); + if ( _uid.err != 0 ) { + throw system_error( _uid.err, get_posix_category(), detail::boot_id ); } return _uid._host_id_str; } @@ -158,12 +162,13 @@ { char buf[37]; - int fd = ::open( "/proc/sys/kernel/random/uuid", O_RDONLY ); + int fd = ::open( detail::uu_id, O_RDONLY ); if ( (fd < 0) || (::read( fd, buf, 37 ) != 37) ) { + system_error se( errno, get_posix_category(), string( "Can't generate UID; " ) + detail::uu_id ); if ( fd >= 0 ) { ::close( fd ); } - throw runtime_error( "Can't generate UID" ); + throw se; // return std::string(); } ::close( fd ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-25 06:35:19
|
Revision: 1951 http://complement.svn.sourceforge.net/complement/?rev=1951&view=rev Author: complement Date: 2008-07-25 06:35:15 +0000 (Fri, 25 Jul 2008) Log Message: ----------- system_error basic functionality; libxmt version 2.0.8 basic functionality of system_error and friends, as described in http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2008/n2691.pdf; no locale support; no real difference between system_category and posix_category; basic trivial test for system_error. Modified Paths: -------------- trunk/complement/explore/include/mt/system_error trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/system_error.cc trunk/complement/explore/lib/mt/ut/Makefile.inc trunk/complement/explore/lib/mt/ut/mt_test_suite.cc Added Paths: ----------- trunk/complement/explore/lib/mt/ut/sys_err_test.cc trunk/complement/explore/lib/mt/ut/sys_err_test.h Modified: trunk/complement/explore/include/mt/system_error =================================================================== --- trunk/complement/explore/include/mt/system_error 2008-07-25 06:34:37 UTC (rev 1950) +++ trunk/complement/explore/include/mt/system_error 2008-07-25 06:35:15 UTC (rev 1951) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/20 19:12:24 ptr> +// -*- C++ -*- Time-stamp: <08/07/25 08:47:37 ptr> /* * Copyright (c) 2007-2008 @@ -25,6 +25,7 @@ #endif #include <cerrno> +#include <ostream> namespace std { @@ -413,6 +414,36 @@ static const error_category& posix_category = get_posix_category(); static const error_category& native_category = get_system_category(); +class error_condition +{ + public: + error_condition(); + error_condition( int val, const error_category& category ); + template <class ErrorConditionEnum> + error_condition( ErrorConditionEnum err, + typename std::tr1::enable_if<is_error_condition_enum<ErrorConditionEnum>::value,void>::type* = 0 ); + + void assign( int val, const error_category& category ); + template <class ErrorConditionEnum> + typename std::tr1::enable_if<is_error_condition_enum<ErrorConditionEnum>::value, error_code >::type& operator =( ErrorConditionEnum err ); + void clear(); + + int value() const + { return v; } + const error_category& category() const + { return *c; } + string message() const + { return c->message( v ); } + operator bool() const + { return v != 0; } + + private: + int v; + const error_category* c; +}; + +bool operator <( const error_condition&, const error_condition& ); + class error_code { public: @@ -426,57 +457,50 @@ typename std::tr1::enable_if<is_error_code_enum<ErrorCodeEnum>::value, error_code >::type& operator =( ErrorCodeEnum err ); void clear(); - int value() const; - const error_category& category() const; - error_condition default_error_condition() const; - string message() const; - operator bool() const; + int value() const + { return v; } + const error_category& category() const + { return *c; } + error_condition default_error_condition() const + { return c->default_error_condition( v ); } + string message() const + { return c->message( v ); } + operator bool() const + { return v != 0; } private: int v; - const error_category& c; + const error_category* c; }; bool operator <( const error_code&, const error_code& ); +template <class charT, class traits> +basic_ostream<charT,traits>& operator <<( basic_ostream<charT,traits>& os, const error_code& e ) +{ return os << e.category().name() << ':' << e.value(); } -class error_condition -{ - public: - error_condition(); - error_condition( int val, const error_category& category ); - template <class ErrorConditionEnum> - error_condition( ErrorConditionEnum err, - typename std::tr1::enable_if<is_error_condition_enum<ErrorConditionEnum>::value,void>::type* = 0 ); - - void assign( int val, const error_category& category ); - template <class ErrorConditionEnum> - typename std::tr1::enable_if<is_error_condition_enum<ErrorConditionEnum>::value, error_code >::type& operator =( ErrorConditionEnum err ); - void clear(); - - int value() const; - const error_category& category() const; - string message() const; - operator bool() const; - - private: - int val_; - const error_category& cat_; -}; - -bool operator <( const error_condition&, const error_condition& ); - class system_error : public runtime_error { public: system_error( error_code code, const string& what ); system_error( error_code code ); - system_error( error_code code, const error_category& category, + system_error( int code, const error_category& category, const string& what ); - system_error( error_code code, const error_category& category ); - error_code& code() const throw(); + system_error( int code, const error_category& category ); + ~system_error() throw(); + + const error_code& code() const throw() + { return ecode_; } const char* what() const throw(); + + private: + error_code ecode_; + + enum { _bufsize = 256 }; + + mutable char _buf[_bufsize]; + mutable char *_dbuf; }; } // namespace std Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-07-25 06:34:37 UTC (rev 1950) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-07-25 06:35:15 UTC (rev 1951) @@ -1,3 +1,16 @@ +2008-07-25 Petr Ovtchenkov <pt...@is...> + + * system_error, system_error.cc: basic functionality + of system_error and friends, as described in + http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2008/n2691.pdf; + no locale support; no real difference between system_category + and posix_category; + + * mt_test_suite.cc, sys_err_test.h, sys_err_test.cc: basic + trivial test for system_error; + + * libxmt: bump revision to 2.0.8. + 2008-07-21 Petr Ovtchenkov <pt...@is...> * mutex: avoid usage of error_catalog---interface in Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2008-07-25 06:34:37 UTC (rev 1950) +++ trunk/complement/explore/lib/mt/Makefile.inc 2008-07-25 06:35:15 UTC (rev 1951) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <08/07/07 10:35:20 ptr> +# -*- Makefile -*- Time-stamp: <08/07/25 10:25:30 ptr> LIBNAME = xmt MAJOR = 2 MINOR = 0 -PATCH = 7 +PATCH = 8 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc callstack.cc system_error.cc thread.cc \ date_time.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/system_error.cc =================================================================== --- trunk/complement/explore/lib/mt/system_error.cc 2008-07-25 06:34:37 UTC (rev 1950) +++ trunk/complement/explore/lib/mt/system_error.cc 2008-07-25 06:35:15 UTC (rev 1951) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/20 19:55:22 ptr> +// -*- C++ -*- Time-stamp: <08/07/25 10:04:45 ptr> /* * Copyright (c) 2007-2008 @@ -8,8 +8,7 @@ * * Based on JTC1/SC22/WG21 C++ 0x working draft; * - * This is revision 2 of <system_error>: - * http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2007/n2303.html + * http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2008/n2691.pdf */ #include "mt/system_error" @@ -261,7 +260,7 @@ * An operation that would block was attempted on an object that has non-blocking mode selected. Trying the same operation again will block until some external condition makes it possible to read, write, or - connect (whatever the operation). You can use @code{select} to find out + connect (whatever the operation). You can use select to find out when the operation will be possible. Portability Note: In many older Unix systems, this condition @@ -543,10 +542,10 @@ _sys_err[EILSEQ] = "Invalid or incomplete multibyte or wide character"; #endif #ifdef EBACKGROUND - /* In the GNU system, servers supporting the @code{term} protocol return + /* In the GNU system, servers supporting the term protocol return this error for certain operations when the caller is not in the foreground process group of the terminal. Users do not usually see this - error because functions such as @code{read} and @code{write} translate + error because functions such as read and write translate it into a SIGTTIN or SIGTTOU signal. */ _sys_err[EBACKGROUND] = "Inappropriate operation for background process"; #endif @@ -824,7 +823,6 @@ public: virtual const char* name() const; virtual std::string message( int err ) const; - }; const char* posix_error_category::name() const @@ -867,6 +865,9 @@ using namespace detail; +error_category::~error_category() +{ } + error_condition error_category::default_error_condition( int err ) const { return error_condition( err, *this ); @@ -907,5 +908,171 @@ return detail::_system_error_category; } +error_code::error_code() : + v( 0 ), + c( &detail::_system_error_category ) +{ } + +error_code::error_code( int val, const error_category& cat ) : + v( val ), + c( &cat ) +{ } + +void error_code::assign( int val, const error_category& cat ) +{ + v = val; + c = &cat; +} + +void error_code::clear() +{ + v = 0; + c = &detail::_system_error_category; +} + +namespace posix_error { + +error_code make_error_code( posix_errno err ) +{ return error_code( err, detail::_posix_error_category ); } + +error_condition make_error_condition( posix_errno err ) +{ return error_condition( err, detail::_posix_error_category ); } + +} // namespace posix_error + +bool operator <( const error_code& l, const error_code& r ) +{ + return l.category() == r.category() ? l.value() < r.value() : l.category() < r.category(); +} + +error_condition::error_condition() : + v( 0 ), + c( &detail::_posix_error_category ) +{ } + +error_condition::error_condition( int val, const error_category& cat ) : + v( val ), + c( &cat ) +{ } + +void error_condition::assign( int val, const error_category& cat ) +{ + v = val; + c = &cat; +} + +void error_condition::clear() +{ + v = 0; + c = &detail::_posix_error_category; +} + +bool operator <( const error_condition& l, const error_condition& r ) +{ + return l.category() == r.category() ? l.value() < r.value() : l.category() < r.category(); +} + +bool operator ==( const error_code& l, const error_code& r ) +{ return l.category() == r.category() && l.value() == r.value(); } + +bool operator ==( const error_code& l, const error_condition& r ) +{ return l.category().equivalent( l.value(), r ) || r.category().equivalent( l, r.value() ); } + +bool operator ==( const error_condition& l, const error_code& r ) +{ return r.category().equivalent( r.value(), l ) || l.category().equivalent( r, l.value() ); } + +bool operator ==( const error_condition& l, const error_condition& r ) +{ return l.category() == r.category() && l.value() == r.value(); } + +bool operator !=( const error_code& l, const error_code& r ) +{ return !(l == r); } + +bool operator !=( const error_code& l, const error_condition& r ) +{ return !(l == r); } + +bool operator !=( const error_condition& l, const error_code& r ) +{ return !(l == r); } + +bool operator !=( const error_condition& l, const error_condition& r ) +{ return !(l == r); } + +system_error::system_error( error_code code, const string& what ) : + runtime_error( what ), + ecode_( code.value(), code.category() ), + _dbuf( 0 ) +{ } + +system_error::system_error( error_code code ) : + runtime_error( "" ), + ecode_( code.value(), code.category() ), + _dbuf( 0 ) +{ } + +system_error::system_error( int code, const error_category& category, + const string& what ) : + runtime_error( what ), + ecode_( code, category ), + _dbuf( 0 ) +{ } + +system_error::system_error( int code, const error_category& category ) : + runtime_error( "" ), + ecode_( code, category ), + _dbuf( 0 ) +{ } + +system_error::~system_error() throw() +{ + if ( _dbuf ) { + free( _dbuf ); + } +} + +const char* system_error::what() const throw() +{ + size_t sz = strlen( runtime_error::what() ); + size_t sz_add = sz + ecode_.message().length() + (sz > 0 ? 3 : 1); // + ": ", not \0 + + if ( sz_add < _bufsize ) { + if ( sz > 0 ) { + memcpy( _buf, runtime_error::what(), sz ); + _buf[sz++] = ':'; + _buf[sz++] = ' '; + } + memcpy( _buf + sz, ecode_.message().data(), ecode_.message().length() ); + _buf[sz_add - 1] = 0; + } else { + _dbuf = static_cast<char *>(malloc( sz_add )); + if ( _dbuf != 0 ) { + if ( sz > 0 ) { + memcpy( _dbuf, runtime_error::what(), sz ); + _dbuf[sz++] = ':'; + _dbuf[sz++] = ' '; + } + memcpy( _dbuf + sz, ecode_.message().data(), ecode_.message().length() ); + _dbuf[sz_add - 1] = 0; + return _dbuf; + } + if ( sz > 0 ) { + strncpy( _buf, runtime_error::what(), _bufsize - 1 ); + } + if ( sz < (_bufsize - 1) ) { + if ( sz > 0 ) { + _buf[sz++] = ':'; + } + if ( sz < (_bufsize - 1) ) { + if ( sz > 0 ) { + _buf[sz++] = ' '; + } + if ( sz < (_bufsize - 1) ) { + strncpy( _buf + sz, ecode_.message().data(), _bufsize - sz - 1 ); + } + } + } + _buf[_bufsize - 1] = 0; + } + + return _buf; +} + } // namespace std - Modified: trunk/complement/explore/lib/mt/ut/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/ut/Makefile.inc 2008-07-25 06:34:37 UTC (rev 1950) +++ trunk/complement/explore/lib/mt/ut/Makefile.inc 2008-07-25 06:35:15 UTC (rev 1951) @@ -1,7 +1,7 @@ -# -*- makefile -*- Time-stamp: <08/07/02 09:03:03 ptr> +# -*- makefile -*- Time-stamp: <08/07/25 09:39:59 ptr> PRGNAME = mt_ut -SRC_CC = timespec.cc \ +SRC_CC = sys_err_test.cc timespec.cc \ signal-1.cc signal-3.cc \ mt_test.cc shm_test.cc mt_test_suite.cc \ mt_test_wg21.cc Modified: trunk/complement/explore/lib/mt/ut/mt_test_suite.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2008-07-25 06:34:37 UTC (rev 1950) +++ trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2008-07-25 06:35:15 UTC (rev 1951) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/07 13:15:01 yeti> +// -*- C++ -*- Time-stamp: <08/07/25 09:43:40 ptr> /* * Copyright (c) 2006-2008 @@ -12,6 +12,7 @@ #include "mt_test.h" #include "shm_test.h" #include "mt_test_wg21.h" +#include "sys_err_test.h" #include <config/feature.h> @@ -30,6 +31,7 @@ int main( int argc, const char** argv ) { exam::test_suite t( "libxmt test" ); + sys_err_test sys_err; mt_test test; #if 0 @@ -44,6 +46,7 @@ exam::test_suite::test_case_type tc[3]; + t.add( &sys_err_test::file, sys_err, "system error, no such file" ); // 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" ); Added: trunk/complement/explore/lib/mt/ut/sys_err_test.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/sys_err_test.cc (rev 0) +++ trunk/complement/explore/lib/mt/ut/sys_err_test.cc 2008-07-25 06:35:15 UTC (rev 1951) @@ -0,0 +1,41 @@ +// -*- C++ -*- Time-stamp: <08/07/25 10:08:26 ptr> + +/* + * Copyright (c) 2008 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +#include "sys_err_test.h" + +#include <mt/system_error> +#include <cerrno> +#include <string> + +// #include <iostream> + +#include <stdio.h> + +using namespace std; + +int EXAM_IMPL(sys_err_test::file) +{ + FILE* f = fopen( "/tmp/no-such-file", "r" ); + + if ( f == 0 ) { + system_error se1( errno, std::get_posix_category(), string( "Test" ) ); + + EXAM_CHECK( strcmp( se1.what(), "Test: No such file or directory" ) == 0 ); + + system_error se2( errno, std::get_posix_category() ); + + EXAM_CHECK( strcmp( se2.what(), "No such file or directory" ) == 0 ); + } else { + EXAM_ERROR( "file exist, but shouldn't" ); + fclose( f ); + } + + return EXAM_RESULT; +} Added: trunk/complement/explore/lib/mt/ut/sys_err_test.h =================================================================== --- trunk/complement/explore/lib/mt/ut/sys_err_test.h (rev 0) +++ trunk/complement/explore/lib/mt/ut/sys_err_test.h 2008-07-25 06:35:15 UTC (rev 1951) @@ -0,0 +1,24 @@ +// -*- C++ -*- Time-stamp: <08/07/25 09:34:11 ptr> + +/* + * Copyright (c) 2008 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +#ifndef __SYS_ERR_TEST_H +#define __SYS_ERR_TEST_H + +#define FIT_EXAM + +#include <exam/suite.h> + +class sys_err_test +{ + public: + int EXAM_DECL(file); +}; + +#endif // __SYS_ERR_TEST_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-25 06:34:42
|
Revision: 1950 http://complement.svn.sourceforge.net/complement/?rev=1950&view=rev Author: complement Date: 2008-07-25 06:34:37 +0000 (Fri, 25 Jul 2008) Log Message: ----------- follow C++ draft for system_error See http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2008/n2691.pdf Modified Paths: -------------- trunk/complement/explore/include/mt/mutex trunk/complement/explore/include/mt/system_error trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/system_error.cc Modified: trunk/complement/explore/include/mt/mutex =================================================================== --- trunk/complement/explore/include/mt/mutex 2008-07-25 06:34:06 UTC (rev 1949) +++ trunk/complement/explore/include/mt/mutex 2008-07-25 06:34:37 UTC (rev 1950) @@ -218,7 +218,7 @@ void lock() { #ifdef __FIT_PTHREADS - std::error_catalog::value_type e = pthread_mutex_lock( &this->_M_lock ); + int /* std::error_catalog::value_type */ e = pthread_mutex_lock( &this->_M_lock ); if ( e ) { // throw std::system_error( e, native_catalog ); } Modified: trunk/complement/explore/include/mt/system_error =================================================================== --- trunk/complement/explore/include/mt/system_error 2008-07-25 06:34:06 UTC (rev 1949) +++ trunk/complement/explore/include/mt/system_error 2008-07-25 06:34:37 UTC (rev 1950) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/02/24 13:19:17 ptr> +// -*- C++ -*- Time-stamp: <08/07/20 19:12:24 ptr> /* * Copyright (c) 2007-2008 @@ -8,135 +8,475 @@ * * Based on JTC1/SC22/WG21 C++ 0x working draft; * - * This is revision 2 of <system_error>: - * http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2007/n2303.html + * http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2008/n2691.pdf */ #ifndef __SYSTEM_ERROR #define __SYSTEM_ERROR -#include <locale> +// #include <locale> #include <string> #include <stdexcept> -namespace std -{ +#ifdef STLPORT +#include <type_traits> +#else +... +#endif -struct error_catalog -{ - typedef int value_type; +#include <cerrno> - static const value_type address_family_not_supported; - static const value_type address_in_use; - static const value_type address_not_available; - static const value_type already_connected; - static const value_type argument_list_too_long; - static const value_type argument_out_of_domain; - static const value_type bad_address; - static const value_type bad_file_descriptor; - static const value_type bad_message; - static const value_type broken_pipe; - static const value_type connection_aborted; - static const value_type connection_refused; - static const value_type connection_reset; - static const value_type cross_device_link; - static const value_type destination_address_required; - static const value_type device_or_resource_busy; - static const value_type directory_not_empty; - static const value_type executable_format_error; - static const value_type file_exists; - static const value_type file_too_large; - static const value_type filename_too_long; - static const value_type function_not_supported; - static const value_type host_unreachable; - static const value_type identifier_removed; - static const value_type illegal_byte_sequence; - static const value_type inappropriate_io_control_operation; - static const value_type interrupted; - static const value_type invalid_argument; - static const value_type invalid_seek; - static const value_type io_error; - static const value_type is_a_directory; - static const value_type message_too_long; - static const value_type network_down; - static const value_type network_reset; - static const value_type network_unreachable; - static const value_type no_buffer_space; - static const value_type no_child_process; - static const value_type no_link; - static const value_type no_lock_available; - static const value_type no_message_available; - static const value_type no_message; - static const value_type no_space_on_device; - static const value_type no_stream_resources; - static const value_type no_such_device_or_address; - static const value_type no_such_device; - static const value_type no_such_file_or_directory; - static const value_type no_such_process; - static const value_type not_a_directory; - static const value_type not_a_socket; - static const value_type not_a_stream; - static const value_type not_connected; - static const value_type not_enough_memory; - static const value_type not_supported; - static const value_type operation_already_in_progress; - static const value_type operation_canceled; - static const value_type operation_in_progress; - static const value_type operation_not_permitted; - static const value_type operation_not_supported; - static const value_type owner_dead; - static const value_type permission_denied; - static const value_type protocol_error; - static const value_type protocol_not_available; - static const value_type protocol_not_supported; - static const value_type read_only_file_system; - static const value_type resource_deadlock_would_occur; - static const value_type result_out_of_range; - static const value_type state_not_recoverable; - static const value_type stream_timeout; - static const value_type text_file_busy; - static const value_type timed_out; - static const value_type too_many_files_open_in_system; - static const value_type too_many_files_open; - static const value_type too_many_links; - static const value_type too_many_synbolic_link_levels; - static const value_type try_again; - static const value_type value_too_large; - static const value_type wrong_protocol_type; +namespace std { - virtual const value_type last_value() const throw(); +class error_category; +class error_code; +class error_condition; +class system_error; - virtual bool is_valid_value(value_type) const throw(); +template <class T> +struct is_error_code_enum : + public std::tr1::false_type +{ }; - virtual const char* str(value_type) const throw(); +template <class T> +struct is_error_condition_enum : + public std::tr1::false_type +{ }; - const locale& getloc() const throw() - { return _M_loc; } +namespace posix_error { - error_catalog(const locale& __loc = locale::classic()) throw() : - _M_loc( __loc ) - { } +enum posix_errno { +#ifdef EAFNOSUPPORT + address_family_not_supported = EAFNOSUPPORT, +#else +#endif +#ifdef EADDRINUSE + address_in_use = EADDRINUSE, +#else +#endif +#ifdef EADDRNOTAVAIL + address_not_available = EADDRNOTAVAIL, +#else +#endif +#ifdef EISCONN + already_connected = EISCONN, +#else +#endif +#ifdef E2BIG + argument_list_too_long = E2BIG, +#else +#endif +#ifdef EDOM + argument_out_of_domain = EDOM, +#else +#endif +#ifdef EFAULT + bad_address = EFAULT, +#else +#endif +#ifdef EBADF + bad_file_descriptor = EBADF, +#else +#endif +#ifdef EBADMSG + bad_message = EBADMSG, +#else +#endif +#ifdef EPIPE + broken_pipe = EPIPE, +#else +#endif +#ifdef ECONNABORTED + connection_aborted = ECONNABORTED, +#else +#endif +#ifdef EALREADY + connection_already_in_progress = EALREADY, +#else +#endif +#ifdef ECONNREFUSED + connection_refused = ECONNREFUSED, +#else +#endif +#ifdef ECONNRESET + connection_reset = ECONNRESET, +#else +#endif +#ifdef EXDEV + cross_device_link = EXDEV, +#else +#endif +#ifdef EDESTADDRREQ + destination_address_required = EDESTADDRREQ, +#else +#endif +#ifdef EBUSY + device_or_resource_busy = EBUSY, +#else +#endif +#ifdef ENOTEMPTY + directory_not_empty = ENOTEMPTY, +#else +#endif +#ifdef ENOEXEC + executable_format_error = ENOEXEC, +#else +#endif +#ifdef EEXIST + file_exists = EEXIST, +#else +#endif +#ifdef EFBIG + file_too_large = EFBIG, +#else +#endif +#ifdef ENAMETOOLONG + filename_too_long = ENAMETOOLONG, +#else +#endif +#ifdef ENOSYS + function_not_supported = ENOSYS, +#else +#endif +#ifdef EHOSTUNREACH + host_unreachable = EHOSTUNREACH, +#else +#endif +#ifdef EIDRM + identifier_removed = EIDRM, +#else +#endif +#ifdef EILSEQ + illegal_byte_sequence = EILSEQ, +#else +#endif +#ifdef ENOTTY + inappropriate_io_control_operation = ENOTTY, +#else +#endif +#ifdef EINTR + interrupted = EINTR, +#else +#endif +#ifdef EINVAL + invalid_argument = EINVAL, +#else +#endif +#ifdef ESPIPE + invalid_seek = ESPIPE, +#else +#endif +#ifdef EIO + io_error = EIO, +#else +#endif +#ifdef EISDIR + is_a_directory = EISDIR, +#else +#endif +#ifdef EMSGSIZE + message_too_long = EMSGSIZE, +#else +#endif +#ifdef ENETDOWN + network_down = ENETDOWN, +#else +#endif +#ifdef ENETRESET + network_reset = ENETRESET, +#else +#endif +#ifdef ENETUNREACH + network_unreachable = ENETUNREACH, +#else +#endif +#ifdef ENOBUFS + no_buffer_space = ENOBUFS, +#else +#endif +#ifdef ECHILD + no_child_process = ECHILD, +#else +#endif +#ifdef ENOLINK + no_link = ENOLINK, +#else +#endif +#ifdef ENOLCK + no_lock_available = ENOLCK, +#else +#endif +#ifdef ENODATA + no_message_available = ENODATA, +#else +#endif +#ifdef ENOMSG + no_message = ENOMSG, +#else +#endif +#ifdef ENOPROTOOPT + no_protocol_option = ENOPROTOOPT, +#else +#endif +#ifdef ENOSPC + no_space_on_device = ENOSPC, +#else +#endif +#ifdef ENOSR + no_stream_resources = ENOSR, +#else +#endif +#ifdef ENXIO + no_such_device_or_address = ENXIO, +#else +#endif +#ifdef ENODEV + no_such_device = ENODEV, +#else +#endif +#ifdef ENOENT + no_such_file_or_directory = ENOENT, +#else +#endif +#ifdef ESRCH + no_such_process = ESRCH, +#else +#endif +#ifdef ENOTDIR + not_a_directory = ENOTDIR, +#else +#endif +#ifdef ENOTSOCK + not_a_socket = ENOTSOCK, +#else +#endif +#ifdef ENOSTR + not_a_stream = ENOSTR, +#else +#endif +#ifdef ENOTCONN + not_connected = ENOTCONN, +#else +#endif +#ifdef ENOMEM + not_enough_memory = ENOMEM, +#else +#endif +#ifdef ENOTSUP + not_supported = ENOTSUP, +#else +#endif +#ifdef EALREADY + operation_already_in_progress = EALREADY, +#else +#endif +#ifdef ECANCELED + operation_canceled = ECANCELED, +#else +#endif +#ifdef EINPROGRESS + operation_in_progress = EINPROGRESS, +#else +#endif +#ifdef EPERM + operation_not_permitted = EPERM, +#else +#endif +#ifdef EOPNOTSUPP + operation_not_supported = EOPNOTSUPP, +#else +#endif +#ifdef EOWNERDEAD + owner_dead = EOWNERDEAD, +#else +#endif +#ifdef EACCES + permission_denied = EACCES, +#else +#endif +#ifdef EPROTO + protocol_error = EPROTO, +#else +#endif +#ifdef EPROTONOSUPPORT + protocol_not_supported = EPROTONOSUPPORT, +#else +#endif +#ifdef EROFS + read_only_file_system = EROFS, +#else +#endif +#ifdef EDEADLK + resource_deadlock_would_occur = EDEADLK, +#else +#endif +#ifdef EAGAIN + resource_unavailable_try_again = EAGAIN, +#else +#endif +#ifdef ERANGE + result_out_of_range = ERANGE, +#else +#endif +#ifdef ENOTRECOVERABLE + state_not_recoverable = ENOTRECOVERABLE, +#else +#endif +#ifdef ETIME + stream_timeout = ETIME, +#else +#endif +#ifdef ETXTBSY + text_file_busy = ETXTBSY, +#else +#endif +#ifdef ETIMEDOUT + timed_out = ETIMEDOUT, +#else +#endif +#ifdef ENFILE + too_many_files_open_in_system = ENFILE, +#else +#endif +#ifdef EMFILE + too_many_files_open = EMFILE, +#else +#endif +#ifdef EMLINK + too_many_links = EMLINK, +#else +#endif +#ifdef ELOOP + too_many_synbolic_link_levels = ELOOP, +#else +#endif +#ifdef EOVERFLOW + value_too_large = EOVERFLOW, +#else +#endif +#ifdef EPROTOTYPE + wrong_protocol_type = EPROTOTYPE +#else +#endif +}; - error_catalog(const char* __name) : - _M_loc( __name ) - { } +} // namespace posix_error - virtual ~error_catalog() throw() +template <> +struct is_error_condition_enum<posix_error::posix_errno> : + public std::tr1::true_type +{ }; + +namespace posix_error { + +error_code make_error_code( posix_errno err ); +error_condition make_error_condition( posix_errno err ); + +} // namespace posix_error + +bool operator ==(const error_code& l, const error_code& r ); +bool operator ==(const error_code& l, const error_condition& r ); +bool operator ==(const error_condition& l, const error_code& r ); +bool operator ==(const error_condition& l, const error_condition& r ); + +bool operator !=(const error_code& l, const error_code& r ); +bool operator !=(const error_code& l, const error_condition& r ); +bool operator !=(const error_condition& l, const error_code& r ); +bool operator !=(const error_condition& l, const error_condition& r ); + +class error_category +{ + public: + virtual ~error_category(); + + private: + error_category( const error_category& ); + error_category& operator =( const error_category& ); + + public: + error_category() { } + virtual const char* name() const = 0; + virtual error_condition default_error_condition( int err ) const; + virtual bool equivalent( int code, const error_condition& cnd ) const; + virtual bool equivalent( const error_code& code, int cnd ) const; + virtual string message( int err ) const = 0; - bool operator ==(const error_catalog& __other) const throw(); - bool operator !=(const error_catalog& __other) const throw(); + bool operator ==( const error_category& ) const; + bool operator !=( const error_category& ) const; + bool operator <( const error_category& ) const; +}; +const error_category& get_posix_category(); +const error_category& get_system_category(); + +static const error_category& posix_category = get_posix_category(); +static const error_category& native_category = get_system_category(); + +class error_code +{ + public: + error_code(); + error_code( int val, const error_category& ); + template <class ErrorCodeEnum> + error_code( ErrorCodeEnum err, typename std::tr1::enable_if<is_error_code_enum<ErrorCodeEnum>::value,void>::type* = 0 ); + + void assign( int val, const error_category& ); + template <class ErrorCodeEnum> + typename std::tr1::enable_if<is_error_code_enum<ErrorCodeEnum>::value, error_code >::type& operator =( ErrorCodeEnum err ); + void clear(); + + int value() const; + const error_category& category() const; + error_condition default_error_condition() const; + string message() const; + operator bool() const; + private: - const locale _M_loc; + int v; + const error_category& c; }; +bool operator <( const error_code&, const error_code& ); + + +class error_condition +{ + public: + error_condition(); + error_condition( int val, const error_category& category ); + template <class ErrorConditionEnum> + error_condition( ErrorConditionEnum err, + typename std::tr1::enable_if<is_error_condition_enum<ErrorConditionEnum>::value,void>::type* = 0 ); + + void assign( int val, const error_category& category ); + template <class ErrorConditionEnum> + typename std::tr1::enable_if<is_error_condition_enum<ErrorConditionEnum>::value, error_code >::type& operator =( ErrorConditionEnum err ); + void clear(); + + int value() const; + const error_category& category() const; + string message() const; + operator bool() const; + + private: + int val_; + const error_category& cat_; +}; + +bool operator <( const error_condition&, const error_condition& ); + class system_error : - public std::runtime_error + public runtime_error { public: - system_error( const std::string& ); - system_error( error_catalog::value_type, const error_catalog& ); + system_error( error_code code, const string& what ); + system_error( error_code code ); + system_error( error_code code, const error_category& category, + const string& what ); + system_error( error_code code, const error_category& category ); + error_code& code() const throw(); + const char* what() const throw(); }; } // namespace std Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-07-25 06:34:06 UTC (rev 1949) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-07-25 06:34:37 UTC (rev 1950) @@ -1,3 +1,11 @@ +2008-07-21 Petr Ovtchenkov <pt...@is...> + + * mutex: avoid usage of error_catalog---interface in + system_error changed. + + * system_error, system_error.cc: follow + http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2008/n2691.pdf + 2008-07-07 Petr Ovtchenkov <pt...@is...> * uid.cc, uid.h: convert uid to string; output uid Modified: trunk/complement/explore/lib/mt/system_error.cc =================================================================== --- trunk/complement/explore/lib/mt/system_error.cc 2008-07-25 06:34:06 UTC (rev 1949) +++ trunk/complement/explore/lib/mt/system_error.cc 2008-07-25 06:34:37 UTC (rev 1950) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/02/24 13:36:56 ptr> +// -*- C++ -*- Time-stamp: <08/07/20 19:55:22 ptr> /* * Copyright (c) 2007-2008 @@ -45,15 +45,14 @@ namespace detail { -class _SysErrInit +struct _SysErrInit { - public: - typedef std::vector<char *> container_type; + typedef std::vector<const char *> container_type; _SysErrInit(); container_type _sys_err; - std::error_catalog::value_type _last_value; + container_type::size_type _last_value; }; _SysErrInit::_SysErrInit() : @@ -817,358 +816,95 @@ static _SysErrInit _syserr; +static const std::string _unknown( "Code not specified in this category" ); + +class posix_error_category : + public std::error_category +{ + public: + virtual const char* name() const; + virtual std::string message( int err ) const; + +}; + +const char* posix_error_category::name() const +{ + return "POSIX"; +} + +std::string posix_error_category::message( int err ) const +{ + // bad: allocation present, so no memory may happens... + return (err >= 0) && (err <= _syserr._last_value) && (_syserr._sys_err[err] != 0) ? std::string( _syserr._sys_err[err] ) : _unknown; +} + +class system_error_category : + public std::error_category +{ + public: + virtual const char* name() const; + virtual std::string message( int err ) const; + +}; + +const char* system_error_category::name() const +{ + return "system"; +} + +std::string system_error_category::message( int err ) const +{ + // bad: allocation present, so no memory may happens... + return (err >= 0) && (err <= _syserr._last_value) && (_syserr._sys_err[err] != 0) ? std::string( _syserr._sys_err[err] ) : _unknown; +} + +static posix_error_category _posix_error_category; +static system_error_category _system_error_category; + } // namespace detail namespace std { using namespace detail; -#ifdef EAFNOSUPPORT -const error_catalog::value_type error_catalog::address_family_not_supported = EAFNOSUPPORT; -#else -#endif -#ifdef EADDRINUSE -const error_catalog::value_type error_catalog::address_in_use = EADDRINUSE; -#else -#endif -#ifdef EADDRNOTAVAIL -const error_catalog::value_type error_catalog::address_not_available = EADDRNOTAVAIL; -#else -#endif -#ifdef EISCONN -const error_catalog::value_type error_catalog::already_connected = EISCONN; -#else -#endif -#ifdef E2BIG -const error_catalog::value_type error_catalog::argument_list_too_long = E2BIG; -#else -#endif -#ifdef EDOM -const error_catalog::value_type error_catalog::argument_out_of_domain = EDOM; -#else -#endif -#ifdef EFAULT -const error_catalog::value_type error_catalog::bad_address = EFAULT; -#else -#endif -#ifdef EBADF -const error_catalog::value_type error_catalog::bad_file_descriptor = EBADF; -#else -#endif -#ifdef EBADMSG -const error_catalog::value_type error_catalog::bad_message = EBADMSG; -#else -#endif -#ifdef EPIPE -const error_catalog::value_type error_catalog::broken_pipe = EPIPE; -#else -#endif -#ifdef ECONNABORTED -const error_catalog::value_type error_catalog::connection_aborted = ECONNABORTED; -#else -#endif -#ifdef ECONNREFUSED -const error_catalog::value_type error_catalog::connection_refused = ECONNREFUSED; -#else -#endif -#ifdef ECONNRESET -const error_catalog::value_type error_catalog::connection_reset = ECONNRESET; -#else -#endif -#ifdef EXDEV -const error_catalog::value_type error_catalog::cross_device_link = EXDEV; -#else -#endif -#ifdef EDESTADDRREQ -const error_catalog::value_type error_catalog::destination_address_required = EDESTADDRREQ; -#else -#endif -#ifdef EBUSY -const error_catalog::value_type error_catalog::device_or_resource_busy = EBUSY; -#else -#endif -#ifdef ENOTEMPTY -const error_catalog::value_type error_catalog::directory_not_empty = ENOTEMPTY; -#else -#endif -#ifdef ENOEXEC -const error_catalog::value_type error_catalog::executable_format_error = ENOEXEC; -#else -#endif -#ifdef EEXIST -const error_catalog::value_type error_catalog::file_exists = EEXIST; -#else -#endif -#ifdef EFBIG -const error_catalog::value_type error_catalog::file_too_large = EFBIG; -#else -#endif -#ifdef ENAMETOOLONG -const error_catalog::value_type error_catalog::filename_too_long = ENAMETOOLONG; -#else -#endif -#ifdef ENOSYS -const error_catalog::value_type error_catalog::function_not_supported = ENOSYS; -#else -#endif -#ifdef EHOSTUNREACH -const error_catalog::value_type error_catalog::host_unreachable = EHOSTUNREACH; -#else -#endif -#ifdef EIDRM -const error_catalog::value_type error_catalog::identifier_removed = EIDRM; -#else -#endif -#ifdef EILSEQ -const error_catalog::value_type error_catalog::illegal_byte_sequence = EILSEQ; -#else -#endif -#ifdef ENOTTY -const error_catalog::value_type error_catalog::inappropriate_io_control_operation =ENOTTY; -#else -#endif -#ifdef EINTR -const error_catalog::value_type error_catalog::interrupted = EINTR; -#else -#endif -#ifdef EINVAL -const error_catalog::value_type error_catalog::invalid_argument = EINVAL; -#else -#endif -#ifdef ESPIPE -const error_catalog::value_type error_catalog::invalid_seek = ESPIPE; -#else -#endif -#ifdef EIO -const error_catalog::value_type error_catalog::io_error = EIO; -#else -#endif -#ifdef EISDIR -const error_catalog::value_type error_catalog::is_a_directory = EISDIR; -#else -#endif -#ifdef EMSGSIZE -const error_catalog::value_type error_catalog::message_too_long = EMSGSIZE; -#else -#endif -#ifdef ENETDOWN -const error_catalog::value_type error_catalog::network_down = ENETDOWN; -#else -#endif -#ifdef ENETRESET -const error_catalog::value_type error_catalog::network_reset = ENETRESET; -#else -#endif -#ifdef ENETUNREACH -const error_catalog::value_type error_catalog::network_unreachable = ENETUNREACH; -#else -#endif -#ifdef ENOBUFS -const error_catalog::value_type error_catalog::no_buffer_space = ENOBUFS; -#else -#endif -#ifdef ECHILD -const error_catalog::value_type error_catalog::no_child_process = ECHILD; -#else -#endif -#ifdef ENOLINK -const error_catalog::value_type error_catalog::no_link = ENOLINK; -#else -#endif -#ifdef ENOLCK -const error_catalog::value_type error_catalog::no_lock_available = ENOLCK; -#else -#endif -#ifdef ENODATA -const error_catalog::value_type error_catalog::no_message_available = ENODATA; -#else -#endif -#ifdef ENOMSG -const error_catalog::value_type error_catalog::no_message = ENOMSG; -#else -#endif -#ifdef ENOSPC -const error_catalog::value_type error_catalog::no_space_on_device = ENOSPC; -#else -#endif -#ifdef ENOSR -const error_catalog::value_type error_catalog::no_stream_resources = ENOSR; -#else -#endif -#ifdef ENXIO -const error_catalog::value_type error_catalog::no_such_device_or_address = ENXIO; -#else -#endif -#ifdef ENODEV -const error_catalog::value_type error_catalog::no_such_device = ENODEV; -#else -#endif -#ifdef ENOENT -const error_catalog::value_type error_catalog::no_such_file_or_directory = ENOENT; -#else -#endif -#ifdef ESRCH -const error_catalog::value_type error_catalog::no_such_process = ESRCH; -#else -#endif -#ifdef ENOTDIR -const error_catalog::value_type error_catalog::not_a_directory = ENOTDIR; -#else -#endif -#ifdef ENOTSOCK -const error_catalog::value_type error_catalog::not_a_socket = ENOTSOCK; -#else -#endif -#ifdef ENOSTR -const error_catalog::value_type error_catalog::not_a_stream = ENOSTR; -#else -#endif -#ifdef ENOTCONN -const error_catalog::value_type error_catalog::not_connected = ENOTCONN; -#else -#endif -#ifdef ENOMEM -const error_catalog::value_type error_catalog::not_enough_memory = ENOMEM; -#else -#endif -#ifdef ENOTSUP -const error_catalog::value_type error_catalog::not_supported = ENOTSUP; -#else -#endif -#ifdef EALREADY -const error_catalog::value_type error_catalog::operation_already_in_progress = EALREADY; -#else -#endif -#ifdef ECANCELED -const error_catalog::value_type error_catalog::operation_canceled = ECANCELED; -#else -#endif -#ifdef EINPROGRESS -const error_catalog::value_type error_catalog::operation_in_progress = EINPROGRESS; -#else -#endif -#ifdef EPERM -const error_catalog::value_type error_catalog::operation_not_permitted = EPERM; -#else -#endif -#ifdef EOPNOTSUPP -const error_catalog::value_type error_catalog::operation_not_supported = EOPNOTSUPP; -#else -#endif -#ifdef EOWNERDEAD -const error_catalog::value_type error_catalog::owner_dead = EOWNERDEAD; -#else -#endif -#ifdef EACCES -const error_catalog::value_type error_catalog::permission_denied = EACCES; -#else -#endif -#ifdef EPROTO -const error_catalog::value_type error_catalog::protocol_error = EPROTO; -#else -#endif -#ifdef ENOPROTOOPT -const error_catalog::value_type error_catalog::protocol_not_available = ENOPROTOOPT; -#else -#endif -#ifdef EPROTONOSUPPORT -const error_catalog::value_type error_catalog::protocol_not_supported = EPROTONOSUPPORT; -#else -#endif -#ifdef EROFS -const error_catalog::value_type error_catalog::read_only_file_system = EROFS; -#else -#endif -#ifdef EDEADLK -const error_catalog::value_type error_catalog::resource_deadlock_would_occur = EDEADLK; -#else -#endif -#ifdef ERANGE -const error_catalog::value_type error_catalog::result_out_of_range = ERANGE; -#else -#endif -#ifdef ENOTRECOVERABLE -const error_catalog::value_type error_catalog::state_not_recoverable = ENOTRECOVERABLE; -#else -#endif -#ifdef ETIME -const error_catalog::value_type error_catalog::stream_timeout = ETIME; -#else -#endif -#ifdef ETXTBSY -const error_catalog::value_type error_catalog::text_file_busy = ETXTBSY; -#else -#endif -#ifdef ETIMEDOUT -const error_catalog::value_type error_catalog::timed_out = ETIMEDOUT; -#else -#endif -#ifdef ENFILE -const error_catalog::value_type error_catalog::too_many_files_open_in_system = ENFILE; -#else -#endif -#ifdef EMFILE -const error_catalog::value_type error_catalog::too_many_files_open = EMFILE; -#else -#endif -#ifdef EMLINK -const error_catalog::value_type error_catalog::too_many_links = EMLINK; -#else -#endif -#ifdef ELOOP -const error_catalog::value_type error_catalog::too_many_synbolic_link_levels = ELOOP; -#else -#endif -#ifdef EAGAIN -const error_catalog::value_type error_catalog::try_again = EAGAIN; -#else -#endif -#ifdef EOVERFLOW -const error_catalog::value_type error_catalog::value_too_large = EOVERFLOW; -#else -#endif -#ifdef EPROTOTYPE -const error_catalog::value_type error_catalog::wrong_protocol_type = EPROTOTYPE; -#else -#endif - -const error_catalog::value_type error_catalog::last_value() const throw() +error_condition error_category::default_error_condition( int err ) const { - return _syserr._last_value; + return error_condition( err, *this ); } -bool error_catalog::is_valid_value( error_catalog::value_type v ) const throw() +bool error_category::equivalent( int code, const error_condition& cnd ) const { - return (v >= 0) && (v <= _syserr._last_value) && (_syserr._sys_err[v] != 0); + return default_error_condition( code ) == cnd; } -const char* error_catalog::str( error_catalog::value_type v ) const throw() +bool error_category::equivalent( const error_code& code, int cnd ) const { - if ( (v < 0) || (v > _syserr._last_value) ) { - return 0; - } + return (*this == code.category()) && (code.value() == cnd); +} - return _syserr._sys_err[v]; +bool error_category::operator ==( const error_category& cat ) const +{ + return this == &cat; } -bool error_catalog::operator ==(const error_catalog& __other) const throw() +bool error_category::operator !=( const error_category& cat ) const { - return (_M_loc == __other.getloc()) && (typeid(*this) == typeid(__other)); + return this != &cat; } -bool error_catalog::operator !=(const error_catalog& __other) const throw() +bool error_category::operator <( const error_category& cat ) const { - return (_M_loc != __other.getloc()) || (typeid(*this) != typeid(__other)); + return this < &cat; } -system_error::system_error( const std::string& s ) : - std::runtime_error( s ) +const error_category& get_posix_category() { + return detail::_posix_error_category; } -system_error::system_error( error_catalog::value_type _v, const error_catalog& _c ) : - std::runtime_error( _c.str( _v ) ) +const error_category& get_system_category() { + return detail::_system_error_category; } } // namespace std This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-25 06:34:08
|
Revision: 1949 http://complement.svn.sourceforge.net/complement/?rev=1949&view=rev Author: complement Date: 2008-07-25 06:34:06 +0000 (Fri, 25 Jul 2008) Log Message: ----------- fix STLport version; use type_traits from STLport type_traits in STLport was derived from this type_traits.h and has fresh modifications Modified Paths: -------------- trunk/complement/explore/include/misc/type_traits.h trunk/complement/explore/lib/misc/ChangeLog Modified: trunk/complement/explore/include/misc/type_traits.h =================================================================== --- trunk/complement/explore/include/misc/type_traits.h 2008-07-09 09:18:44 UTC (rev 1948) +++ trunk/complement/explore/include/misc/type_traits.h 2008-07-25 06:34:06 UTC (rev 1949) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/12/02 19:55:42 ptr> +// -*- C++ -*- Time-stamp: <08/07/20 18:17:36 ptr> /* - * Copyright (c) 2007 + * Copyright (c) 2007, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -15,7 +15,7 @@ #include <config/feature.h> #endif -#if 1 /* !defined(STLPORT) */ /* || (_STLPORT_VERSION < 50200) */ +#if !defined(STLPORT) || (_STLPORT_VERSION < 0x520) // libstdc++ v3, timestamp 20050519 (3.4.4) has __type_traits, // libstdc++ v3, timestamp 20060306 (3.4.6) has __type_traits, Modified: trunk/complement/explore/lib/misc/ChangeLog =================================================================== --- trunk/complement/explore/lib/misc/ChangeLog 2008-07-09 09:18:44 UTC (rev 1948) +++ trunk/complement/explore/lib/misc/ChangeLog 2008-07-25 06:34:06 UTC (rev 1949) @@ -1,3 +1,9 @@ +2008-07-21 Petr Ovtchenkov <pt...@is...> + + * type_traits.h: fix STLport version; use type_traits + from STLport (it was derived from this type_traits.h and has + fresh modifications). + 2008-06-30 Petr Ovtchenkov <pt...@is...> * opts.h: free allocated objects; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-09 09:18:46
|
Revision: 1948 http://complement.svn.sourceforge.net/complement/?rev=1948&view=rev Author: complement Date: 2008-07-09 02:18:44 -0700 (Wed, 09 Jul 2008) Log Message: ----------- Merge branch 'master' of /export/hostel/pub/scm/complement into HEAD Conflicts: complement/explore/lib/stem/ChangeLog complement/explore/lib/stem/Makefile.inc Modified Paths: -------------- trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/Makefile.inc trunk/complement/explore/lib/stem/_EventHandler.cc Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2008-07-09 07:11:29 UTC (rev 1947) +++ trunk/complement/explore/lib/stem/ChangeLog 2008-07-09 09:18:44 UTC (rev 1948) @@ -1,3 +1,9 @@ +2008-07-08 Petr Ovtchenkov <ye...@ya...> + + * _EventHandler.cc: return state via local variable; + + * libstem: library version 4.8.2. + 2008-07-07 Petr Ovtchenkov <ye...@ya...> * EvManager.h, EvManager.cc: fix dispatch loop finish Modified: trunk/complement/explore/lib/stem/Makefile.inc =================================================================== --- trunk/complement/explore/lib/stem/Makefile.inc 2008-07-09 07:11:29 UTC (rev 1947) +++ trunk/complement/explore/lib/stem/Makefile.inc 2008-07-09 09:18:44 UTC (rev 1948) @@ -1,8 +1,8 @@ -# -*- Makefile -*- Time-stamp: <08/07/07 21:07:49 yeti> +# -*- Makefile -*- Time-stamp: <08/07/08 13:13:44 yeti> LIBNAME = stem MAJOR = 4 MINOR = 8 -PATCH = 1 +PATCH = 2 SRC_CC = _EventHandler.cc NetTransport.cc EvManager.cc EvPack.cc crc.cc \ Names.cc Cron.cc Modified: trunk/complement/explore/lib/stem/_EventHandler.cc =================================================================== --- trunk/complement/explore/lib/stem/_EventHandler.cc 2008-07-09 07:11:29 UTC (rev 1947) +++ trunk/complement/explore/lib/stem/_EventHandler.cc 2008-07-09 09:18:44 UTC (rev 1948) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/30 18:16:58 yeti> +// -*- C++ -*- Time-stamp: <08/07/08 13:04:19 yeti> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006, 2008 @@ -136,7 +136,8 @@ state_type EventHandler::State() const { lock_guard<recursive_mutex> lk( _theHistory_lock ); - return theHistory.front(); + state_type top = theHistory.front(); + return top; } __FIT_DECLSPEC This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-09 07:11:30
|
Revision: 1947 http://complement.svn.sourceforge.net/complement/?rev=1947&view=rev Author: complement Date: 2008-07-09 00:11:29 -0700 (Wed, 09 Jul 2008) Log Message: ----------- rdbuf()->in_avail() should check positive number rdbuf()->in_avail() should check positive number, not non-null, because showmanyc may return -1 to indicate marginal cases. Modified Paths: -------------- trunk/complement/explore/include/sockios/socksrv.cc Modified: trunk/complement/explore/include/sockios/socksrv.cc =================================================================== --- trunk/complement/explore/include/sockios/socksrv.cc 2008-07-09 07:07:02 UTC (rev 1946) +++ trunk/complement/explore/include/sockios/socksrv.cc 2008-07-09 07:11:29 UTC (rev 1947) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/09 10:41:48 ptr> +// -*- C++ -*- Time-stamp: <08/07/09 11:09:53 ptr> /* * Copyright (c) 2008 @@ -197,7 +197,7 @@ Connect* c = new Connect( *s ); // bad point! I can't read from s in ctor indeed! - if ( s->rdbuf()->in_avail() ) { + if ( s->rdbuf()->in_avail() > 0 ) { std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); ready_pool.push_back( processor( c, s ) ); std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-09 07:07:06
|
Revision: 1946 http://complement.svn.sourceforge.net/complement/?rev=1946&view=rev Author: complement Date: 2008-07-09 00:07:02 -0700 (Wed, 09 Jul 2008) Log Message: ----------- simplify worker's loop and finish notification not_empty predicate check as not empty ready_pool as _in_work; after this, pop_ready check ready_pool (i.e. if nothing to extract, then _in_work false) and throw exception if finish detected; att: it throw exception only if ready_pool empty! rdbuf()->in_avail() should check positive number, not non-null, because showmanyc may return -1 to indicate marginal cases. Modified Paths: -------------- trunk/complement/explore/include/sockios/socksrv.cc trunk/complement/explore/include/sockios/socksrv.h Modified: trunk/complement/explore/include/sockios/socksrv.cc =================================================================== --- trunk/complement/explore/include/sockios/socksrv.cc 2008-07-07 17:26:37 UTC (rev 1945) +++ trunk/complement/explore/include/sockios/socksrv.cc 2008-07-09 07:07:02 UTC (rev 1946) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/26 09:00:54 ptr> +// -*- C++ -*- Time-stamp: <08/07/09 10:41:48 ptr> /* * Copyright (c) 2008 @@ -200,7 +200,7 @@ if ( s->rdbuf()->in_avail() ) { std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); ready_pool.push_back( processor( c, s ) ); - // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; cnd.notify_one(); } else { std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); @@ -265,30 +265,20 @@ std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); ready_pool.push_back( p ); cnd.notify_one(); - // std::cerr << "notify data " << (void *)c << " " << ready_pool.size() << std::endl; } template <class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream<charT,traits,_Alloc>& )> -bool connect_processor<Connect, charT, traits, _Alloc, C>::pop_ready( processor& p ) +void connect_processor<Connect, charT, traits, _Alloc, C>::pop_ready( processor& p ) { std::tr2::unique_lock<std::tr2::mutex> lk( rdlock ); - if ( !_in_work && ready_pool.empty() ) { - // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - return false; - } - // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; cnd.wait( lk, not_empty ); - // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - p = ready_pool.front(); // it may contain p.c == 0, p.s == 0, if !in_work() - ready_pool.pop_front(); - - if ( _in_work ) { - return true; + if ( ready_pool.empty() ) { + throw finish(); } - - return !ready_pool.empty(); // if !_in_work && ready_pool.empty() return false + p = ready_pool.front(); + ready_pool.pop_front(); } template <class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream<charT,traits,_Alloc>& )> @@ -296,26 +286,34 @@ { processor p; - while ( pop_ready( p ) ) { - if ( p.c != 0 ) { + try { + for ( ; ; ) { + pop_ready( p ); + // if ( p.c != 0 ) { // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; (p.c->*C)( *p.s ); - if ( p.s->rdbuf()->in_avail() ) { + if ( p.s->rdbuf()->in_avail() > 0 ) { std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); ready_pool.push_back( p ); } else { std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); worker_pool[p.s->rdbuf()->fd()] = p; } - } // else { - // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - // } + // } // else { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // } + } } + catch ( const finish& ) { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + } -// { -// std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); -// std::cerr << __FILE__ << ":" << __LINE__ << " " << worker_pool.size() << std::endl; -// } + { + std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); + if ( !worker_pool.empty() ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << worker_pool.size() << std::endl; + } + } // { // std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); @@ -328,14 +326,8 @@ { std::tr2::lock_guard<std::tr2::mutex> lk2( rdlock ); - _in_work = false; // <--- set before cnd.notify_one(); (below in this func) - if ( ready_pool.empty() ) { - ready_pool.push_back( processor() ); // make ready_pool not empty - // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - cnd.notify_one(); - } // else { - // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - // } + _in_work = false; + cnd.notify_one(); } } // namespace std Modified: trunk/complement/explore/include/sockios/socksrv.h =================================================================== --- trunk/complement/explore/include/sockios/socksrv.h 2008-07-07 17:26:37 UTC (rev 1945) +++ trunk/complement/explore/include/sockios/socksrv.h 2008-07-09 07:07:02 UTC (rev 1946) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/26 08:59:54 ptr> +// -*- C++ -*- Time-stamp: <08/07/09 01:02:12 ptr> /* * Copyright (c) 2008 @@ -35,6 +35,7 @@ #include <sockios/sockstream> #include <deque> #include <functional> +#include <exception> namespace std { @@ -223,6 +224,11 @@ void worker(); + class finish : + public std::exception + { + }; + private: connect_processor( const connect_processor& ) { } @@ -269,7 +275,7 @@ */ }; - bool pop_ready( processor& ); + void pop_ready( processor& ); void _close() { base_t::_close(); } void _stop(); @@ -292,7 +298,7 @@ { } bool operator()() const - { return !me.ready_pool.empty(); } + { return !me.ready_pool.empty() || !me._in_work; } connect_processor& me; } not_empty; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-07 17:27:26
|
Revision: 1945 http://complement.svn.sourceforge.net/complement/?rev=1945&view=rev Author: complement Date: 2008-07-07 10:26:37 -0700 (Mon, 07 Jul 2008) Log Message: ----------- fix dispatch loop finish condition; libstem 4.8.1 (for git-svn) pass predicate to wait condition in dispatch loop; predicate check as non-empty income events queue, as flag for _dispatch_stop flag; spinlock, that cover only _dispatch_stop removed. Modified Paths: -------------- trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Makefile.inc Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2008-07-07 10:30:59 UTC (rev 1944) +++ trunk/complement/explore/include/stem/EvManager.h 2008-07-07 17:26:37 UTC (rev 1945) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 12:35:36 ptr> +// -*- C++ -*- Time-stamp: <08/07/07 21:03:34 yeti> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -266,6 +266,19 @@ } private: + struct _not_empty + { + _not_empty( EvManager& m ) : + me( m ) + { } + + bool operator()() const + { return !me.in_ev_queue.empty() || me._dispatch_stop; } + + EvManager& me; + } not_empty; + + void Send( const Event& e ); __FIT_DECLSPEC void unsafe_Remove( void * ); @@ -308,7 +321,6 @@ unsigned _trflags; std::ostream *_trs; - std::tr2::spinlock _ev_queue_dispatch_guard; std::tr2::thread _ev_queue_thr; friend class Names; Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2008-07-07 10:30:59 UTC (rev 1944) +++ trunk/complement/explore/lib/stem/ChangeLog 2008-07-07 17:26:37 UTC (rev 1945) @@ -1,3 +1,10 @@ +2008-07-07 Petr Ovtchenkov <ye...@ya...> + + * EvManager.h, EvManager.cc: fix dispatch loop finish + condition; + + * libstem: library version 4.8.1. + 2008-06-27 Petr Ovtchenkov <pt...@is...> * Cron.h, EvManager.h, EventHandler.h, NetTransport.h: Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2008-07-07 10:30:59 UTC (rev 1944) +++ trunk/complement/explore/lib/stem/EvManager.cc 2008-07-07 17:26:37 UTC (rev 1945) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/30 18:18:21 yeti> +// -*- C++ -*- Time-stamp: <08/07/07 21:01:28 yeti> /* * @@ -44,6 +44,7 @@ std::string EvManager::inv_key_str( "invalid key" ); __FIT_DECLSPEC EvManager::EvManager() : + not_empty( *this ), _low( beglocaddr ), _high( endlocaddr ), _id( _low ), @@ -62,7 +63,7 @@ __FIT_DECLSPEC EvManager::~EvManager() { { - lock_guard<spinlock> lk( _ev_queue_dispatch_guard ); + lock_guard<mutex> lk( _lock_queue ); _dispatch_stop = true; _cnd_queue.notify_one(); } @@ -72,7 +73,7 @@ bool EvManager::not_finished() { - lock_guard<spinlock> lk( _ev_queue_dispatch_guard ); + lock_guard<mutex> lk( _lock_queue ); return !_dispatch_stop; } @@ -94,9 +95,7 @@ } { unique_lock<mutex> lk( lq ); - if ( in_ev_queue.empty() && me.not_finished() ) { - me._cnd_queue.wait( lk ); - } + me._cnd_queue.wait( lk, me.not_empty ); } } } Modified: trunk/complement/explore/lib/stem/Makefile.inc =================================================================== --- trunk/complement/explore/lib/stem/Makefile.inc 2008-07-07 10:30:59 UTC (rev 1944) +++ trunk/complement/explore/lib/stem/Makefile.inc 2008-07-07 17:26:37 UTC (rev 1945) @@ -1,8 +1,8 @@ -# -*- Makefile -*- Time-stamp: <08/06/27 13:16:59 ptr> +# -*- Makefile -*- Time-stamp: <08/07/07 21:07:49 yeti> LIBNAME = stem MAJOR = 4 MINOR = 8 -PATCH = 0 +PATCH = 1 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...> - 2008-07-07 10:31:05
|
Revision: 1944 http://complement.svn.sourceforge.net/complement/?rev=1944&view=rev Author: complement Date: 2008-07-07 03:30:59 -0700 (Mon, 07 Jul 2008) Log Message: ----------- fixed bad conversion from string to binary for all uids; libxmt 2.0.7 Modified Paths: -------------- trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/uid.cc trunk/complement/explore/lib/mt/ut/mt_test_suite.cc trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc trunk/complement/explore/lib/mt/ut/mt_test_wg21.h Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-07-07 06:39:32 UTC (rev 1943) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-07-07 10:30:59 UTC (rev 1944) @@ -3,8 +3,13 @@ * uid.cc, uid.h: convert uid to string; output uid to ostream; - * libxmt: bump revision to 2.0.6. + * libxmt: bump revision to 2.0.6; + * uid.cc: fixed bad conversion from string form to binary + for all uids; + + * libxmt: bump revision to 2.0.7. + 2008-07-02 Petr Ovtchenkov <pt...@is...> * uid.cc: fix wrong type cast; Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2008-07-07 06:39:32 UTC (rev 1943) +++ trunk/complement/explore/lib/mt/Makefile.inc 2008-07-07 10:30:59 UTC (rev 1944) @@ -3,7 +3,7 @@ LIBNAME = xmt MAJOR = 2 MINOR = 0 -PATCH = 6 +PATCH = 7 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc callstack.cc system_error.cc thread.cc \ date_time.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2008-07-07 06:39:32 UTC (rev 1943) +++ trunk/complement/explore/lib/mt/uid.cc 2008-07-07 10:30:59 UTC (rev 1944) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/07 04:14:12 ptr> +// -*- C++ -*- Time-stamp: <08/07/07 14:19:23 yeti> /* * Copyright (c) 2006, 2008 @@ -25,13 +25,22 @@ { std::ios_base::fmtflags f = s.flags( 0 ); s << hex << setfill('0') - << setw(2) << uid.u.b[0] << setw(2) << uid.u.b[1] << setw(2) << uid.u.b[2] << setw(2) << uid.u.b[3] << '-' - << setw(2) << uid.u.b[4] << setw(2) << uid.u.b[5] << '-' - << setw(2) << uid.u.b[6] << setw(2) << uid.u.b[7] << '-' - << setw(2) << uid.u.b[8] << setw(2) << uid.u.b[9] << '-' - << setw(2) << uid.u.b[10] << setw(2) << uid.u.b[11] - << setw(2) << uid.u.b[12] << setw(2) << uid.u.b[13] - << setw(2) << uid.u.b[14] << setw(2) << uid.u.b[15]; + << setw(2) << static_cast<unsigned>(uid.u.b[0]) + << setw(2) << static_cast<unsigned>(uid.u.b[1]) + << setw(2) << static_cast<unsigned>(uid.u.b[2]) + << setw(2) << static_cast<unsigned>(uid.u.b[3]) << '-' + << setw(2) << static_cast<unsigned>(uid.u.b[4]) + << setw(2) << static_cast<unsigned>(uid.u.b[5]) << '-' + << setw(2) << static_cast<unsigned>(uid.u.b[6]) + << setw(2) << static_cast<unsigned>(uid.u.b[7]) << '-' + << setw(2) << static_cast<unsigned>(uid.u.b[8]) + << setw(2) << static_cast<unsigned>(uid.u.b[9]) << '-' + << setw(2) << static_cast<unsigned>(uid.u.b[10]) + << setw(2) << static_cast<unsigned>(uid.u.b[11]) + << setw(2) << static_cast<unsigned>(uid.u.b[12]) + << setw(2) << static_cast<unsigned>(uid.u.b[13]) + << setw(2) << static_cast<unsigned>(uid.u.b[14]) + << setw(2) << static_cast<unsigned>(uid.u.b[15]); s.flags( f ); return s; @@ -89,12 +98,30 @@ << _host_id_str[30] << _host_id_str[31] << ' ' << _host_id_str[32] << _host_id_str[33] << ' ' << _host_id_str[34] << _host_id_str[35]; - - s >> hex - >> _host_id.u.b[0] >> _host_id.u.b[1] >> _host_id.u.b[2] >> _host_id.u.b[3] - >> _host_id.u.b[4] >> _host_id.u.b[5] >> _host_id.u.b[6] >> _host_id.u.b[7] - >> _host_id.u.b[8] >> _host_id.u.b[9] >> _host_id.u.b[10] >> _host_id.u.b[11] - >> _host_id.u.b[12] >> _host_id.u.b[13] >> _host_id.u.b[14] >> _host_id.u.b[15]; + + s >> hex; + + unsigned v[16]; + + s >> v[0] >> v[1] >> v[2] >> v[3] >> v[4] >> v[5] >> v[6] >> v[7] + >> v[8] >> v[9] >> v[10] >> v[11] >> v[12] >> v[13] >> v[14] >> v[15]; + + _host_id.u.b[0] = v[0]; + _host_id.u.b[1] = v[1]; + _host_id.u.b[2] = v[2]; + _host_id.u.b[3] = v[3]; + _host_id.u.b[4] = v[4]; + _host_id.u.b[5] = v[5]; + _host_id.u.b[6] = v[6]; + _host_id.u.b[7] = v[7]; + _host_id.u.b[8] = v[8]; + _host_id.u.b[9] = v[9]; + _host_id.u.b[10] = v[10]; + _host_id.u.b[11] = v[11]; + _host_id.u.b[12] = v[12]; + _host_id.u.b[13] = v[13]; + _host_id.u.b[14] = v[14]; + _host_id.u.b[15] = v[15]; } } @@ -167,12 +194,30 @@ << tmp[32] << tmp[33] << ' ' << tmp[34] << tmp[35]; - s >> hex - >> id.u.b[0] >> id.u.b[1] >> id.u.b[2] >> id.u.b[3] - >> id.u.b[4] >> id.u.b[5] >> id.u.b[6] >> id.u.b[7] - >> id.u.b[8] >> id.u.b[9] >> id.u.b[10] >> id.u.b[11] - >> id.u.b[12] >> id.u.b[13] >> id.u.b[14] >> id.u.b[15]; + s >> hex; + unsigned v[16]; + + s >> v[0] >> v[1] >> v[2] >> v[3] >> v[4] >> v[5] >> v[6] >> v[7] + >> v[8] >> v[9] >> v[10] >> v[11] >> v[12] >> v[13] >> v[14] >> v[15]; + + id.u.b[0] = v[0]; + id.u.b[1] = v[1]; + id.u.b[2] = v[2]; + id.u.b[3] = v[3]; + id.u.b[4] = v[4]; + id.u.b[5] = v[5]; + id.u.b[6] = v[6]; + id.u.b[7] = v[7]; + id.u.b[8] = v[8]; + id.u.b[9] = v[9]; + id.u.b[10] = v[10]; + id.u.b[11] = v[11]; + id.u.b[12] = v[12]; + id.u.b[13] = v[13]; + id.u.b[14] = v[14]; + id.u.b[15] = v[15]; + return id; } Modified: trunk/complement/explore/lib/mt/ut/mt_test_suite.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2008-07-07 06:39:32 UTC (rev 1943) +++ trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2008-07-07 10:30:59 UTC (rev 1944) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/02 13:01:53 yeti> +// -*- C++ -*- Time-stamp: <08/07/07 13:15:01 yeti> /* * Copyright (c) 2006-2008 @@ -83,8 +83,9 @@ t.add( &uid_test_wg21::uid, test_wg21_uid, "uid_test_wg21::uid", t.add( &uid_test_wg21::uidstr, test_wg21_uid, "uid_test_wg21::uidstr" ) ); - t.add( &uid_test_wg21::hostid, test_wg21_uid, "uid_test_wg21::hostid", - t.add( &uid_test_wg21::hostidstr, test_wg21_uid, "uid_test_wg21::hostidstr" ) ); + t.add( &uid_test_wg21::uidconv, test_wg21_uid, "uid_test_wg21::uidconv", + t.add( &uid_test_wg21::hostid, test_wg21_uid, "uid_test_wg21::hostid", + t.add( &uid_test_wg21::hostidstr, test_wg21_uid, "uid_test_wg21::hostidstr" ) ) ); Opts opts; Modified: trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-07 06:39:32 UTC (rev 1943) +++ trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-07 10:30:59 UTC (rev 1944) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/02 13:00:38 yeti> +// -*- C++ -*- Time-stamp: <08/07/07 14:23:07 yeti> /* * Copyright (c) 2006-2008 @@ -18,6 +18,7 @@ #include <typeinfo> #include <iostream> +#include <sstream> #include <sys/wait.h> #include <sys/ipc.h> @@ -385,3 +386,19 @@ return EXAM_RESULT; } + +int EXAM_IMPL(uid_test_wg21::uidconv) +{ + xmt::uuid_type u1 = xmt::hostid(); + std::string u2 = xmt::hostid_str(); + + EXAM_CHECK( static_cast<std::string>(u1) == u2 ); // <-- conversion to string + + std::stringstream s; + + s << u1; + + EXAM_CHECK( s.str() == u2 ); + + return EXAM_RESULT; +} Modified: trunk/complement/explore/lib/mt/ut/mt_test_wg21.h =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_wg21.h 2008-07-07 06:39:32 UTC (rev 1943) +++ trunk/complement/explore/lib/mt/ut/mt_test_wg21.h 2008-07-07 10:30:59 UTC (rev 1944) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/02 12:59:27 yeti> +// -*- C++ -*- Time-stamp: <08/07/07 13:10:54 yeti> /* * Copyright (c) 2006-2008 @@ -37,6 +37,7 @@ int EXAM_DECL(uid); int EXAM_DECL(hostidstr); int EXAM_DECL(hostid); + int EXAM_DECL(uidconv); }; #endif // __MT_TEST_WG21_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-07 06:39:36
|
Revision: 1943 http://complement.svn.sourceforge.net/complement/?rev=1943&view=rev Author: complement Date: 2008-07-06 23:39:32 -0700 (Sun, 06 Jul 2008) Log Message: ----------- convert uid to string; output uid to ostream; libxmt 2.0.6 Modified Paths: -------------- trunk/complement/explore/include/mt/uid.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/uid.cc Modified: trunk/complement/explore/include/mt/uid.h =================================================================== --- trunk/complement/explore/include/mt/uid.h 2008-07-02 11:01:18 UTC (rev 1942) +++ trunk/complement/explore/include/mt/uid.h 2008-07-07 06:39:32 UTC (rev 1943) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/06 21:21:30 yeti> +// -*- C++ -*- Time-stamp: <08/07/07 01:13:55 ptr> /* * Copyright (c) 2006, 2008 @@ -19,6 +19,7 @@ // #include <algorithm> #include <stdint.h> #include <stdexcept> +#include <ostream> namespace xmt { @@ -61,6 +62,8 @@ // return std::lexicographical_compare( u.i, u.i + 4, uid.u.i, uid.u.i + 4 ); return u.l[0] < uid.u.l[0] ? true : u.l[0] > uid.u.l[0] ? false : (u.l[1] < uid.u.l[1]); } + + operator std::string() const; }; const char *hostid_str() throw (std::runtime_error); @@ -71,4 +74,10 @@ } // namespace xmt +namespace std { + +std::ostream& operator <<( std::ostream&, const xmt::uuid_type& ); + +} // namespace std + #endif // __mt_uid_h Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-07-02 11:01:18 UTC (rev 1942) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-07-07 06:39:32 UTC (rev 1943) @@ -1,3 +1,10 @@ +2008-07-07 Petr Ovtchenkov <pt...@is...> + + * uid.cc, uid.h: convert uid to string; output uid + to ostream; + + * libxmt: bump revision to 2.0.6. + 2008-07-02 Petr Ovtchenkov <pt...@is...> * uid.cc: fix wrong type cast; Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2008-07-02 11:01:18 UTC (rev 1942) +++ trunk/complement/explore/lib/mt/Makefile.inc 2008-07-07 06:39:32 UTC (rev 1943) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <08/07/02 09:28:02 ptr> +# -*- Makefile -*- Time-stamp: <08/07/07 10:35:20 ptr> LIBNAME = xmt MAJOR = 2 MINOR = 0 -PATCH = 5 +PATCH = 6 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc callstack.cc system_error.cc thread.cc \ date_time.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2008-07-02 11:01:18 UTC (rev 1942) +++ trunk/complement/explore/lib/mt/uid.cc 2008-07-07 06:39:32 UTC (rev 1943) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/02 13:15:01 yeti> +// -*- C++ -*- Time-stamp: <08/07/07 04:14:12 ptr> /* * Copyright (c) 2006, 2008 @@ -19,6 +19,26 @@ #include <iostream> +namespace std { + +std::ostream& operator <<( std::ostream& s, const xmt::uuid_type& uid ) +{ + std::ios_base::fmtflags f = s.flags( 0 ); + s << hex << setfill('0') + << setw(2) << uid.u.b[0] << setw(2) << uid.u.b[1] << setw(2) << uid.u.b[2] << setw(2) << uid.u.b[3] << '-' + << setw(2) << uid.u.b[4] << setw(2) << uid.u.b[5] << '-' + << setw(2) << uid.u.b[6] << setw(2) << uid.u.b[7] << '-' + << setw(2) << uid.u.b[8] << setw(2) << uid.u.b[9] << '-' + << setw(2) << uid.u.b[10] << setw(2) << uid.u.b[11] + << setw(2) << uid.u.b[12] << setw(2) << uid.u.b[13] + << setw(2) << uid.u.b[14] << setw(2) << uid.u.b[15]; + s.flags( f ); + + return s; +} + +} // namespace std + namespace xmt { namespace detail { @@ -83,6 +103,15 @@ using namespace std; using namespace std::tr2; +uuid_type::operator string() const +{ + ostringstream s; + + s << *this; + + return s.str(); +} + const char *hostid_str() throw (runtime_error) { static detail::__uid_init _uid; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-02 11:01:21
|
Revision: 1942 http://complement.svn.sourceforge.net/complement/?rev=1942&view=rev Author: complement Date: 2008-07-02 04:01:18 -0700 (Wed, 02 Jul 2008) Log Message: ----------- fix uuid generation /proc/sys/kernel/random/uuid should be reopen for next read; if not, next read will return 0 (not eveident!). All uid-generated functions throw runtime_exception if detect problem. Modified Paths: -------------- trunk/complement/explore/include/mt/uid.h trunk/complement/explore/lib/mt/uid.cc trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc Modified: trunk/complement/explore/include/mt/uid.h =================================================================== --- trunk/complement/explore/include/mt/uid.h 2008-07-02 09:39:31 UTC (rev 1941) +++ trunk/complement/explore/include/mt/uid.h 2008-07-02 11:01:18 UTC (rev 1942) @@ -1,7 +1,7 @@ // -*- C++ -*- Time-stamp: <08/06/06 21:21:30 yeti> /* - * Copyright (c) 2006 + * Copyright (c) 2006, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -18,6 +18,7 @@ #include <string> // #include <algorithm> #include <stdint.h> +#include <stdexcept> namespace xmt { @@ -62,11 +63,11 @@ } }; -const char *hostid_str(); -const xmt::uuid_type& hostid(); +const char *hostid_str() throw (std::runtime_error); +const xmt::uuid_type& hostid() throw (std::runtime_error); -std::string uid_str(); -xmt::uuid_type uid(); +std::string uid_str() throw (std::runtime_error); +xmt::uuid_type uid() throw (std::runtime_error); } // namespace xmt Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2008-07-02 09:39:31 UTC (rev 1941) +++ trunk/complement/explore/lib/mt/uid.cc 2008-07-02 11:01:18 UTC (rev 1942) @@ -15,7 +15,10 @@ #include <cstring> #include <unistd.h> #include <fcntl.h> +#include <stdexcept> +#include <iostream> + namespace xmt { namespace detail { @@ -24,98 +27,95 @@ using namespace xmt; using namespace std::tr2; -class __uid_init +struct __uid_init { - public: __uid_init(); static uuid_type _host_id; char _host_id_str[48]; // 37 really + bool fail; }; uuid_type __uid_init::_host_id; -struct __uuid_init +__uid_init::__uid_init() : + fail( false ) { - public: - __uuid_init(); - ~__uuid_init(); - - int fd; -}; - -__uid_init::__uid_init() -{ int fd = ::open( "/proc/sys/kernel/random/boot_id", O_RDONLY ); - ::read( fd, _host_id_str, 36 ); - _host_id_str[36] = '\0'; - ::close( fd ); + if ( (fd < 0) || (::read( fd, _host_id_str, 36 ) != 36 )) { + if ( fd >= 0 ) { + ::close( fd ); + } + fail = true; + } else { + _host_id_str[36] = '\0'; + ::close( fd ); - stringstream s; - s << _host_id_str[0] << _host_id_str[1] << ' ' - << _host_id_str[2] << _host_id_str[3] << ' ' - << _host_id_str[4] << _host_id_str[5] << ' ' - << _host_id_str[6] << _host_id_str[7] << ' ' // - - << _host_id_str[9] << _host_id_str[10] << ' ' - << _host_id_str[11] << _host_id_str[12] << ' ' // - - << _host_id_str[14] << _host_id_str[15] << ' ' - << _host_id_str[16] << _host_id_str[17] << ' ' // - - << _host_id_str[19] << _host_id_str[20] << ' ' - << _host_id_str[21] << _host_id_str[22] << ' ' // - - << _host_id_str[24] << _host_id_str[25] << ' ' - << _host_id_str[26] << _host_id_str[27] << ' ' - << _host_id_str[28] << _host_id_str[29] << ' ' - << _host_id_str[30] << _host_id_str[31] << ' ' - << _host_id_str[32] << _host_id_str[33] << ' ' - << _host_id_str[34] << _host_id_str[35]; + stringstream s; + s << _host_id_str[0] << _host_id_str[1] << ' ' + << _host_id_str[2] << _host_id_str[3] << ' ' + << _host_id_str[4] << _host_id_str[5] << ' ' + << _host_id_str[6] << _host_id_str[7] << ' ' // - + << _host_id_str[9] << _host_id_str[10] << ' ' + << _host_id_str[11] << _host_id_str[12] << ' ' // - + << _host_id_str[14] << _host_id_str[15] << ' ' + << _host_id_str[16] << _host_id_str[17] << ' ' // - + << _host_id_str[19] << _host_id_str[20] << ' ' + << _host_id_str[21] << _host_id_str[22] << ' ' // - + << _host_id_str[24] << _host_id_str[25] << ' ' + << _host_id_str[26] << _host_id_str[27] << ' ' + << _host_id_str[28] << _host_id_str[29] << ' ' + << _host_id_str[30] << _host_id_str[31] << ' ' + << _host_id_str[32] << _host_id_str[33] << ' ' + << _host_id_str[34] << _host_id_str[35]; - s >> hex - >> _host_id.u.b[0] >> _host_id.u.b[1] >> _host_id.u.b[2] >> _host_id.u.b[3] - >> _host_id.u.b[4] >> _host_id.u.b[5] >> _host_id.u.b[6] >> _host_id.u.b[7] - >> _host_id.u.b[8] >> _host_id.u.b[9] >> _host_id.u.b[10] >> _host_id.u.b[11] - >> _host_id.u.b[12] >> _host_id.u.b[13] >> _host_id.u.b[14] >> _host_id.u.b[15]; + s >> hex + >> _host_id.u.b[0] >> _host_id.u.b[1] >> _host_id.u.b[2] >> _host_id.u.b[3] + >> _host_id.u.b[4] >> _host_id.u.b[5] >> _host_id.u.b[6] >> _host_id.u.b[7] + >> _host_id.u.b[8] >> _host_id.u.b[9] >> _host_id.u.b[10] >> _host_id.u.b[11] + >> _host_id.u.b[12] >> _host_id.u.b[13] >> _host_id.u.b[14] >> _host_id.u.b[15]; + } } -__uuid_init::__uuid_init() -{ - fd = ::open( "/proc/sys/kernel/random/uuid", O_RDONLY ); -} - -__uuid_init::~__uuid_init() -{ - ::close( fd ); -} - } // namespace detail using namespace std; using namespace std::tr2; -const char *hostid_str() +const char *hostid_str() throw (runtime_error) { static detail::__uid_init _uid; + if ( _uid.fail ) { + throw runtime_error( "can't read hostid" ); + } return _uid._host_id_str; } -const xmt::uuid_type& hostid() +const xmt::uuid_type& hostid() throw (runtime_error) { hostid_str(); return detail::__uid_init::_host_id; } -std::string uid_str() +std::string uid_str() throw (runtime_error) { - static detail::__uuid_init __uuid; + char buf[37]; - char buf[36]; + int fd = ::open( "/proc/sys/kernel/random/uuid", O_RDONLY ); + if ( (fd < 0) || (::read( fd, buf, 37 ) != 37) ) { + if ( fd >= 0 ) { + ::close( fd ); + } + throw runtime_error( "Can't generate UID" ); + // return std::string(); + } + ::close( fd ); - ::read( __uuid.fd, buf, 36 ); - return std::string( buf, 36 ); } -xmt::uuid_type uid() +xmt::uuid_type uid() throw (runtime_error) { string tmp = uid_str(); uuid_type id; Modified: trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-02 09:39:31 UTC (rev 1941) +++ trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-02 11:01:18 UTC (rev 1942) @@ -334,6 +334,18 @@ EXAM_CHECK( u1 != u2 ); + for ( int i = 0; i < 100; ++i ) { + std::string s = xmt::uid_str(); + + EXAM_REQUIRE( s.length() == 36 ); + EXAM_REQUIRE( s[8] == '-' ); + EXAM_REQUIRE( s[13] == '-' ); + EXAM_REQUIRE( s[18] == '-' ); + EXAM_REQUIRE( s[23] == '-' ); + + EXAM_REQUIRE( s.find_first_not_of( "0123456789abcdef-" ) == std::string::npos ); + } + return EXAM_RESULT; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-02 09:39:35
|
Revision: 1941 http://complement.svn.sourceforge.net/complement/?rev=1941&view=rev Author: complement Date: 2008-07-02 02:39:31 -0700 (Wed, 02 Jul 2008) Log Message: ----------- merge mistake Modified Paths: -------------- trunk/complement/explore/lib/mt/uid.cc Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2008-07-02 09:28:14 UTC (rev 1940) +++ trunk/complement/explore/lib/mt/uid.cc 2008-07-02 09:39:31 UTC (rev 1941) @@ -87,16 +87,6 @@ ::close( fd ); } -__uuid_init::__uuid_init() -{ - fd = ::open( "/proc/sys/kernel/random/uuid", O_RDONLY ); -} - -__uuid_init::~__uuid_init() -{ - ::close( fd ); -} - } // namespace detail using namespace std; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-02 09:28:17
|
Revision: 1940 http://complement.svn.sourceforge.net/complement/?rev=1940&view=rev Author: complement Date: 2008-07-02 02:28:14 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Merge branch 'master' of /export/hostel/pub/scm/complement Conflicts: complement/explore/lib/mt/ChangeLog complement/explore/lib/mt/uid.cc complement/explore/lib/mt/ut/mt_test_suite.cc complement/explore/lib/mt/ut/mt_test_wg21.cc complement/explore/lib/mt/ut/mt_test_wg21.h complement/explore/lib/mt/ut/shm_test.cc Modified Paths: -------------- trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/uid.cc trunk/complement/explore/lib/mt/ut/mt_test_suite.cc trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc trunk/complement/explore/lib/mt/ut/mt_test_wg21.h trunk/complement/explore/lib/mt/ut/shm_test.cc Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-07-02 05:36:38 UTC (rev 1939) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-07-02 09:28:14 UTC (rev 1940) @@ -1,5 +1,7 @@ 2008-07-02 Petr Ovtchenkov <pt...@is...> + * uid.cc: fix wrong type cast; + * uid.cc: fix generation of uids; * mt_test_suite.cc, mt_test_wg21.cc, mt_test_wg21.h: test Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2008-07-02 05:36:38 UTC (rev 1939) +++ trunk/complement/explore/lib/mt/uid.cc 2008-07-02 09:28:14 UTC (rev 1940) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/02 08:56:16 ptr> +// -*- C++ -*- Time-stamp: <08/07/02 13:15:01 yeti> /* * Copyright (c) 2006, 2008 @@ -71,22 +71,10 @@ << _host_id_str[34] << _host_id_str[35]; s >> hex - >> reinterpret_cast<unsigned&>(_host_id.u.b[0]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[1]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[2]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[3]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[4]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[5]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[6]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[7]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[8]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[9]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[10]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[11]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[12]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[13]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[14]) - >> reinterpret_cast<unsigned&>(_host_id.u.b[15]); + >> _host_id.u.b[0] >> _host_id.u.b[1] >> _host_id.u.b[2] >> _host_id.u.b[3] + >> _host_id.u.b[4] >> _host_id.u.b[5] >> _host_id.u.b[6] >> _host_id.u.b[7] + >> _host_id.u.b[8] >> _host_id.u.b[9] >> _host_id.u.b[10] >> _host_id.u.b[11] + >> _host_id.u.b[12] >> _host_id.u.b[13] >> _host_id.u.b[14] >> _host_id.u.b[15]; } __uuid_init::__uuid_init() @@ -99,6 +87,16 @@ ::close( fd ); } +__uuid_init::__uuid_init() +{ + fd = ::open( "/proc/sys/kernel/random/uuid", O_RDONLY ); +} + +__uuid_init::~__uuid_init() +{ + ::close( fd ); +} + } // namespace detail using namespace std; @@ -151,22 +149,10 @@ << tmp[34] << tmp[35]; s >> hex - >> reinterpret_cast<unsigned&>(id.u.b[0]) - >> reinterpret_cast<unsigned&>(id.u.b[1]) - >> reinterpret_cast<unsigned&>(id.u.b[2]) - >> reinterpret_cast<unsigned&>(id.u.b[3]) - >> reinterpret_cast<unsigned&>(id.u.b[4]) - >> reinterpret_cast<unsigned&>(id.u.b[5]) - >> reinterpret_cast<unsigned&>(id.u.b[6]) - >> reinterpret_cast<unsigned&>(id.u.b[7]) - >> reinterpret_cast<unsigned&>(id.u.b[8]) - >> reinterpret_cast<unsigned&>(id.u.b[9]) - >> reinterpret_cast<unsigned&>(id.u.b[10]) - >> reinterpret_cast<unsigned&>(id.u.b[11]) - >> reinterpret_cast<unsigned&>(id.u.b[12]) - >> reinterpret_cast<unsigned&>(id.u.b[13]) - >> reinterpret_cast<unsigned&>(id.u.b[14]) - >> reinterpret_cast<unsigned&>(id.u.b[15]); + >> id.u.b[0] >> id.u.b[1] >> id.u.b[2] >> id.u.b[3] + >> id.u.b[4] >> id.u.b[5] >> id.u.b[6] >> id.u.b[7] + >> id.u.b[8] >> id.u.b[9] >> id.u.b[10] >> id.u.b[11] + >> id.u.b[12] >> id.u.b[13] >> id.u.b[14] >> id.u.b[15]; return id; } Modified: trunk/complement/explore/lib/mt/ut/mt_test_suite.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2008-07-02 05:36:38 UTC (rev 1939) +++ trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2008-07-02 09:28:14 UTC (rev 1940) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/02 09:24:48 ptr> +// -*- C++ -*- Time-stamp: <08/07/02 13:01:53 yeti> /* * Copyright (c) 2006-2008 @@ -81,8 +81,10 @@ uid_test_wg21 test_wg21_uid; - t.add( &uid_test_wg21::uid, test_wg21_uid, "uid_test_wg21::uid" ); - t.add( &uid_test_wg21::hostid, test_wg21_uid, "uid_test_wg21::hostid" ); + t.add( &uid_test_wg21::uid, test_wg21_uid, "uid_test_wg21::uid", + t.add( &uid_test_wg21::uidstr, test_wg21_uid, "uid_test_wg21::uidstr" ) ); + t.add( &uid_test_wg21::hostid, test_wg21_uid, "uid_test_wg21::hostid", + t.add( &uid_test_wg21::hostidstr, test_wg21_uid, "uid_test_wg21::hostidstr" ) ); Opts opts; Modified: trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-02 05:36:38 UTC (rev 1939) +++ trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-02 09:28:14 UTC (rev 1940) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/02 09:21:04 ptr> +// -*- C++ -*- Time-stamp: <08/07/02 13:00:38 yeti> /* * Copyright (c) 2006-2008 @@ -318,7 +318,7 @@ return EXAM_RESULT; } -int EXAM_IMPL(uid_test_wg21::uid) +int EXAM_IMPL(uid_test_wg21::uidstr) { std::string u1 = xmt::uid_str(); @@ -337,7 +337,7 @@ return EXAM_RESULT; } -int EXAM_IMPL(uid_test_wg21::hostid) +int EXAM_IMPL(uid_test_wg21::hostidstr) { std::string u1 = xmt::hostid_str(); @@ -354,3 +354,22 @@ return EXAM_RESULT; } +int EXAM_IMPL(uid_test_wg21::hostid) +{ + xmt::uuid_type u1 = xmt::hostid(); + xmt::uuid_type u2 = xmt::hostid(); + + EXAM_CHECK( u1 == u2 ); + + return EXAM_RESULT; +} + +int EXAM_IMPL(uid_test_wg21::uid) +{ + xmt::uuid_type u1 = xmt::uid(); + xmt::uuid_type u2 = xmt::uid(); + + EXAM_CHECK( u1 != u2 ); + + return EXAM_RESULT; +} Modified: trunk/complement/explore/lib/mt/ut/mt_test_wg21.h =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_wg21.h 2008-07-02 05:36:38 UTC (rev 1939) +++ trunk/complement/explore/lib/mt/ut/mt_test_wg21.h 2008-07-02 09:28:14 UTC (rev 1940) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/02 09:27:26 ptr> +// -*- C++ -*- Time-stamp: <08/07/02 12:59:27 yeti> /* * Copyright (c) 2006-2008 @@ -33,7 +33,9 @@ class uid_test_wg21 { public: + int EXAM_DECL(uidstr); int EXAM_DECL(uid); + int EXAM_DECL(hostidstr); int EXAM_DECL(hostid); }; Modified: trunk/complement/explore/lib/mt/ut/shm_test.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/shm_test.cc 2008-07-02 05:36:38 UTC (rev 1939) +++ trunk/complement/explore/lib/mt/ut/shm_test.cc 2008-07-02 09:28:14 UTC (rev 1940) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/02 08:58:02 ptr> +// -*- C++ -*- Time-stamp: <08/07/02 13:05:03 yeti> /* * Copyright (c) 2006-2008 @@ -336,7 +336,13 @@ seg1.allocate( fname1, 4*4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); } catch ( xmt::shm_bad_alloc& err ) { - EXAM_ERROR_ASYNC( err.what() ); + try { + seg1.allocate( fname1, 4*4096, 0, 0660 ); + } + catch ( xmt::shm_bad_alloc& err2 ) { + EXAM_ERROR_ASYNC( err2.what() ); + unlink( fname1 ); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-02 05:36:40
|
Revision: 1939 http://complement.svn.sourceforge.net/complement/?rev=1939&view=rev Author: complement Date: 2008-07-01 22:36:38 -0700 (Tue, 01 Jul 2008) Log Message: ----------- fix generation of uids; libxmt 2.0.5. Avoid fstream in uid generation: only 'read' need here: it atomic, that's why allow to skip mutexes. In shared memory test use tr2::condition_event_ip and tr2::barrier_ip (extention to wg21 draft). Modified Paths: -------------- trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/uid.cc trunk/complement/explore/lib/mt/ut/Makefile trunk/complement/explore/lib/mt/ut/Makefile.inc trunk/complement/explore/lib/mt/ut/mt_test_suite.cc trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc trunk/complement/explore/lib/mt/ut/mt_test_wg21.h trunk/complement/explore/lib/mt/ut/shm_test.cc Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-07-02 05:36:21 UTC (rev 1938) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-07-02 05:36:38 UTC (rev 1939) @@ -1,3 +1,14 @@ +2008-07-02 Petr Ovtchenkov <pt...@is...> + + * uid.cc: fix generation of uids; + + * mt_test_suite.cc, mt_test_wg21.cc, mt_test_wg21.h: test + for uids; use options for test suite; + + * shm_test.cc: use WG21-style conditionals; + + * libxmt: bump revision to 2.0.5. + 2008-06-30 Petr Ovtchenkov <ye...@ya...> * shm.h: condition_event_ip may be used in shared memory; Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2008-07-02 05:36:21 UTC (rev 1938) +++ trunk/complement/explore/lib/mt/Makefile.inc 2008-07-02 05:36:38 UTC (rev 1939) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <08/06/30 13:51:45 yeti> +# -*- Makefile -*- Time-stamp: <08/07/02 09:28:02 ptr> LIBNAME = xmt MAJOR = 2 MINOR = 0 -PATCH = 4 +PATCH = 5 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc callstack.cc system_error.cc thread.cc \ date_time.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2008-07-02 05:36:21 UTC (rev 1938) +++ trunk/complement/explore/lib/mt/uid.cc 2008-07-02 05:36:38 UTC (rev 1939) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <08/06/06 21:23:34 yeti> +// -*- C++ -*- Time-stamp: <08/07/02 08:56:16 ptr> /* - * Copyright (c) 2006 + * Copyright (c) 2006, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -10,10 +10,11 @@ #include <mt/uid.h> #include <mt/mutex> -#include <fstream> #include <sstream> #include <iomanip> #include <cstring> +#include <unistd.h> +#include <fcntl.h> namespace xmt { @@ -29,26 +30,28 @@ __uid_init(); static uuid_type _host_id; - static char _host_id_str[48]; // 37 really + char _host_id_str[48]; // 37 really }; uuid_type __uid_init::_host_id; -char __uid_init::_host_id_str[48]; -// ifstream _uuid; +struct __uuid_init +{ + public: + __uuid_init(); + ~__uuid_init(); + int fd; +}; + __uid_init::__uid_init() { - static mutex _lk; + int fd = ::open( "/proc/sys/kernel/random/boot_id", O_RDONLY ); - lock_guard<mutex> lock( _lk ); - ifstream f( "/proc/sys/kernel/random/boot_id" ); + ::read( fd, _host_id_str, 36 ); + _host_id_str[36] = '\0'; + ::close( fd ); - string tmp; - getline( f, tmp ); - strcpy( _host_id_str, tmp.c_str() ); - - stringstream s; s << _host_id_str[0] << _host_id_str[1] << ' ' << _host_id_str[2] << _host_id_str[3] << ' ' @@ -86,6 +89,16 @@ >> reinterpret_cast<unsigned&>(_host_id.u.b[15]); } +__uuid_init::__uuid_init() +{ + fd = ::open( "/proc/sys/kernel/random/uuid", O_RDONLY ); +} + +__uuid_init::~__uuid_init() +{ + ::close( fd ); +} + } // namespace detail using namespace std; @@ -94,7 +107,7 @@ const char *hostid_str() { static detail::__uid_init _uid; - return detail::__uid_init::_host_id_str; + return _uid._host_id_str; } const xmt::uuid_type& hostid() @@ -105,22 +118,13 @@ std::string uid_str() { - static mutex _lk; + static detail::__uuid_init __uuid; - lock_guard<mutex> lock( _lk ); + char buf[36]; - // if ( !detail::_uuid.is_open() ) { - // detail::_uuid.open( "/proc/sys/kernel/random/uuid" ); - // } + ::read( __uuid.fd, buf, 36 ); - ifstream _uuid( "/proc/sys/kernel/random/uuid" ); - - std::string tmp; - - // getline( detail::_uuid, tmp ).clear(); // clear eof bit - getline( _uuid, tmp ); - - return tmp; + return std::string( buf, 36 ); } xmt::uuid_type uid() Modified: trunk/complement/explore/lib/mt/ut/Makefile =================================================================== --- trunk/complement/explore/lib/mt/ut/Makefile 2008-07-02 05:36:21 UTC (rev 1938) +++ trunk/complement/explore/lib/mt/ut/Makefile 2008-07-02 05:36:38 UTC (rev 1939) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <08/06/12 15:11:40 ptr> +# -*- Makefile -*- Time-stamp: <08/07/02 09:15:45 ptr> SRCROOT := ../../.. @@ -21,18 +21,18 @@ # endif LIBMT_DIR = ${CoMT_DIR}/lib/mt -# LIBUTF_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/test/unit_test_framework LIBEXAM_DIR = ${CoMT_DIR}/lib/exam +LIBMISC_DIR = ${CoMT_DIR}/lib/misc LIBFS_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/filesystem ifeq ($(OSNAME),linux) -release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBFS_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBFS_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBFS_DIR}/${OUTPUT_DIR} -L${LIBMISC_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBFS_DIR}/${OUTPUT_DIR}:${LIBMISC_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBFS_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBFS_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBFS_DIR}/${OUTPUT_DIR_DBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBFS_DIR}/${OUTPUT_DIR_DBG}:${LIBMISC_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBFS_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBFS_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBFS_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBFS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif @@ -49,10 +49,10 @@ endif -release-shared : LDLIBS = -lxmt -lexam -lboost_fs -dbg-shared : LDLIBS = -lxmtg -lexamg -lboost_fsg +release-shared : LDLIBS = -lxmt -lexam -lmisc -lboost_fs +dbg-shared : LDLIBS = -lxmtg -lexamg -lmiscg -lboost_fsg ifndef WITHOUT_STLPORT -stldbg-shared : LDLIBS = -lxmtstlg -lexamstlg -lboost_fsstlg +stldbg-shared : LDLIBS = -lxmtstlg -lexamstlg -lmiscstlg -lboost_fsstlg endif ifeq ($(OSNAME),freebsd) Modified: trunk/complement/explore/lib/mt/ut/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/ut/Makefile.inc 2008-07-02 05:36:21 UTC (rev 1938) +++ trunk/complement/explore/lib/mt/ut/Makefile.inc 2008-07-02 05:36:38 UTC (rev 1939) @@ -1,7 +1,7 @@ -# -*- makefile -*- Time-stamp: <08/03/26 10:12:36 ptr> +# -*- makefile -*- Time-stamp: <08/07/02 09:03:03 ptr> PRGNAME = mt_ut -SRC_CC = unit_test.cc timespec.cc \ +SRC_CC = timespec.cc \ signal-1.cc signal-3.cc \ mt_test.cc shm_test.cc mt_test_suite.cc \ mt_test_wg21.cc Modified: trunk/complement/explore/lib/mt/ut/mt_test_suite.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2008-07-02 05:36:21 UTC (rev 1938) +++ trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2008-07-02 05:36:38 UTC (rev 1939) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/26 10:12:21 ptr> +// -*- C++ -*- Time-stamp: <08/07/02 09:24:48 ptr> /* * Copyright (c) 2006-2008 @@ -15,6 +15,9 @@ #include <config/feature.h> +#include <misc/opts.h> +#include <string> + int EXAM_DECL(timespec_diff); int EXAM_DECL(signal_1_test); // int EXAM_DECL(signal_2_test); @@ -24,7 +27,7 @@ // int EXAM_DECL( flock_test ); // int EXAM_DECL( lfs_test ); -int EXAM_IMPL(mt_test_suite) +int main( int argc, const char** argv ) { exam::test_suite t( "libxmt test" ); mt_test test; @@ -75,7 +78,58 @@ t.add( &mt_test_wg21::barrier, test_wg21, "mt_test_wg21::barrier" ); t.add( &mt_test_wg21::semaphore, test_wg21, "mt_test_wg21::semaphore" ); t.add( &mt_test_wg21::fork, test_wg21, "mt_test_wg21::fork" ); - t.add( &mt_test_wg21::uid, test_wg21, "mt_test_wg21::uid" ); + uid_test_wg21 test_wg21_uid; + + t.add( &uid_test_wg21::uid, test_wg21_uid, "uid_test_wg21::uid" ); + t.add( &uid_test_wg21::hostid, test_wg21_uid, "uid_test_wg21::hostid" ); + + Opts opts; + + opts.description( "test suite for 'sockios' framework" ); + opts.usage( "[options]" ); + + opts << option<bool>( "print this help message", 'h', "help" ) + << option<bool>( "list all test cases", 'l', "list" ) + << option<std::string>( "run tests by number", 'r', "run" )["0"] + << option<bool>( "print status of tests within test suite", 'v', "verbose" ) + << option<bool>( "trace checks", 't', "trace" ); + + try { + opts.parse( argc, argv ); + } + catch (...) { + opts.help( std::cerr ); + return 1; + } + + if ( opts.is_set( 'h' ) ) { + opts.help( std::cerr ); + return 0; + } + + if ( opts.is_set( 'l' ) ) { + t.print_graph( std::cerr ); + return 0; + } + + if ( opts.is_set( 'v' ) ) { + t.flags( t.flags() | exam::base_logger::verbose ); + } + + if ( opts.is_set( 't' ) ) { + t.flags( t.flags() | exam::base_logger::trace ); + } + + if ( opts.is_set( 'r' ) ) { + std::stringstream ss( opts.get<std::string>( 'r' ) ); + int n; + while ( ss >> n ) { + t.single( n ); + } + + return 0; + } + return t.girdle(); }; Modified: trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-02 05:36:21 UTC (rev 1938) +++ trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-02 05:36:38 UTC (rev 1939) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/26 01:53:46 ptr> +// -*- C++ -*- Time-stamp: <08/07/02 09:21:04 ptr> /* * Copyright (c) 2006-2008 @@ -318,18 +318,39 @@ return EXAM_RESULT; } -int EXAM_IMPL(mt_test_wg21::uid) +int EXAM_IMPL(uid_test_wg21::uid) { std::string u1 = xmt::uid_str(); EXAM_CHECK( !u1.empty() ); + EXAM_CHECK( u1.length() == 36 ); + std::string u2 = xmt::uid_str(); EXAM_CHECK( !u2.empty() ); + EXAM_CHECK( u2.length() == 36 ); + EXAM_CHECK( u1 != u2 ); return EXAM_RESULT; } +int EXAM_IMPL(uid_test_wg21::hostid) +{ + std::string u1 = xmt::hostid_str(); + + EXAM_CHECK( !u1.empty() ); + + EXAM_CHECK( u1.length() == 36 ); + + std::string u2 = xmt::hostid_str(); + + EXAM_CHECK( !u2.empty() ); + + EXAM_CHECK( u1 == u2 ); + + return EXAM_RESULT; +} + Modified: trunk/complement/explore/lib/mt/ut/mt_test_wg21.h =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_wg21.h 2008-07-02 05:36:21 UTC (rev 1938) +++ trunk/complement/explore/lib/mt/ut/mt_test_wg21.h 2008-07-02 05:36:38 UTC (rev 1939) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/02/25 12:12:20 ptr> +// -*- C++ -*- Time-stamp: <08/07/02 09:27:26 ptr> /* * Copyright (c) 2006-2008 @@ -14,7 +14,6 @@ #define FIT_EXAM #include <exam/suite.h> -// #include <mt/shm.h> class mt_test_wg21 { @@ -25,11 +24,17 @@ int EXAM_DECL(barrier); int EXAM_DECL(semaphore); int EXAM_DECL(fork); - int EXAM_DECL(uid); private: // static xmt::Thread::ret_t thread_entry_call( void * ); // static int x; }; +class uid_test_wg21 +{ + public: + int EXAM_DECL(uid); + int EXAM_DECL(hostid); +}; + #endif // __MT_TEST_WG21_H Modified: trunk/complement/explore/lib/mt/ut/shm_test.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/shm_test.cc 2008-07-02 05:36:21 UTC (rev 1938) +++ trunk/complement/explore/lib/mt/ut/shm_test.cc 2008-07-02 05:36:38 UTC (rev 1939) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <08/03/26 10:11:58 ptr> +// -*- C++ -*- Time-stamp: <08/07/02 08:58:02 ptr> /* - * Copyright (c) 2006, 2007 + * Copyright (c) 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License Version 3.0 @@ -10,7 +10,7 @@ #include "shm_test.h" -#include <mt/xmt.h> +#include <mt/condition_variable> #include <mt/shm.h> @@ -188,27 +188,29 @@ seg.allocate( fname, 1024, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); xmt::allocator_shm<char,0> shm; - xmt::__condition<true>& fcnd = *new( shm.allocate( sizeof(xmt::__condition<true>) ) ) xmt::__condition<true>(); - fcnd.set( false ); + std::tr2::condition_event_ip& fcnd = *new( shm.allocate( sizeof(std::tr2::condition_event_ip) ) ) std::tr2::condition_event_ip(); + try { xmt::fork(); try { // Child code - fcnd.try_wait(); + if ( fcnd.timed_wait( std::tr2::milliseconds( 800 ) ) ) { + exit( 0 ); + } } catch ( ... ) { } - exit( 0 ); + exit( 1 ); } catch ( xmt::fork_in_parent& child ) { try { EXAM_CHECK( child.pid() > 0 ); - fcnd.set( true ); + fcnd.notify_one(); int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); @@ -224,8 +226,8 @@ catch ( ... ) { } - (&fcnd)->~__condition<true>(); - shm.deallocate( reinterpret_cast<char *>(&fcnd), sizeof(xmt::__condition<true>) ); + (&fcnd)->~__condition_event<true>(); + shm.deallocate( reinterpret_cast<char *>(&fcnd), sizeof(std::tr2::condition_event_ip) ); seg.deallocate(); fs::remove( fname ); } @@ -251,11 +253,10 @@ seg.allocate( fname, 4*4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); xmt::shm_name_mgr<0>& nm = seg.name_mgr(); - xmt::allocator_shm<xmt::__condition<true>,0> shm; + xmt::allocator_shm<std::tr2::condition_event_ip,0> shm; - xmt::__condition<true>& fcnd = *new ( shm.allocate( 1 ) ) xmt::__condition<true>(); + std::tr2::condition_event_ip& fcnd = *new ( shm.allocate( 1 ) ) std::tr2::condition_event_ip(); nm.named( fcnd, test_Condition_Object ); - fcnd.set( false ); try { xmt::fork(); @@ -276,8 +277,8 @@ } xmt::shm_name_mgr<0>& nm_ch = seg_ch.name_mgr(); - xmt::__condition<true>& fcnd_ch = nm_ch.named<xmt::__condition<true> >( test_Condition_Object ); - fcnd_ch.set( true ); + std::tr2::condition_event_ip& fcnd_ch = nm_ch.named<std::tr2::condition_event_ip>( test_Condition_Object ); + fcnd_ch.notify_one(); } catch ( const xmt::shm_bad_alloc& err ) { EXAM_ERROR_ASYNC_F( err.what(), eflag ); @@ -295,7 +296,7 @@ try { EXAM_CHECK( child.pid() > 0 ); - fcnd.try_wait(); + EXAM_CHECK( fcnd.timed_wait( std::tr2::milliseconds( 800 ) ) ); int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); @@ -313,7 +314,7 @@ EXAM_ERROR( "Fail in fork" ); } - (&fcnd)->~__condition<true>(); + (&fcnd)->~__condition_event<true>(); shm.deallocate( &fcnd, 1 ); seg.deallocate(); fs::remove( fname ); @@ -359,11 +360,10 @@ try { xmt::shm_name_mgr<1>& nm = seg1.name_mgr(); - xmt::allocator_shm<xmt::__condition<true>,1> shm; + xmt::allocator_shm<std::tr2::condition_event_ip,1> shm; - xmt::__condition<true>& fcnd = *new ( shm.allocate( 1 ) ) xmt::__condition<true>(); + std::tr2::condition_event_ip& fcnd = *new ( shm.allocate( 1 ) ) std::tr2::condition_event_ip(); nm.named( fcnd, ObjName ); - fcnd.set( false ); try { xmt::fork(); @@ -372,10 +372,10 @@ try { xmt::shm_name_mgr<1>& nm_ch = seg1.name_mgr(); - xmt::allocator_shm<xmt::__condition<true>,1> shm_ch; - xmt::__condition<true>& fcnd_ch = nm_ch.named<xmt::__condition<true> >( ObjName ); - fcnd_ch.set( true ); - nm_ch.release<xmt::__condition<true> >( ObjName ); + xmt::allocator_shm<std::tr2::condition_event_ip,1> shm_ch; + std::tr2::condition_event_ip& fcnd_ch = nm_ch.named<std::tr2::condition_event_ip>( ObjName ); + fcnd_ch.notify_one(); + nm_ch.release<std::tr2::condition_event_ip>( ObjName ); } catch ( const std::invalid_argument& err ) { EXAM_ERROR_ASYNC_F( err.what(), eflag ); @@ -383,7 +383,7 @@ exit( eflag ); } catch ( xmt::fork_in_parent& child ) { - fcnd.try_wait(); + EXAM_CHECK( fcnd.timed_wait( std::tr2::milliseconds( 800 ) ) ); int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); if ( WIFEXITED(stat) ) { @@ -392,11 +392,10 @@ EXAM_ERROR( "child interrupted" ); } } - nm.release<xmt::__condition<true> >( ObjName ); // fcnd should be destroyed here + nm.release<std::tr2::condition_event_ip>( ObjName ); // fcnd should be destroyed here - xmt::__condition<true>& fcnd1 = *new ( shm.allocate( 1 ) ) xmt::__condition<true>(); + std::tr2::condition_event_ip& fcnd1 = *new ( shm.allocate( 1 ) ) std::tr2::condition_event_ip(); nm.named( fcnd1, ObjName ); // ObjName should be free here - fcnd1.set( false ); try { xmt::fork(); @@ -405,10 +404,10 @@ try { xmt::shm_name_mgr<1>& nm_ch = seg1.name_mgr(); - xmt::allocator_shm<xmt::__condition<true>,1> shm_ch; - xmt::__condition<true>& fcnd_ch = nm_ch.named<xmt::__condition<true> >( ObjName ); - fcnd_ch.set( true ); - nm_ch.release<xmt::__condition<true> >( ObjName ); + xmt::allocator_shm<std::tr2::condition_event_ip,1> shm_ch; + std::tr2::condition_event_ip& fcnd_ch = nm_ch.named<std::tr2::condition_event_ip>( ObjName ); + fcnd_ch.notify_one(); + nm_ch.release<std::tr2::condition_event_ip>( ObjName ); } catch ( const std::invalid_argument& err ) { EXAM_ERROR_ASYNC_F( err.what(), eflag ); @@ -417,7 +416,7 @@ exit( eflag ); } catch ( xmt::fork_in_parent& child ) { - fcnd1.try_wait(); + EXAM_CHECK( fcnd1.timed_wait( std::tr2::milliseconds( 800 ) ) ); int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); if ( WIFEXITED(stat) ) { @@ -426,10 +425,10 @@ EXAM_ERROR( "child interrupted" ); } } - nm.release<xmt::__condition<true> >( ObjName ); // fcnd should be destroyed here + nm.release<std::tr2::condition_event_ip>( ObjName ); // fcnd should be destroyed here - xmt::allocator_shm<xmt::__barrier<true>,1> shm_b; - xmt::__barrier<true>& b = *new ( shm_b.allocate( 1 ) ) xmt::__barrier<true>(); + xmt::allocator_shm<std::tr2::barrier_ip,1> shm_b; + std::tr2::barrier_ip& b = *new ( shm_b.allocate( 1 ) ) std::tr2::barrier_ip(); nm.named( b, ObjName ); // ObjName should be free here @@ -439,10 +438,10 @@ int eflag = 0; try { xmt::shm_name_mgr<1>& nm_ch = seg1.name_mgr(); - xmt::allocator_shm<xmt::__barrier<true>,1> shm_ch; - xmt::__barrier<true>& b_ch = nm_ch.named<xmt::__barrier<true> >( ObjName ); + xmt::allocator_shm<std::tr2::barrier_ip,1> shm_ch; + std::tr2::barrier_ip& b_ch = nm_ch.named<std::tr2::barrier_ip>( ObjName ); b_ch.wait(); - nm_ch.release<xmt::__barrier<true> >( ObjName ); + nm_ch.release<std::tr2::barrier_ip>( ObjName ); } catch ( const std::invalid_argument& err ) { EXAM_ERROR_ASYNC_F( err.what(), eflag ); @@ -460,7 +459,7 @@ EXAM_ERROR( "child interrupted" ); } } - nm.release<xmt::__barrier<true> >( ObjName ); // barrier should be destroyed here + nm.release<std::tr2::barrier_ip>( ObjName ); // barrier should be destroyed here } catch ( xmt::shm_bad_alloc& err ) { EXAM_ERROR( err.what() ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-02 05:36:23
|
Revision: 1938 http://complement.svn.sourceforge.net/complement/?rev=1938&view=rev Author: complement Date: 2008-07-01 22:36:21 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Merge branch 'master' of /export/hostel/pub/scm/complement Conflicts: complement/explore/include/sockios/sockmgr.cc complement/explore/lib/stem/NetTransport.cc Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockstream trunk/complement/explore/include/sockios/sockstream.cc trunk/complement/explore/lib/sockios/ut/Makefile trunk/complement/explore/lib/sockios/ut/Makefile.inc trunk/complement/explore/lib/sockios/ut/sockios2_test.cc trunk/complement/explore/lib/sockios/ut/sockios2_test.h trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc trunk/complement/explore/lib/stem/NetTransport.cc Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/01 10:16:39 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 14:40:03 yeti> /* * Copyright (c) 2008 @@ -407,13 +407,19 @@ } if ( (ev.events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR) ) != 0 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; - if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { - // throw system_error - std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; - } if ( info.p != 0 ) { + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + // throw system_error + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; + } + { + std::tr2::lock_guard<std::tr2::mutex> lk( b->ulck ); + b->close(); + b->ucnd.notify_all(); + } // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; @@ -434,7 +440,9 @@ std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; } descr.erase( ifd ); + std::tr2::lock_guard<std::tr2::mutex> lk( b->ulck ); b->close(); + b->ucnd.notify_all(); } // dump_descr(); } Modified: trunk/complement/explore/include/sockios/sockstream =================================================================== --- trunk/complement/explore/include/sockios/sockstream 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/include/sockios/sockstream 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 00:51:30 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 14:46:29 yeti> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -480,7 +480,7 @@ protected: virtual streamsize showmanyc() - { return this->egptr() - this->gptr(); } + { return basic_socket_t::_fd != -1 ? this->egptr() - this->gptr() : -1; } virtual int_type underflow(); virtual int_type overflow( int_type c = traits::eof() ); @@ -568,7 +568,7 @@ b( self ) { } bool operator ()() const - { return b.showmanyc() != 0; } + { return b.showmanyc() > 0; } private: sockbuf_type& b; } rdready; Modified: trunk/complement/explore/include/sockios/sockstream.cc =================================================================== --- trunk/complement/explore/include/sockios/sockstream.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/include/sockios/sockstream.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/26 08:40:03 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 13:30:58 yeti> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -307,8 +307,9 @@ std::tr2::unique_lock<std::tr2::mutex> lk( ulck ); - if ( this->gptr() < this->egptr() ) + if ( this->gptr() < this->egptr() ) { return traits::to_int_type(*this->gptr()); + } if ( this->egptr() == this->gptr() ) { // fullfilled: _ebuf == gptr() setg( this->eback(), this->eback(), this->eback() ); @@ -317,12 +318,14 @@ // setg( this->eback(), this->eback(), this->eback() + offset ); // wait on condition if ( basic_socket_t::_use_rdtimeout ) { - ucnd.timed_wait( lk, basic_socket_t::_rdtimeout, rdready ); + if ( !ucnd.timed_wait( lk, basic_socket_t::_rdtimeout, rdready ) ) { + return traits::eof(); + } } else { ucnd.wait( lk, rdready ); } - - return traits::to_int_type(*this->gptr()); + + return this->gptr() < this->egptr() ? traits::to_int_type(*this->gptr()) : traits::eof(); } template<class charT, class traits, class _Alloc> Modified: trunk/complement/explore/lib/sockios/ut/Makefile =================================================================== --- trunk/complement/explore/lib/sockios/ut/Makefile 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/Makefile 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <08/06/12 15:24:26 ptr> +# -*- Makefile -*- Time-stamp: <08/07/01 12:27:54 yeti> SRCROOT := ../../.. @@ -15,18 +15,24 @@ LIBMT_DIR = ${CoMT_DIR}/lib/mt LIBSOCK_DIR = ${CoMT_DIR}/lib/sockios LIBEXAM_DIR = ${CoMT_DIR}/lib/exam -# LIBUTF_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/test/unit_test_framework +LIBMISC_DIR = ${CoMT_DIR}/lib/misc ifeq ($(OSNAME),linux) -release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} + +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBMISC_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBMISC_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} + +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBMISC_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} + ifndef WITHOUT_STLPORT -stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} + endif -release-shared : LDLIBS = -lxmt -lsockios -lexam +release-shared : LDLIBS = -lxmt -lsockios -lexam -lmisc + +dbg-shared : LDLIBS = -lxmtg -lsockiosg -lexamg -lmiscg + ifndef WITHOUT_STLPORT -stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lexamstlg +stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lexamstlg -lmiscstlg endif -dbg-shared : LDLIBS = -lxmtg -lsockiosg -lexamg Modified: trunk/complement/explore/lib/sockios/ut/Makefile.inc =================================================================== --- trunk/complement/explore/lib/sockios/ut/Makefile.inc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/Makefile.inc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,5 +1,5 @@ -# -*- makefile -*- Time-stamp: <08/06/09 20:31:17 yeti> +# -*- makefile -*- Time-stamp: <08/07/01 12:22:34 yeti> PRGNAME = sockios_ut SRC_CC = message.cc \ - names.cc sockios_test.cc sockios2_test.cc sockios_test_suite.cc unit_test.cc + names.cc sockios_test.cc sockios2_test.cc sockios_test_suite.cc Modified: trunk/complement/explore/lib/sockios/ut/sockios2_test.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios2_test.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/sockios2_test.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/26 21:29:52 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 15:28:50 yeti> /* * @@ -464,6 +464,96 @@ return EXAM_RESULT; } +class srv_reader +{ + public: + srv_reader( sockstream& ) + { } + ~srv_reader() + { } + void connect( sockstream& s ) + { + char buf[64]; + + while ( s.read( buf, 4 ).good() ) { + continue; + } + + cnd.notify_one(); + } + + static std::tr2::condition_event cnd; +}; + +std::tr2::condition_event srv_reader::cnd; + +int EXAM_IMPL(sockios2_test::disconnect) +{ + const char fname[] = "/tmp/sockios2_test.shm"; + xmt::shm_alloc<0> seg; + + try { + seg.allocate( fname, 4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); + } + catch ( xmt::shm_bad_alloc& err ) { + EXAM_ERROR( err.what() ); + try { + seg.allocate( fname, 4096, 0, 0660 ); + } + catch ( xmt::shm_bad_alloc& err2 ) { + EXAM_ERROR( err.what() ); + return EXAM_RESULT; + } + } + + xmt::allocator_shm<barrier_ip,0> shm; + barrier_ip& b = *new ( shm.allocate( 1 ) ) barrier_ip(); + + try { + this_thread::fork(); + + connect_processor<srv_reader> prss( 2008 ); + + EXAM_CHECK_ASYNC( prss.good() ); + + b.wait(); + + if ( srv_reader::cnd.timed_wait( milliseconds( 800 ) ) ) { + exit( 0 ); + } + // srv_reader::cnd.wait(); + + exit( 1 ); + } + catch ( std::tr2::fork_in_parent& child ) { + b.wait(); + + sockstream s( "localhost", 2008 ); + + char buf[] = "1234"; + + EXAM_CHECK( s.write( buf, 4 ).flush().good() ); + + s.rdbuf()->shutdown( sock_base::stop_in | sock_base::stop_out ); + + // s.close(); + + int stat = -1; + EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + } else { + EXAM_ERROR( "child fail" ); + } + } + + shm.deallocate( &b ); + seg.deallocate(); + unlink( fname ); + + return EXAM_RESULT; +} + int EXAM_IMPL(sockios2_test::fork) { const char fname[] = "/tmp/sockios2_test.shm"; Modified: trunk/complement/explore/lib/sockios/ut/sockios2_test.h =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios2_test.h 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/sockios2_test.h 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 00:55:32 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 12:21:46 yeti> /* * @@ -22,6 +22,7 @@ int EXAM_DECL(srv_core); int EXAM_DECL(connect_disconnect); + int EXAM_DECL(disconnect); int EXAM_DECL(processor_core); int EXAM_DECL(fork); int EXAM_DECL(srv_sigpipe); Modified: trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/11 21:55:26 yeti> +// -*- C++ -*- Time-stamp: <08/07/01 12:57:40 yeti> /* * @@ -9,7 +9,6 @@ * */ -#include "sockios_test_suite.h" #include "sockios_test.h" #include "sockios2_test.h" @@ -17,7 +16,7 @@ #include <iostream> #include <list> -#include <mt/xmt.h> +#include <misc/opts.h> // #include <sockios/sockstream> // #include <sockios/sockmgr.h> @@ -31,14 +30,12 @@ int EXAM_DECL(test_more_bytes_in_socket); int EXAM_DECL(test_more_bytes_in_socket2); -int EXAM_IMPL(sockios_test_suite) +int main( int argc, const char** argv ) { - exam::test_suite::test_case_type tc[3]; + exam::test_suite::test_case_type tc[4]; exam::test_suite t( "libsockios test" ); - t.flags( t.flags() | exam::base_logger::trace | exam::base_logger::verbose ); - #if 0 trivial_sockios_test trivial_test; @@ -83,10 +80,59 @@ t.add( &sockios2_test::read0, test2, "sockios2_test::read0", t.add( &sockios2_test::srv_sigpipe, test2, "sockios2_test::srv_sigpipe", t.add( &sockios2_test::fork, test2, "sockios2_test::fork", - t.add( &sockios2_test::processor_core, test2, "sockios2_test::processor_core", + tc[3] = t.add( &sockios2_test::processor_core, test2, "sockios2_test::processor_core", t.add( &sockios2_test::connect_disconnect, test2, "sockios2_test::connect_disconnect", t.add( &sockios2_test::srv_core, test2, "sockios2_test::srv_core" ) ) ) ) ) ); + t.add( &sockios2_test::disconnect, test2, "sockios2_test::disconnect", tc[3] ); + + Opts opts; + + opts.description( "test suite for 'sockios' framework" ); + opts.usage( "[options]" ); + + opts << option<bool>( "print this help message", 'h', "help" ) + << option<bool>( "list all test cases", 'l', "list" ) + << option<string>( "run tests by number", 'r', "run" )["0"] + << option<bool>( "print status of tests within test suite", 'v', "verbose" ) + << option<bool>( "trace checks", 't', "trace" ); + + try { + opts.parse( argc, argv ); + } + catch (...) { + opts.help( cerr ); + return 1; + } + + if ( opts.is_set( 'h' ) ) { + opts.help( cerr ); + return 0; + } + + if ( opts.is_set( 'l' ) ) { + t.print_graph( cerr ); + return 0; + } + + if ( opts.is_set( 'v' ) ) { + t.flags( t.flags() | exam::base_logger::verbose ); + } + + if ( opts.is_set( 't' ) ) { + t.flags( t.flags() | exam::base_logger::trace ); + } + + if ( opts.is_set( 'r' ) ) { + stringstream ss( opts.get<string>( 'r' ) ); + int n; + while ( ss >> n ) { + t.single( n ); + } + + return 0; + } + return t.girdle(); } Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -105,8 +105,6 @@ uint32_t buf[bsz]; using namespace std; - MT_IO_REENTRANT( *net ) - if ( !net->read( (char *)buf, sizeof(uint32_t) ).good() ) { return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-01 14:42:06
|
Revision: 1937 http://complement.svn.sourceforge.net/complement/?rev=1937&view=rev Author: complement Date: 2008-07-01 07:42:03 -0700 (Tue, 01 Jul 2008) Log Message: ----------- fix generation of uid Fix not good: reopen file for every call Modified Paths: -------------- trunk/complement/explore/lib/mt/uid.cc trunk/complement/explore/lib/mt/ut/mt_test_suite.cc trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc trunk/complement/explore/lib/mt/ut/mt_test_wg21.h Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2008-07-01 14:41:48 UTC (rev 1936) +++ trunk/complement/explore/lib/mt/uid.cc 2008-07-01 14:42:03 UTC (rev 1937) @@ -9,7 +9,7 @@ */ #include <mt/uid.h> -#include <mt/xmt.h> +#include <mt/mutex> #include <fstream> #include <sstream> #include <iomanip> @@ -21,6 +21,7 @@ using namespace std; using namespace xmt; +using namespace std::tr2; class __uid_init { @@ -34,21 +35,13 @@ uuid_type __uid_init::_host_id; char __uid_init::_host_id_str[48]; -class __uuid_init -{ - public: - __uuid_init(); +// ifstream _uuid; - static ifstream _uuid; -}; - -ifstream __uuid_init::_uuid; - __uid_init::__uid_init() { static mutex _lk; - scoped_lock lock( _lk ); + lock_guard<mutex> lock( _lk ); ifstream f( "/proc/sys/kernel/random/boot_id" ); string tmp; @@ -93,20 +86,10 @@ >> reinterpret_cast<unsigned&>(_host_id.u.b[15]); } -__uuid_init::__uuid_init() -{ - static mutex _lk; - - scoped_lock lock( _lk ); - - if ( !_uuid.is_open() ) { - _uuid.open( "/proc/sys/kernel/random/uuid" ); - } -} - } // namespace detail using namespace std; +using namespace std::tr2; const char *hostid_str() { @@ -122,15 +105,20 @@ std::string uid_str() { - static detail::__uuid_init _uid; - static mutex _lk; - scoped_lock lock( _lk ); + lock_guard<mutex> lock( _lk ); + // if ( !detail::_uuid.is_open() ) { + // detail::_uuid.open( "/proc/sys/kernel/random/uuid" ); + // } + + ifstream _uuid( "/proc/sys/kernel/random/uuid" ); + std::string tmp; - getline( _uid._uuid, tmp ); + // getline( detail::_uuid, tmp ).clear(); // clear eof bit + getline( _uuid, tmp ); return tmp; } Modified: trunk/complement/explore/lib/mt/ut/mt_test_suite.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2008-07-01 14:41:48 UTC (rev 1936) +++ trunk/complement/explore/lib/mt/ut/mt_test_suite.cc 2008-07-01 14:42:03 UTC (rev 1937) @@ -75,6 +75,7 @@ t.add( &mt_test_wg21::barrier, test_wg21, "mt_test_wg21::barrier" ); t.add( &mt_test_wg21::semaphore, test_wg21, "mt_test_wg21::semaphore" ); t.add( &mt_test_wg21::fork, test_wg21, "mt_test_wg21::fork" ); + t.add( &mt_test_wg21::uid, test_wg21, "mt_test_wg21::uid" ); return t.girdle(); }; Modified: trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-01 14:41:48 UTC (rev 1936) +++ trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-01 14:42:03 UTC (rev 1937) @@ -23,6 +23,10 @@ #include <sys/ipc.h> #include <sys/shm.h> +#include <mt/uid.h> + +#include <string> + int EXAM_IMPL(mt_test_wg21::date_time) { // using namespace std::tr2; @@ -314,3 +318,18 @@ return EXAM_RESULT; } +int EXAM_IMPL(mt_test_wg21::uid) +{ + std::string u1 = xmt::uid_str(); + + EXAM_CHECK( !u1.empty() ); + + std::string u2 = xmt::uid_str(); + + EXAM_CHECK( !u2.empty() ); + + EXAM_CHECK( u1 != u2 ); + + return EXAM_RESULT; +} + Modified: trunk/complement/explore/lib/mt/ut/mt_test_wg21.h =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_wg21.h 2008-07-01 14:41:48 UTC (rev 1936) +++ trunk/complement/explore/lib/mt/ut/mt_test_wg21.h 2008-07-01 14:42:03 UTC (rev 1937) @@ -25,6 +25,7 @@ int EXAM_DECL(barrier); int EXAM_DECL(semaphore); int EXAM_DECL(fork); + int EXAM_DECL(uid); private: // static xmt::Thread::ret_t thread_entry_call( void * ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-01 14:41:49
|
Revision: 1936 http://complement.svn.sourceforge.net/complement/?rev=1936&view=rev Author: complement Date: 2008-07-01 07:41:48 -0700 (Tue, 01 Jul 2008) Log Message: ----------- print errno in unclean case (debug) Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2008-07-01 14:41:36 UTC (rev 1935) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2008-07-01 14:41:48 UTC (rev 1936) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/26 09:10:47 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 10:16:39 ptr> /* * Copyright (c) 2008 @@ -374,7 +374,7 @@ } break; default: - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << " " << errno << std::endl; break; } break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-01 14:41:39
|
Revision: 1935 http://complement.svn.sourceforge.net/complement/?rev=1935&view=rev Author: complement Date: 2008-07-01 07:41:36 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Replace old xmt-style mutexes/conds by new wg21 implementation. Modified Paths: -------------- trunk/complement/explore/include/stem/Event.h trunk/complement/explore/include/stem/NetTransport.h trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Names.cc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/lib/stem/_EventHandler.cc trunk/complement/explore/lib/stem/ut/Convert.cc trunk/complement/explore/lib/stem/ut/Convert.h trunk/complement/explore/lib/stem/ut/Echo.cc trunk/complement/explore/lib/stem/ut/Echo.h trunk/complement/explore/lib/stem/ut/Makefile trunk/complement/explore/lib/stem/ut/NameService.cc trunk/complement/explore/lib/stem/ut/NameService.h trunk/complement/explore/lib/stem/ut/Node.cc trunk/complement/explore/lib/stem/ut/Node.h trunk/complement/explore/lib/stem/ut/NodeDL.h trunk/complement/explore/lib/stem/ut/dl/loadable_stem.cc trunk/complement/explore/lib/stem/ut/unit_test.cc Modified: trunk/complement/explore/include/stem/Event.h =================================================================== --- trunk/complement/explore/include/stem/Event.h 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/include/stem/Event.h 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <07/10/15 22:41:17 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:14:16 yeti> /* * - * Copyright (c) 1995-1999, 2002, 2003, 2005-2007 + * Copyright (c) 1995-1999, 2002, 2003, 2005-2008 * Petr Ovtchenkov * * Copyright (c) 1999-2001 @@ -29,7 +29,7 @@ #include <misc/type_traits.h> #include <stem/EvPack.h> #include <mt/uid.h> -#include <mt/xmt.h> +#include <mt/thread> #ifdef STLPORT # include <unordered_map> @@ -85,7 +85,7 @@ explicit gaddr_type( stem::addr_type _addr ) : hid( xmt::hostid() ), - pid( xmt::getpid() ), + pid( std::tr2::getpid() ), addr( _addr ) { } Modified: trunk/complement/explore/include/stem/NetTransport.h =================================================================== --- trunk/complement/explore/include/stem/NetTransport.h 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/include/stem/NetTransport.h 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 12:34:34 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 15:29:44 yeti> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006, 2008 @@ -81,6 +81,10 @@ __FIT_DECLSPEC void connect( std::sockstream& ); + + private: + void _do_handshake(); + bool _handshake; }; class NetTransportMgr : Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/EvManager.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 12:36:14 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:18:21 yeti> /* * @@ -20,7 +20,7 @@ #include "stem/EvManager.h" #include "stem/NetTransport.h" #include <iomanip> -#include <mt/xmt.h> +#include <mt/mutex> // #include <typeinfo> @@ -114,7 +114,7 @@ lock_guard<mutex> lk( _lock_xheap ); gaddr_type& gaddr = _ex_heap[id]; gaddr.hid = xmt::hostid(); - gaddr.pid = xmt::getpid(); + gaddr.pid = std::tr2::getpid(); gaddr.addr = id; } @@ -147,7 +147,7 @@ lock_guard<mutex> lk( _lock_xheap ); gaddr_type& gaddr = _ex_heap[id]; gaddr.hid = xmt::hostid(); - gaddr.pid = xmt::getpid(); + gaddr.pid = std::tr2::getpid(); gaddr.addr = id; } @@ -198,7 +198,7 @@ const std::string& info ) { addr_type id; - if ( addr.hid == xmt::hostid() && addr.pid == xmt::getpid() ) { // local + if ( addr.hid == xmt::hostid() && addr.pid == std::tr2::getpid() ) { // local if ( addr.addr & extbit ) { // may be transit object lock_guard<mutex> lk( _lock_xheap ); pair<uuid_tr_heap_type::const_iterator,uuid_tr_heap_type::const_iterator> range = _tr_heap.equal_range( addr ); @@ -286,7 +286,7 @@ __FIT_DECLSPEC addr_type EvManager::reflect( const gaddr_type& addr ) const { - if ( addr.hid == xmt::hostid() && addr.pid == xmt::getpid() ) { + if ( addr.hid == xmt::hostid() && addr.pid == std::tr2::getpid() ) { // this host, this process if ( (addr.addr & extbit) == 0 ) { // looks like local object lock_guard<mutex> _x1( _lock_heap ); @@ -432,7 +432,7 @@ if ( i == _ex_heap.end() ) { // destination not found ostringstream s; s << "external address unknown: " << hex << e.dest() << " from " - << e.src() << ", pid " << xmt::getpid() << dec; + << e.src() << ", pid " << std::tr2::getpid() << dec; throw invalid_argument( s.str() ); } @@ -450,7 +450,7 @@ if ( j == _ex_heap.end() ) { gaddr_type& _gaddr_src = _ex_heap[e.src()]; _gaddr_src.hid = xmt::hostid(); - _gaddr_src.pid = xmt::getpid(); + _gaddr_src.pid = std::tr2::getpid(); _gaddr_src.addr = e.src(); // it may be as local as foreign; if e.src() // is foreign, the object is 'transit object' gaddr_src = _gaddr_src; Modified: trunk/complement/explore/lib/stem/Names.cc =================================================================== --- trunk/complement/explore/lib/stem/Names.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/Names.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <06/12/04 18:43:56 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:11:16 yeti> /* - * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 + * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006, 2008 * Petr Ovtchenkov * * Copyright (c) 1999-2001 @@ -26,12 +26,9 @@ #include <list> #include <iostream> -#include <mt/xmt.h> - namespace stem { using namespace std; -using namespace xmt; __FIT_DECLSPEC Names::Names() : EventHandler() Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 01:28:00 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:07:37 yeti> /* * @@ -264,10 +264,15 @@ __FIT_DECLSPEC NetTransport::NetTransport( std::sockstream& s ) : - NetTransport_base( "stem::NetTransport" ) + NetTransport_base( "stem::NetTransport" ), + _handshake( false ) { net = &s; +} +__FIT_DECLSPEC +void NetTransport::_do_handshake() +{ try { Event ev; gaddr_type dst; @@ -295,40 +300,46 @@ } else { throw runtime_error( "net error or net handshake error" ); } + _handshake = true; } catch ( runtime_error& err ) { try { lock_guard<mutex> 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() + << " (" << net->rdbuf()->inet_addr() << ":" << net->rdbuf()->port() << ")" << endl; } } catch ( ... ) { } - s.close(); + net->close(); } catch ( ... ) { try { lock_guard<mutex> 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() + << " (" << net->rdbuf()->inet_addr() << ":" << net->rdbuf()->port() << ")" << endl; } } catch ( ... ) { } - s.close(); + net->close(); } } __FIT_DECLSPEC void NetTransport::connect( sockstream& s ) { + if ( !_handshake ) { + _do_handshake(); + return; + } + try { Event ev; gaddr_type dst; @@ -339,7 +350,7 @@ try { lock_guard<mutex> 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()->_trs << "Pid/ppid: " << std::tr2::getpid() << "/" << std::tr2::getppid() << "\n"; manager()->dump( *manager()->_trs ) << endl; } } @@ -354,7 +365,7 @@ if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & (EvManager::tracefault)) ) { *manager()->_trs << __FILE__ << ":" << __LINE__ << " (" - << xmt::getpid() << "/" << xmt::getppid() << ") " + << std::tr2::getpid() << "/" << std::tr2::getppid() << ") " << "Unknown destination\n"; manager()->dump( *manager()->_trs ) << endl; } @@ -511,7 +522,7 @@ try { lock_guard<mutex> 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()->_trs << "Pid/ppid: " << std::tr2::getpid() << "/" << std::tr2::getppid() << "\n"; manager()->dump( *manager()->_trs ) << endl; } } @@ -526,7 +537,7 @@ if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & (EvManager::tracefault)) ) { *manager()->_trs << __FILE__ << ":" << __LINE__ << " (" - << xmt::getpid() << "/" << xmt::getppid() << ") " + << std::tr2::getpid() << "/" << std::tr2::getppid() << ") " << "Unknown destination\n"; manager()->dump( *manager()->_trs ) << endl; } @@ -578,7 +589,7 @@ lock_guard<mutex> lk(manager()->_lock_tr); if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & E vManager::tracenet) ) { - *manager()->_trs << "Pid/ppid: " << xmt::getpid() << "/" << xmt::getppid() << + *manager()->_trs << "Pid/ppid: " << std::tr2::getpid() << "/" << std::tr2::getppid() << "\n"; manager()->dump( *manager()->_trs ) << endl; } @@ -594,7 +605,7 @@ if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & (EvManager::tracefault)) ) { *manager()->_trs << __FILE__ << ":" << __LINE__ << " (" - << xmt::getpid() << "/" << xmt::getppid() << ") " + << std::tr2::getpid() << "/" << std::tr2::getppid() << ") " << "Unknown destination\n"; manager()->dump( *manager()->_trs ) << endl; } Modified: trunk/complement/explore/lib/stem/_EventHandler.cc =================================================================== --- trunk/complement/explore/lib/stem/_EventHandler.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/_EventHandler.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 12:32:30 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:16:58 yeti> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006, 2008 @@ -19,7 +19,9 @@ #include "stem/EventHandler.h" #include "stem/EvManager.h" #include "stem/Names.h" -#include "mt/mutex" +#include <mt/mutex> +#include <mt/thread> +#include <mt/uid.h> #include <unistd.h> @@ -265,7 +267,7 @@ __FIT_DECLSPEC gaddr_type EventHandler::self_glid() const { - return gaddr_type(xmt::hostid(), xmt::getpid(), _id ); + return gaddr_type(xmt::hostid(), std::tr2::getpid(), _id ); } } // namespace stem Modified: trunk/complement/explore/lib/stem/ut/Convert.cc =================================================================== --- trunk/complement/explore/lib/stem/ut/Convert.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/Convert.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <07/07/20 00:05:52 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 19:08:00 yeti> /* * - * Copyright (c) 2007 + * Copyright (c) 2007, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -10,7 +10,10 @@ */ #include "Convert.h" +#include <mt/date_time> +using namespace std::tr2; + void mess::pack( std::ostream& s ) const { __pack( s, super_id ); @@ -35,65 +38,64 @@ __net_unpack( s, message ); } +int Convert::v = 0; + + Convert::Convert() : - EventHandler(), - v( 0 ) + EventHandler() { - cnd.set( false ); } Convert::Convert( stem::addr_type id ) : - EventHandler( id ), - v( 0 ) + EventHandler( id ) { - cnd.set( false ); } Convert::Convert( stem::addr_type id, const char *info ) : - EventHandler( id, info ), - v( 0 ) + EventHandler( id, info ) { - cnd.set( false ); } Convert::~Convert() { - // cnd.wait(); } void Convert::handler0() { + lock_guard<mutex> lk( mtx ); v = -1; - cnd.set(true); + cnd.notify_one(); } void Convert::handler1( const stem::Event& ) { + lock_guard<mutex> lk( mtx ); v = 1; - cnd.set(true); + cnd.notify_one(); } void Convert::handler2( const stem::Event_base<mess>& ev ) { + lock_guard<mutex> lk( mtx ); v = ev.value().super_id; m2 = ev.value().message; - cnd.set(true); + cnd.notify_one(); } void Convert::handler3( const mess& m ) { + lock_guard<mutex> lk( mtx ); v = m.super_id; m3 = m.message; - cnd.set(true); + cnd.notify_one(); } -void Convert::wait() +bool Convert::wait() { - cnd.try_wait(); - - cnd.set( false ); + unique_lock<mutex> lk( mtx ); + return cnd.timed_wait( lk, std::tr2::milliseconds( 500 ), v_nz_check ); } DEFINE_RESPONSE_TABLE( Convert ) Modified: trunk/complement/explore/lib/stem/ut/Convert.h =================================================================== --- trunk/complement/explore/lib/stem/ut/Convert.h 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/Convert.h 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <07/07/20 00:03:52 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 19:07:02 yeti> /* * - * Copyright (c) 2007 + * Copyright (c) 2007, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -12,7 +12,8 @@ #ifndef __Convert_h #define __Convert_h -#include <mt/xmt.h> +#include <mt/mutex> +#include <mt/condition_variable> #include <stem/Event.h> #include <stem/EventHandler.h> @@ -53,16 +54,20 @@ void handler2( const stem::Event_base<mess>& ); void handler3( const mess& ); - void wait(); + bool wait(); - int v; + static int v; std::string m2; std::string m3; private: - xmt::condition cnd; + static bool v_nz_check() + { return v != 0; } + std::tr2::mutex mtx; + std::tr2::condition_variable cnd; + DECLARE_RESPONSE_TABLE( Convert, stem::EventHandler ); }; Modified: trunk/complement/explore/lib/stem/ut/Echo.cc =================================================================== --- trunk/complement/explore/lib/stem/ut/Echo.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/Echo.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/29 13:02:34 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 13:16:04 yeti> /* * Copyright (c) 2006, 2007 @@ -14,6 +14,7 @@ #include <stem/EvManager.h> #include <exam/suite.h> +#include <mt/date_time> using namespace stem; @@ -45,7 +46,8 @@ { // cerr << "Echo\n"; manager()->change_announce( ev.src(), ev.value() ); - cnd.set( true ); + + cnd.notify_one(); } DEFINE_RESPONSE_TABLE( StEMecho ) @@ -57,21 +59,18 @@ EventHandler(), mess( "echo string" ) { - cnd.set( false ); } EchoClient::EchoClient( stem::addr_type id ) : EventHandler( id ), mess( "echo string" ) { - cnd.set( false ); } EchoClient::EchoClient( stem::addr_type id, const char *info ) : EventHandler( id, info ), mess( "echo string" ) { - cnd.set( false ); } EchoClient::~EchoClient() @@ -82,12 +81,13 @@ void EchoClient::handler1( const stem::Event& ev ) { EXAM_CHECK_ASYNC( ev.value() == mess ); - cnd.set(true); + + cnd.notify_one(); } -void EchoClient::wait() +bool EchoClient::wait() { - cnd.try_wait(); + return cnd.timed_wait( std::tr2::milliseconds( 500 ) ); } DEFINE_RESPONSE_TABLE( EchoClient ) @@ -98,28 +98,24 @@ EventHandler(), mess( "peer client" ) { - cnd.set( false ); } PeerClient::PeerClient( stem::addr_type id ) : EventHandler( id ), mess( "peer client" ) { - cnd.set( false ); } PeerClient::PeerClient( const char *info ) : EventHandler( info ), mess( info ) { - cnd.set( false ); } PeerClient::PeerClient( stem::addr_type id, const char *info ) : EventHandler( id, info ), mess( info ) { - cnd.set( false ); } PeerClient::~PeerClient() @@ -131,12 +127,12 @@ { EXAM_CHECK_ASYNC( ev.value() == mess ); - cnd.set(true); + cnd.notify_one(); } -void PeerClient::wait() +bool PeerClient::wait() { - cnd.try_wait(); + return cnd.timed_wait( std::tr2::milliseconds( 500 ) ); } DEFINE_RESPONSE_TABLE( PeerClient ) Modified: trunk/complement/explore/lib/stem/ut/Echo.h =================================================================== --- trunk/complement/explore/lib/stem/ut/Echo.h 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/Echo.h 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/07/11 21:45:09 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 13:15:07 yeti> /* - * Copyright (c) 2006, 2007 + * Copyright (c) 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -12,7 +12,7 @@ #define __Echo_h #include <string> -#include <mt/xmt.h> +#include <mt/condition_variable> #include <stem/EventHandler.h> // #include <stem/Names.h> // #include <list> @@ -28,7 +28,7 @@ void echo( const stem::Event& ); void regme( const stem::Event& ); - xmt::condition cnd; + std::tr2::condition_event cnd; private: DECLARE_RESPONSE_TABLE( StEMecho, stem::EventHandler ); @@ -45,12 +45,12 @@ void handler1( const stem::Event& ); - void wait(); + bool wait(); const std::string mess; private: - xmt::condition cnd; + std::tr2::condition_event cnd; DECLARE_RESPONSE_TABLE( EchoClient, stem::EventHandler ); }; @@ -67,12 +67,12 @@ void handler1( const stem::Event& ); - void wait(); + bool wait(); const std::string mess; private: - xmt::condition cnd; + std::tr2::condition_event cnd; DECLARE_RESPONSE_TABLE( PeerClient, stem::EventHandler ); }; Modified: trunk/complement/explore/lib/stem/ut/Makefile =================================================================== --- trunk/complement/explore/lib/stem/ut/Makefile 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/Makefile 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <08/06/12 15:25:10 ptr> +# -*- Makefile -*- Time-stamp: <08/06/30 11:54:35 yeti> SRCROOT := ../../.. @@ -16,25 +16,26 @@ LIBSOCK_DIR = ${CoMT_DIR}/lib/sockios LIBSTEM_DIR = ${CoMT_DIR}/lib/stem LIBEXAM_DIR = ${CoMT_DIR}/lib/exam +LIBMISC_DIR = ${CoMT_DIR}/lib/misc ifeq ($(OSNAME),linux) -release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -Wl,--rpath=./dl/${OUTPUT_DIR}:${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -L${LIBMISC_DIR}/${OUTPUT_DIR} -Wl,--rpath=./dl/${OUTPUT_DIR}:${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBMISC_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=./dl/${OUTPUT_DIR_DBG}:${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBMISC_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} + ifndef WITHOUT_STLPORT -stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=./dl/${OUTPUT_DIR_STLDBG}:${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=./dl/${OUTPUT_DIR_STLDBG}:${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=./dl/${OUTPUT_DIR_DBG}:${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} - endif -release-shared : LDLIBS = -lxmt -lsockios -lstem -lexam -ldl -dbg-shared : LDLIBS = -lxmtg -lsockiosg -lstemg -lexamg -ldl +release-shared : LDLIBS = -lxmt -lsockios -lstem -lexam -lmisc -ldl +dbg-shared : LDLIBS = -lxmtg -lsockiosg -lstemg -lexamg -lmiscg -ldl ifndef WITHOUT_STLPORT -stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lexamstlg -ldl +stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lexamstlg -lmiscstlg -ldl endif # dbg-shared: DEFS += -DDEBUG Modified: trunk/complement/explore/lib/stem/ut/NameService.cc =================================================================== --- trunk/complement/explore/lib/stem/ut/NameService.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/NameService.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <06/11/29 10:50:21 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:47:39 yeti> /* - * Copyright (c) 2006, 2007 + * Copyright (c) 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -15,44 +15,43 @@ #include <stem/EDSEv.h> #include "NameService.h" +#include <mt/date_time> + using namespace std; using namespace stem; -using namespace xmt; +using namespace std::tr2; Naming::Naming() : EventHandler() { - cnd.set( false ); } Naming::Naming( stem::addr_type id ) : EventHandler( id ) { - cnd.set( false ); } Naming::~Naming() { - // cnd.wait(); } void Naming::names_list( const nsrecords_type& nr ) { copy( nr.container.begin(), nr.container.end(), back_insert_iterator<nsrecords_type::container_type>(lst) ); - cnd.set(true); + cnd.notify_one(); } void Naming::names_name( const nsrecords_type& nr ) { copy( nr.container.begin(), nr.container.end(), back_insert_iterator<nsrecords_type::container_type>(lst) ); - cnd.set(true); + cnd.notify_one(); } -void Naming::wait() +bool Naming::wait() { - cnd.try_wait(); + return cnd.timed_wait( std::tr2::milliseconds( 500 ) ); } DEFINE_RESPONSE_TABLE( Naming ) Modified: trunk/complement/explore/lib/stem/ut/NameService.h =================================================================== --- trunk/complement/explore/lib/stem/ut/NameService.h 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/NameService.h 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/07/11 21:47:37 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:45:50 yeti> /* - * Copyright (c) 2006, 2007 + * Copyright (c) 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -11,7 +11,7 @@ #ifndef __NameService_h #define __NameService_h -#include <mt/xmt.h> +#include <mt/condition_variable> #include <stem/EventHandler.h> #include <stem/Names.h> #include <list> @@ -29,14 +29,14 @@ void names_list( const nsrecords_type& ); void names_name( const nsrecords_type& ); - void wait(); + bool wait(); void reset() - { cnd.set( false ); } + { cnd.reset(); } nsrecords_type::container_type lst; private: - xmt::condition cnd; + std::tr2::condition_event cnd; DECLARE_RESPONSE_TABLE( Naming, stem::EventHandler ); }; Modified: trunk/complement/explore/lib/stem/ut/Node.cc =================================================================== --- trunk/complement/explore/lib/stem/ut/Node.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/Node.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <06/09/29 23:23:57 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:41:59 yeti> /* * - * Copyright (c) 2002, 2003, 2006, 2007 + * Copyright (c) 2002, 2003, 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -11,47 +11,47 @@ #include "Node.h" +#include <mt/date_time> + using namespace std; using namespace stem; -using namespace xmt; +using namespace std::tr2; Node::Node() : EventHandler(), v( 0 ) { - cnd.set( false ); } Node::Node( stem::addr_type id ) : EventHandler( id ), v( 0 ) { - cnd.set( false ); } Node::Node( stem::addr_type id, const char *info ) : EventHandler( id, info ), v( 0 ) { - cnd.set( false ); } Node::~Node() { - // cnd.wait(); } void Node::handler1( const stem::Event& ) { + lock_guard<mutex> lk( m ); // std::cerr << "I am here 1\n"; v = 1; - cnd.set(true); + cnd.notify_one(); // std::cerr << "I am here 2\n"; } -void Node::wait() +bool Node::wait() { - cnd.try_wait(); + unique_lock<mutex> lk( m ); + return cnd.timed_wait( lk, std::tr2::milliseconds( 500 ) ); } DEFINE_RESPONSE_TABLE( Node ) @@ -64,32 +64,31 @@ EventHandler(), v( 0 ) { - cnd.set( false ); } NewNode::NewNode( stem::addr_type id ) : EventHandler( id ), v( 0 ) { - cnd.set( false ); } NewNode::~NewNode() { - // cnd.wait(); } void NewNode::handler1( const stem::Event& ) { + lock_guard<mutex> lk( m ); // std::cerr << "I am here 1\n"; v = 1; - cnd.set(true); + cnd.notify_one(); // std::cerr << "I am here 2\n"; } -void NewNode::wait() +bool NewNode::wait() { - cnd.try_wait(); + unique_lock<mutex> lk( m ); + return cnd.timed_wait( lk, std::tr2::milliseconds( 500 ) ); } DEFINE_RESPONSE_TABLE( NewNode ) Modified: trunk/complement/explore/lib/stem/ut/Node.h =================================================================== --- trunk/complement/explore/lib/stem/ut/Node.h 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/Node.h 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <07/07/11 21:47:25 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:54:21 yeti> /* * - * Copyright (c) 2002, 2003, 2006, 2007 + * Copyright (c) 2002, 2003, 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -12,7 +12,8 @@ #ifndef __Node_h #define __Node_h -#include <mt/xmt.h> +#include <mt/mutex> +#include <mt/condition_variable> #include <stem/EventHandler.h> class Node : @@ -26,12 +27,13 @@ void handler1( const stem::Event& ); - void wait(); + bool wait(); int v; private: - xmt::condition cnd; + std::tr2::mutex m; + std::tr2::condition_variable cnd; DECLARE_RESPONSE_TABLE( Node, stem::EventHandler ); }; @@ -47,12 +49,13 @@ void handler1( const stem::Event& ); - void wait(); + bool wait(); int v; private: - xmt::condition cnd; + std::tr2::mutex m; + std::tr2::condition_variable cnd; DECLARE_RESPONSE_TABLE( NewNode, stem::EventHandler ); }; Modified: trunk/complement/explore/lib/stem/ut/NodeDL.h =================================================================== --- trunk/complement/explore/lib/stem/ut/NodeDL.h 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/NodeDL.h 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <07/07/11 21:47:58 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:35:02 yeti> /* * - * Copyright (c) 2002, 2003, 2006, 2007 + * Copyright (c) 2002, 2003, 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -12,7 +12,8 @@ #ifndef __NodeDL_h #define __NodeDL_h -#include <mt/xmt.h> +#include <mt/mutex> +#include <mt/condition_variable> #include <stem/EventHandler.h> class NodeDL : @@ -25,12 +26,13 @@ void handler1( const stem::Event& ); - void wait(); + bool wait(); int v; private: - xmt::condition cnd; + std::tr2::mutex m; + std::tr2::condition_variable cnd; DECLARE_RESPONSE_TABLE( NodeDL, stem::EventHandler ); }; @@ -46,12 +48,13 @@ void handler1( const stem::Event& ); - void wait(); + bool wait(); int v; private: - xmt::condition cnd; + std::tr2::mutex m; + std::tr2::condition_variable cnd; DECLARE_RESPONSE_TABLE( NewNodeDL, stem::EventHandler ); }; @@ -59,7 +62,7 @@ #define NODE_EV2 0x901 extern "C" void *create_NewNodeDL( unsigned ); -extern "C" void wait_NewNodeDL( void * ); +extern "C" int wait_NewNodeDL( void * ); extern "C" int v_NewNodeDL( void * ); extern "C" void destroy_NewNodeDL( void * ); Modified: trunk/complement/explore/lib/stem/ut/dl/loadable_stem.cc =================================================================== --- trunk/complement/explore/lib/stem/ut/dl/loadable_stem.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/dl/loadable_stem.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <06/09/29 22:53:34 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:36:09 yeti> /* * - * Copyright (c) 2002, 2003, 2006, 2007 + * Copyright (c) 2002, 2003, 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -12,19 +12,18 @@ #include "../NodeDL.h" using namespace stem; +using namespace std::tr2; NodeDL::NodeDL() : EventHandler(), v( 0 ) { - cnd.set( false ); } NodeDL::NodeDL( stem::addr_type id ) : EventHandler( id ), v( 0 ) { - cnd.set( false ); } NodeDL::~NodeDL() @@ -33,13 +32,15 @@ void NodeDL::handler1( const stem::Event& ) { + lock_guard<mutex> lk( m ); v = 1; - cnd.set(true); + cnd.notify_one(); } -void NodeDL::wait() +bool NodeDL::wait() { - cnd.try_wait(); + unique_lock<mutex> lk( m ); + return cnd.timed_wait( lk, std::tr2::milliseconds( 500 ) ); } DEFINE_RESPONSE_TABLE( NodeDL ) @@ -52,14 +53,12 @@ EventHandler(), v( 0 ) { - cnd.set( false ); } NewNodeDL::NewNodeDL( stem::addr_type id ) : EventHandler( id ), v( 0 ) { - cnd.set( false ); } NewNodeDL::~NewNodeDL() @@ -68,13 +67,15 @@ void NewNodeDL::handler1( const stem::Event& ) { + lock_guard<mutex> lk( m ); v = 1; - cnd.set(true); + cnd.notify_one(); } -void NewNodeDL::wait() +bool NewNodeDL::wait() { - cnd.try_wait(); + unique_lock<mutex> lk( m ); + return cnd.timed_wait( lk, std::tr2::milliseconds( 500 ) ); } DEFINE_RESPONSE_TABLE( NewNodeDL ) @@ -86,9 +87,9 @@ return (void *)new NewNodeDL( a ); } -void wait_NewNodeDL( void *p ) +int wait_NewNodeDL( void *p ) { - reinterpret_cast<NewNodeDL *>( p )->wait(); + return reinterpret_cast<NewNodeDL *>( p )->wait() ? 1 : 0; } int v_NewNodeDL( void *p ) Modified: trunk/complement/explore/lib/stem/ut/unit_test.cc =================================================================== --- trunk/complement/explore/lib/stem/ut/unit_test.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/unit_test.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 13:14:16 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 19:19:39 yeti> /* * Copyright (c) 2002, 2003, 2006-2008 @@ -41,6 +41,8 @@ #include <signal.h> +#include <misc/opts.h> + using namespace std; using namespace std::tr2; @@ -161,7 +163,7 @@ EXAM_REQUIRE( lh != NULL ); void *(*f)(unsigned); void (*g)(void *); - void (*w)(void *); + int (*w)(void *); int (*v)(void *); *(void **)(&f) = dlsym( lh, "create_NewNodeDL" ); @@ -178,7 +180,7 @@ ev.dest( 2002 ); node->Send( ev ); - w( reinterpret_cast<void *>(node) ); + EXAM_CHECK( w( reinterpret_cast<void *>(node) ) == 1 ); EXAM_CHECK( v(reinterpret_cast<void *>(node)) == 1 ); g( reinterpret_cast<void *>(node) ); @@ -289,7 +291,7 @@ node.Send( ev ); - node.wait(); + EXAM_CHECK( node.wait() ); mgr.close(); mgr.join(); @@ -305,8 +307,8 @@ const char fname[] = "/tmp/stem_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; +xmt::allocator_shm<condition_event_ip,0> shm_cnd; +xmt::allocator_shm<barrier_ip,0> shm_b; stem_test::stem_test() { @@ -314,7 +316,16 @@ seg.allocate( fname, 4*4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0600 ); } catch ( const xmt::shm_bad_alloc& err ) { - EXAM_ERROR_ASYNC( err.what() ); + try { + seg.allocate( fname, 4*4096, 0, 0600 ); + } + catch ( const xmt::shm_bad_alloc& err2 ) { + string s = err.what(); + s += "; "; + s += err2.what(); + EXAM_ERROR_ASYNC( s.c_str() ); + } + // EXAM_ERROR_ASYNC( err.what() ); } } @@ -326,18 +337,17 @@ int EXAM_IMPL(stem_test::echo_net) { - xmt::__condition<true>& fcnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__condition<true>(); - fcnd.set( false ); + condition_event_ip& fcnd = *new ( shm_cnd.allocate( 1 ) ) condition_event_ip(); try { - xmt::fork(); + std::tr2::this_thread::fork(); int eflag = 0; try { stem::NetTransportMgr mgr; - fcnd.try_wait(); + EXAM_CHECK_ASYNC_F( fcnd.timed_wait( std::tr2::milliseconds( 800 ) ), eflag ); stem::addr_type zero = mgr.open( "localhost", 6995 ); @@ -353,7 +363,7 @@ node.Send( ev ); - node.wait(); + EXAM_CHECK_ASYNC_F( node.wait(), eflag ); mgr.close(); mgr.join(); @@ -363,13 +373,13 @@ exit( eflag ); } - catch ( xmt::fork_in_parent& child ) { + catch ( std::tr2::fork_in_parent& child ) { try { connect_processor<stem::NetTransport> srv( 6995 ); StEMecho echo( 0, "echo service"); // <= zero! - fcnd.set( true ); + fcnd.notify_one(); int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); @@ -386,7 +396,7 @@ } } - (&fcnd)->~__condition<true>(); + (&fcnd)->~condition_event_ip(); shm_cnd.deallocate( &fcnd, 1 ); // cerr << "Fine\n"; @@ -399,13 +409,11 @@ int EXAM_IMPL(stem_test::net_echo) { try { - xmt::__barrier<true>& b = *new ( shm_b.allocate( 1 ) ) xmt::__barrier<true>(); - xmt::__condition<true>& c = *new ( shm_cnd.allocate( 1 ) ) xmt::__condition<true>(); + barrier_ip& b = *new ( shm_b.allocate( 1 ) ) barrier_ip(); + condition_event_ip& c = *new ( shm_cnd.allocate( 1 ) ) condition_event_ip(); - c.set( false ); - try { - xmt::fork(); + std::tr2::this_thread::fork(); int eflag = 0; // server part @@ -417,7 +425,7 @@ // echo.manager()->settrs( &std::cerr ); EXAM_CHECK_ASYNC_F( srv.good(), eflag ); - c.set( true ); // ok, server listen + c.notify_one(); // ok, server listen b.wait(); // server may go away @@ -427,14 +435,14 @@ exit( eflag ); } - catch ( xmt::fork_in_parent& child ) { + catch ( std::tr2::fork_in_parent& child ) { // client part stem::NetTransportMgr mgr; // mgr.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch | stem::EvManager::tracefault ); // mgr.manager()->settrs( &std::cerr ); - c.try_wait(); // wait server start + EXAM_CHECK( c.timed_wait( std::tr2::milliseconds( 800 ) ) ); // wait server start stem::addr_type zero = mgr.open( "localhost", 6995 ); @@ -448,7 +456,7 @@ ev.value() = node.mess; node.Send( ev ); - node.wait(); + EXAM_CHECK( node.wait() ); mgr.close(); mgr.join(); @@ -464,9 +472,9 @@ } } - (&c)->~__condition<true>(); + (&c)->~condition_event_ip(); shm_cnd.deallocate( &c, 1 ); - (&b)->~__barrier<true>(); + (&b)->~barrier_ip(); shm_b.deallocate( &b, 1 ); } catch ( xmt::shm_bad_alloc& err ) { @@ -504,18 +512,13 @@ pid_t fpid; - xmt::__condition<true>& fcnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__condition<true>(); - fcnd.set( false ); + condition_event_ip& fcnd = *new ( shm_cnd.allocate( 1 ) ) condition_event_ip(); + condition_event_ip& pcnd = *new ( shm_cnd.allocate( 1 ) ) condition_event_ip(); + condition_event_ip& scnd = *new ( shm_cnd.allocate( 1 ) ) condition_event_ip(); - xmt::__condition<true>& pcnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__condition<true>(); - pcnd.set( false ); - - xmt::__condition<true>& scnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__condition<true>(); - scnd.set( false ); - try { // Client 1 - xmt::fork(); + std::tr2::this_thread::fork(); #if 0 struct sigaction action; struct sigaction old_action; @@ -539,7 +542,7 @@ PeerClient c1( "c1 local" ); // c1 client Naming nm; - fcnd.try_wait(); + EXAM_CHECK_ASYNC_F( fcnd.timed_wait( std::tr2::milliseconds( 800 ) ), eflag ); stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server // It done like it should on client side @@ -568,7 +571,7 @@ evname.dest( c1.manager()->reflect( ga ) ); evname.value() = "c2@here"; - pcnd.try_wait(); + EXAM_CHECK_ASYNC_F( pcnd.timed_wait( std::tr2::milliseconds( 800 ) ), eflag ); Naming::nsrecords_type::const_iterator i; @@ -602,7 +605,7 @@ c1.Send( pe ); } - scnd.try_wait(); + EXAM_CHECK_ASYNC_F( scnd.timed_wait( std::tr2::milliseconds( 800 ) ), eflag ); mgr.close(); mgr.join(); @@ -613,13 +616,13 @@ exit( eflag ); } - catch ( xmt::fork_in_parent& child ) { + catch ( std::tr2::fork_in_parent& child ) { fpid = child.pid(); } try { // Client 2 - xmt::fork(); + std::tr2::this_thread::fork(); #if 0 struct sigaction action; @@ -643,7 +646,7 @@ // ^ PeerClient c2( "c2 local" ); // <<--- name the same as mess expected ... | - fcnd.try_wait(); + EXAM_CHECK_ASYNC_F( fcnd.timed_wait( std::tr2::milliseconds( 800 ) ), eflag ); stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server // It done like it should on client side @@ -657,11 +660,11 @@ ev.value() = "c2@here"; c2.Send( ev ); // 'register' c2 client on 'echo' server - pcnd.set( true ); + pcnd.notify_one(); c2.wait(); // cerr << "Fine!" << endl; - scnd.set( true ); + scnd.notify_one(); mgr.close(); mgr.join(); @@ -672,11 +675,11 @@ exit( eflag ); } - catch ( xmt::fork_in_parent& child ) { + catch ( std::tr2::fork_in_parent& child ) { connect_processor<stem::NetTransport> srv( 6995 ); // server, it serve 'echo' StEMecho echo( 0, "echo service"); // <= zero! 'echo' server, default ('zero' address) - fcnd.set( true, true ); + fcnd.notify_all(); int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); @@ -697,11 +700,11 @@ srv.wait(); } - (&fcnd)->~__condition<true>(); + (&fcnd)->~condition_event_ip(); shm_cnd.deallocate( &fcnd, 1 ); - (&pcnd)->~__condition<true>(); + (&pcnd)->~condition_event_ip(); shm_cnd.deallocate( &pcnd, 1 ); - (&scnd)->~__condition<true>(); + (&scnd)->~condition_event_ip(); shm_cnd.deallocate( &scnd, 1 ); return EXAM_RESULT; @@ -709,17 +712,16 @@ int EXAM_IMPL(stem_test::boring_manager) { - xmt::__condition<true>& fcnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__condition<true>(); - fcnd.set( false ); + condition_event_ip& fcnd = *new ( shm_cnd.allocate( 1 ) ) condition_event_ip(); try { // Client - xmt::fork(); + std::tr2::this_thread::fork(); int eflag = 0; try { - fcnd.try_wait(); + EXAM_CHECK_ASYNC_F( fcnd.timed_wait( std::tr2::milliseconds( 800 ) ), eflag ); for ( int i = 0; i < 10; ++i ) { const int n = 10; @@ -745,11 +747,11 @@ } exit( eflag ); } - catch ( xmt::fork_in_parent& child ) { + catch ( std::tr2::fork_in_parent& child ) { connect_processor<stem::NetTransport> srv( 6995 ); // server, it serve 'echo' StEMecho echo( 0, "echo service"); // <= zero! 'echo' server, default ('zero' address) - fcnd.set( true, true ); + fcnd.notify_all(); int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); @@ -763,7 +765,7 @@ srv.wait(); } - (&fcnd)->~__condition<true>(); + (&fcnd)->~condition_event_ip(); shm_cnd.deallocate( &fcnd, 1 ); return EXAM_RESULT; @@ -784,10 +786,11 @@ conv.Send( ev ); - conv.wait(); - + EXAM_CHECK( conv.wait() ); EXAM_CHECK( conv.v == -1 ); + conv.v = 0; + stem::Event_base<mess> ev1( CONV_EV1 ); ev1.dest( conv.self_id() ); @@ -795,10 +798,11 @@ conv.Send( ev1 ); - conv.wait(); - + EXAM_CHECK( conv.wait() ); EXAM_CHECK( conv.v == 1 ); + conv.v = 0; + stem::Event_base<mess> ev2( CONV_EV2 ); ev2.dest( conv.self_id() ); @@ -806,11 +810,13 @@ conv.Send( ev2 ); - conv.wait(); + EXAM_CHECK( conv.wait() ); EXAM_CHECK( conv.v == 2 ); EXAM_CHECK( conv.m2 == "hello" ); + conv.v = 0; + stem::Event_base<mess> ev3( CONV_EV3 ); ev3.dest( conv.self_id() ); @@ -819,21 +825,17 @@ conv.Send( ev3 ); - conv.wait(); + EXAM_CHECK( conv.wait() ); EXAM_CHECK( conv.v == 3 ); EXAM_CHECK( conv.m3 == ", wold!" ); + conv.v = 0; + return EXAM_RESULT; } -// ----------------- - -// ----------------- - -int EXAM_DECL(stem_test_suite); - -int EXAM_IMPL(stem_test_suite) +int main( int argc, const char** argv ) { exam::test_suite::test_case_type tc[4]; @@ -858,10 +860,52 @@ t.add( &stem_test::convert, test, "convert", tc[0] ); + Opts opts; + + opts.description( "test suite for 'StEM' framework" ); + opts.usage( "[options]" ); + + opts << option<bool>( "print this help message", 'h', "help" ) + << option<bool>( "list all test cases", 'l', "list" ) + << option<string>( "run tests by number", 'r', "run" )["0"] + << option<bool>( "print status of tests within test suite", 'v', "verbose" ) + << option<bool>( "trace checks", 't', "trace" ); + + try { + opts.parse( argc, argv ); + } + catch (...) { + opts.help( cerr ); + return 1; + } + + if ( opts.is_set( 'h' ) ) { + opts.help( cerr ); + return 0; + } + + if ( opts.is_set( 'l' ) ) { + t.print_graph( cerr ); + return 0; + } + + if ( opts.is_set( 'v' ) ) { + t.flags( t.flags() | exam::base_logger::verbose ); + } + + if ( opts.is_set( 't' ) ) { + t.flags( t.flags() | exam::base_logger::trace ); + } + + if ( opts.is_set( 'r' ) ) { + stringstream ss( opts.get<string>( 'r' ) ); + int n; + while ( ss >> n ) { + t.single( n ); + } + + return 0; + } + return t.girdle(); } - -int main( int, char ** ) -{ - return stem_test_suite(0); -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-01 14:41:16
|
Revision: 1934 http://complement.svn.sourceforge.net/complement/?rev=1934&view=rev Author: complement Date: 2008-07-01 07:41:10 -0700 (Tue, 01 Jul 2008) Log Message: ----------- build libmisc Modified Paths: -------------- trunk/complement/explore/lib/Makefile Modified: trunk/complement/explore/lib/Makefile =================================================================== --- trunk/complement/explore/lib/Makefile 2008-06-30 12:51:01 UTC (rev 1933) +++ trunk/complement/explore/lib/Makefile 2008-07-01 14:41:10 UTC (rev 1934) @@ -1,13 +1,13 @@ -# Time-stamp: <07/01/23 14:12:04 ptr> +# Time-stamp: <08/06/30 12:51:10 yeti> # -# Copyright (c) 2006, 2007 +# Copyright (c) 2006-2008 # Petr Ovtchenkov # # Licensed under the Academic Free License version 3.0 # SRCROOT := .. -SUBDIRS := exam mt sockios stem +SUBDIRS := misc exam mt sockios stem include ${SRCROOT}/Makefiles/gmake/subdirs.mak This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-30 12:51:08
|
Revision: 1933 http://complement.svn.sourceforge.net/complement/?rev=1933&view=rev Author: complement Date: 2008-06-30 05:51:01 -0700 (Mon, 30 Jun 2008) Log Message: ----------- Merge branch 'master' of /export/hostel/pub/scm/complement Modified Paths: -------------- trunk/complement/explore/include/mt/shm.h trunk/complement/explore/lib/misc/ut/misc_test.cc trunk/complement/explore/lib/misc/ut/misc_test.h trunk/complement/explore/lib/misc/ut/misc_test_suite.cc trunk/complement/explore/lib/misc/ut/opts_test.cc trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc Modified: trunk/complement/explore/include/mt/shm.h =================================================================== --- trunk/complement/explore/include/mt/shm.h 2008-06-30 12:50:41 UTC (rev 1932) +++ trunk/complement/explore/include/mt/shm.h 2008-06-30 12:51:01 UTC (rev 1933) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/26 10:37:01 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 13:48:26 yeti> /* * Copyright (c) 2006-2008 @@ -106,6 +106,7 @@ __SPEC_FULL(is_ipc_sharable,std::tr2::condition_variable_ip,true); __SPEC_FULL(is_ipc_sharable,std::tr2::condition_variable_any_ip,true); +__SPEC_FULL(is_ipc_sharable,std::tr2::condition_event_ip,true); __SPEC_FULL(is_ipc_sharable,std::tr2::semaphore_ip,true); __SPEC_FULL(is_ipc_sharable,std::tr2::barrier_ip,true); __SPEC_FULL(is_ipc_sharable,std::tr2::mutex_ip,true); Modified: trunk/complement/explore/lib/misc/ut/misc_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test.cc 2008-06-30 12:50:41 UTC (rev 1932) +++ trunk/complement/explore/lib/misc/ut/misc_test.cc 2008-06-30 12:51:01 UTC (rev 1933) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/12/02 20:37:29 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 12:39:37 yeti> /* * Copyright (c) 2007 @@ -512,8 +512,6 @@ { EXAM_CHECK( std::tr1::is_pod<const int>::value == true ); EXAM_CHECK( std::tr1::is_pod<int *>::value == true ); - EXAM_CHECK( std::tr1::is_pod<NT>::value == true ); - EXAM_CHECK( std::tr1::is_pod<POD>::value == true ); EXAM_CHECK( std::tr1::is_pod<SL>::value == false ); EXAM_CHECK( std::tr1::is_pod<N>::value == false ); @@ -522,6 +520,18 @@ return EXAM_RESULT; } +int EXAM_IMPL(misc_test::type_traits_is_pod_compiler_supp) +{ +#if defined(__GNUC__) && ((__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 3)) ) + throw exam::skip_exception(); +#endif + + EXAM_CHECK( std::tr1::is_pod<NT>::value == true ); + EXAM_CHECK( std::tr1::is_pod<POD>::value == true ); + + return EXAM_RESULT; +} + class empty { }; Modified: trunk/complement/explore/lib/misc/ut/misc_test.h =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test.h 2008-06-30 12:50:41 UTC (rev 1932) +++ trunk/complement/explore/lib/misc/ut/misc_test.h 2008-06-30 12:51:01 UTC (rev 1933) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/12/02 18:50:20 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 12:40:05 yeti> /* * Copyright (c) 2007 @@ -50,6 +50,7 @@ int EXAM_DECL(type_traits_is_trivial); int EXAM_DECL(type_traits_is_standard_layout); int EXAM_DECL(type_traits_is_pod); + int EXAM_DECL(type_traits_is_pod_compiler_supp); int EXAM_DECL(type_traits_is_empty); }; Modified: trunk/complement/explore/lib/misc/ut/misc_test_suite.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-06-30 12:50:41 UTC (rev 1932) +++ trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-06-30 12:51:01 UTC (rev 1933) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/30 01:37:00 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 12:42:03 yeti> /* * Copyright (c) 2007, 2008 @@ -52,7 +52,8 @@ t.add( &misc_test::type_traits_is_volatile, test, "is_volatile", tc[0] ); // t.add( &misc_test::type_traits_is_trivial, test, "is_trivial", tc[0] ); // t.add( &misc_test::type_traits_is_standard_layout, test, "is_standard_layout", tc[0] ); - t.add( &misc_test::type_traits_is_pod, test, "is_pod", tc[0] ); + tc[4] = t.add( &misc_test::type_traits_is_pod, test, "is_pod", tc[0] ); + t.add( &misc_test::type_traits_is_pod_compiler_supp, test, "is_pod_compiler_supp", tc[4] ); t.add( &misc_test::type_traits_is_empty, test, "is_empty", tc[0] ); return t.girdle(); Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-30 12:50:41 UTC (rev 1932) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-30 12:51:01 UTC (rev 1933) @@ -324,6 +324,8 @@ opts << option<string>( "run tests by number", 'r', "run" )["0"]; + opts.parse( argc, argv ); + EXAM_CHECK( opts.is_set( 'r' ) ); EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); } @@ -336,6 +338,8 @@ opts << option<string>( "run tests by number", 'r', "run" )["20"]; + opts.parse( argc, argv ); + EXAM_CHECK( opts.is_set( 'r' ) == false ); // not set EXAM_CHECK( opts.get<string>( 'r' ) == "20" ); // but has default value } @@ -348,6 +352,8 @@ opts << option<string>( "run tests by number", 'r', "run" ); + opts.parse( argc, argv ); + EXAM_CHECK( opts.is_set( 'r' ) ); EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); } Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-06-30 12:50:41 UTC (rev 1932) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-06-30 12:51:01 UTC (rev 1933) @@ -1,3 +1,9 @@ +2008-06-30 Petr Ovtchenkov <ye...@ya...> + + * shm.h: condition_event_ip may be used in shared memory; + + * libxmt: bump revision to 2.0.4. + 2008-06-06 Petr Ovtchenkov <pt...@is...> * uid.h, uid.cc: functions for generating UIDs; Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2008-06-30 12:50:41 UTC (rev 1932) +++ trunk/complement/explore/lib/mt/Makefile.inc 2008-06-30 12:51:01 UTC (rev 1933) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <08/06/06 21:25:42 yeti> +# -*- Makefile -*- Time-stamp: <08/06/30 13:51:45 yeti> LIBNAME = xmt MAJOR = 2 MINOR = 0 -PATCH = 3 +PATCH = 4 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc callstack.cc system_error.cc thread.cc \ date_time.cc SRC_C = fl.c This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-30 12:50:46
|
Revision: 1932 http://complement.svn.sourceforge.net/complement/?rev=1932&view=rev Author: complement Date: 2008-06-30 05:50:41 -0700 (Mon, 30 Jun 2008) Log Message: ----------- Revert "fix opts/ut" This reverts commit bd109078f223aecfa6cf41029a50ed33f8e3c2eb. Modified Paths: -------------- trunk/complement/explore/lib/misc/ut/opts_test.cc trunk/complement/explore/lib/mt/ut/Makefile Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-30 12:31:55 UTC (rev 1931) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-30 12:50:41 UTC (rev 1932) @@ -292,7 +292,6 @@ return EXAM_RESULT; } - int EXAM_IMPL(opts_test::defaults) { { @@ -325,18 +324,8 @@ opts << option<string>( "run tests by number", 'r', "run" )["0"]; - try { - opts.parse( argc , argv ); - - EXAM_CHECK( opts.is_set( 'r' ) ); - EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); - } - catch( const Opts::unknown_option& e) { - } - catch( const Opts::arg_typemismatch&e ) { - } - catch( ... ) { - } + EXAM_CHECK( opts.is_set( 'r' ) ); + EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); } { @@ -351,6 +340,18 @@ EXAM_CHECK( opts.get<string>( 'r' ) == "20" ); // but has default value } + { + const char* argv[] = { "name", "-r", "10" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts << option<string>( "run tests by number", 'r', "run" ); + + EXAM_CHECK( opts.is_set( 'r' ) ); + EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); + } + return EXAM_RESULT; } Modified: trunk/complement/explore/lib/mt/ut/Makefile =================================================================== --- trunk/complement/explore/lib/mt/ut/Makefile 2008-06-30 12:31:55 UTC (rev 1931) +++ trunk/complement/explore/lib/mt/ut/Makefile 2008-06-30 12:50:41 UTC (rev 1932) @@ -49,7 +49,7 @@ endif -release-shared : LDLIBS = -lxmt -lexam -lboost_filesystem +release-shared : LDLIBS = -lxmt -lexam -lboost_fs dbg-shared : LDLIBS = -lxmtg -lexamg -lboost_fsg ifndef WITHOUT_STLPORT stldbg-shared : LDLIBS = -lxmtstlg -lexamstlg -lboost_fsstlg This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Dmi...@us...> - 2008-06-30 12:31:57
|
Revision: 1931 http://complement.svn.sourceforge.net/complement/?rev=1931&view=rev Author: DmitryOsmakov Date: 2008-06-30 05:31:55 -0700 (Mon, 30 Jun 2008) Log Message: ----------- fix opts/ut Modified Paths: -------------- trunk/complement/explore/lib/misc/ut/opts_test.cc trunk/complement/explore/lib/mt/ut/Makefile Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-30 06:40:02 UTC (rev 1930) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-30 12:31:55 UTC (rev 1931) @@ -292,6 +292,7 @@ return EXAM_RESULT; } + int EXAM_IMPL(opts_test::defaults) { { @@ -324,8 +325,18 @@ opts << option<string>( "run tests by number", 'r', "run" )["0"]; - EXAM_CHECK( opts.is_set( 'r' ) ); - EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); + try { + opts.parse( argc , argv ); + + EXAM_CHECK( opts.is_set( 'r' ) ); + EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); + } + catch( const Opts::unknown_option& e) { + } + catch( const Opts::arg_typemismatch&e ) { + } + catch( ... ) { + } } { @@ -340,18 +351,6 @@ EXAM_CHECK( opts.get<string>( 'r' ) == "20" ); // but has default value } - { - const char* argv[] = { "name", "-r", "10" }; - int argc = sizeof( argv ) / sizeof(argv[0]); - - Opts opts; - - opts << option<string>( "run tests by number", 'r', "run" ); - - EXAM_CHECK( opts.is_set( 'r' ) ); - EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); - } - return EXAM_RESULT; } Modified: trunk/complement/explore/lib/mt/ut/Makefile =================================================================== --- trunk/complement/explore/lib/mt/ut/Makefile 2008-06-30 06:40:02 UTC (rev 1930) +++ trunk/complement/explore/lib/mt/ut/Makefile 2008-06-30 12:31:55 UTC (rev 1931) @@ -49,7 +49,7 @@ endif -release-shared : LDLIBS = -lxmt -lexam -lboost_fs +release-shared : LDLIBS = -lxmt -lexam -lboost_filesystem dbg-shared : LDLIBS = -lxmtg -lexamg -lboost_fsg ifndef WITHOUT_STLPORT stldbg-shared : LDLIBS = -lxmtstlg -lexamstlg -lboost_fsstlg This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-30 06:40:05
|
Revision: 1930 http://complement.svn.sourceforge.net/complement/?rev=1930&view=rev Author: complement Date: 2008-06-29 23:40:02 -0700 (Sun, 29 Jun 2008) Log Message: ----------- Merge branch 'master' of /export/hostel/pub/scm/complement Conflicts: complement/explore/include/misc/opts.h complement/explore/lib/misc/ChangeLog complement/explore/lib/misc/Makefile.inc complement/explore/lib/misc/ut/opts_test.cc Modified Paths: -------------- trunk/complement/explore/lib/misc/ut/opts_test.cc Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-30 06:28:32 UTC (rev 1929) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-30 06:40:02 UTC (rev 1930) @@ -842,4 +842,3 @@ return EXAM_RESULT; } - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-30 06:28:37
|
Revision: 1929 http://complement.svn.sourceforge.net/complement/?rev=1929&view=rev Author: complement Date: 2008-06-29 23:28:32 -0700 (Sun, 29 Jun 2008) Log Message: ----------- libmisc 1.10.1; free allocated objects. add tests for is_set with/without default value, that not pass (unexpected behaviour) Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/ChangeLog trunk/complement/explore/lib/misc/Makefile.inc trunk/complement/explore/lib/misc/ut/opts_test.cc Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-06-29 21:48:33 UTC (rev 1928) +++ trunk/complement/explore/include/misc/opts.h 2008-06-30 06:28:32 UTC (rev 1929) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/29 22:16:12 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 10:00:22 ptr> /* * Copyright (c) 2008 @@ -110,6 +110,9 @@ { return *__x == __y; } }; +inline void option_base_destroyer( option_base* p ) +{ delete p; } + } // namespace detail template <class T> @@ -361,6 +364,9 @@ Opts() { } + ~Opts() + { std::for_each( storage.begin(), storage.end(), detail::option_base_destroyer ); } + void description( const char* text ) { _brief = text; } Modified: trunk/complement/explore/lib/misc/ChangeLog =================================================================== --- trunk/complement/explore/lib/misc/ChangeLog 2008-06-29 21:48:33 UTC (rev 1928) +++ trunk/complement/explore/lib/misc/ChangeLog 2008-06-30 06:28:32 UTC (rev 1929) @@ -1,5 +1,9 @@ 2008-06-30 Petr Ovtchenkov <pt...@is...> + * opts.h: free allocated objects; + + * libmisc: version 1.10.1. + * opts.h, opts.cc: revision of options framework; insert object with type and type check into option; default value passed via [] operator; Modified: trunk/complement/explore/lib/misc/Makefile.inc =================================================================== --- trunk/complement/explore/lib/misc/Makefile.inc 2008-06-29 21:48:33 UTC (rev 1928) +++ trunk/complement/explore/lib/misc/Makefile.inc 2008-06-30 06:28:32 UTC (rev 1929) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <08/06/30 01:39:17 ptr> +# -*- Makefile -*- Time-stamp: <08/06/30 10:25:33 ptr> # I have only one reason while I should use "C++" variant of MD5 instead of "C": # names like MD5Init is wide distributed, but some cool programmers use this @@ -10,6 +10,6 @@ LIBNAME = misc MAJOR = 1 MINOR = 10 -PATCH = 0 +PATCH = 1 SRC_CC = CyrMoney.cc args.cc arguments.cc opts.cc SRC_C = md5.c Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-29 21:48:33 UTC (rev 1928) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-30 06:28:32 UTC (rev 1929) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/30 01:10:34 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 10:08:01 ptr> /* * Copyright (c) 2008 @@ -294,26 +294,63 @@ int EXAM_IMPL(opts_test::defaults) { - const char* argv[] = { "name" }; - int argc = sizeof( argv ) / sizeof(argv[0]); + { + const char* argv[] = { "name" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts << option<int>( "listen tcp port", 'p', "port" )[0]; + opts << option<int>( "listen tcp port", 'p', "port" )[0]; - try { - opts.parse( argc, argv ); + try { + opts.parse( argc, argv ); + EXAM_CHECK( !opts.is_set( 'p' ) ); + EXAM_CHECK( opts.get<int>( 'p' ) == 0 ); + } + catch ( const Opts::unknown_option& e ) { + } + catch ( const Opts::arg_typemismatch& e ) { + } + catch ( ... ) { + } + } - EXAM_CHECK( !opts.is_set( 'p' ) ); - EXAM_CHECK( opts.get<int>( 'p' ) == 0 ); + { + const char* argv[] = { "name", "-r", "10" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts << option<string>( "run tests by number", 'r', "run" )["0"]; + + EXAM_CHECK( opts.is_set( 'r' ) ); + EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); } - catch ( const Opts::unknown_option& e ) { + + { + const char* argv[] = { "name" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts << option<string>( "run tests by number", 'r', "run" )["20"]; + + EXAM_CHECK( opts.is_set( 'r' ) == false ); // not set + EXAM_CHECK( opts.get<string>( 'r' ) == "20" ); // but has default value } - catch ( const Opts::arg_typemismatch& e ) { + + { + const char* argv[] = { "name", "-r", "10" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts << option<string>( "run tests by number", 'r', "run" ); + + EXAM_CHECK( opts.is_set( 'r' ) ); + EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); } - catch ( ... ) { - } return EXAM_RESULT; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |