[complement-svn] SF.net SVN: complement: [1457] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-12-15 08:11:13
|
Revision: 1457 http://svn.sourceforge.net/complement/?rev=1457&view=rev Author: complement Date: 2006-12-15 00:11:12 -0800 (Fri, 15 Dec 2006) Log Message: ----------- add timespec in xmt namespace, useful for conversions and inline objects; clean some code in timespec operations. changes related to timespec in xmt namespace and in global namespace; now 'delay' functions family only in xmt namespace and go away from Thread class. Modified Paths: -------------- trunk/complement/explore/include/mt/time.h trunk/complement/explore/include/mt/xmt.h trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/stem/Cron.h trunk/complement/explore/inquiry/makes/static-lib/Makefile trunk/complement/explore/lib/DB/PgSQL/PgSQL.cc trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/time.cc trunk/complement/explore/lib/mt/xmt.cc trunk/complement/explore/lib/stem/Cron.cc trunk/complement/explore/test/mt/flck.cc trunk/complement/explore/test/mt/lfs.cc trunk/complement/explore/test/mt/mutex_test.cc trunk/complement/explore/test/mt/recursive_mutex.cc trunk/complement/explore/test/mt/signal-1.cc trunk/complement/explore/test/mt/signal-2.cc trunk/complement/explore/test/mt/spinlock_test.cc trunk/complement/explore/test/sockios/client-wc.cc trunk/complement/explore/test/sockios/read0_on_exec.cc Modified: trunk/complement/explore/include/mt/time.h =================================================================== --- trunk/complement/explore/include/mt/time.h 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/include/mt/time.h 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/24 09:28:28 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 10:21:37 ptr> /* * Copyright (c) 2002, 2006 @@ -51,32 +51,95 @@ std::string calendar_time( time_t t ); -timespec operator +( const timespec& a, const timespec& b ); -timespec operator -( const timespec& a, const timespec& b ); -timespec operator /( const timespec& a, unsigned b ); -timespec operator /( const timespec& a, unsigned long b ); +::timespec operator +( const ::timespec& a, const ::timespec& b ); +::timespec operator -( const ::timespec& a, const ::timespec& b ); +::timespec operator /( const ::timespec& a, unsigned b ); +::timespec operator /( const ::timespec& a, unsigned long b ); +::timespec operator *( const ::timespec& a, unsigned b ); +::timespec operator *( const ::timespec& a, unsigned long b ); +inline ::timespec operator *( unsigned b, const ::timespec& a ) +{ return a * b; } +inline ::timespec operator *( unsigned long b, const ::timespec& a ) +{ return a * b; } // timespec& operator =( timespec& a, const timespec& b ); -timespec& operator +=( timespec& a, const timespec& b ); -timespec& operator -=( timespec& a, const timespec& b ); -timespec& operator /=( timespec& a, unsigned b ); -timespec& operator /=( timespec& a, unsigned long b ); +::timespec& operator +=( ::timespec& a, const ::timespec& b ); +::timespec& operator -=( ::timespec& a, const ::timespec& b ); +::timespec& operator /=( ::timespec& a, unsigned b ); +::timespec& operator /=( ::timespec& a, unsigned long b ); +::timespec& operator *=( ::timespec& a, unsigned b ); +::timespec& operator *=( ::timespec& a, unsigned long b ); -bool operator >( const timespec& a, const timespec& b ); -bool operator >=( const timespec& a, const timespec& b ); -bool operator <( const timespec& a, const timespec& b ); -bool operator <=( const timespec& a, const timespec& b ); -bool operator ==( const timespec& a, const timespec& b ); -bool operator !=( const timespec& a, const timespec& b ); +bool operator >( const ::timespec& a, const ::timespec& b ); +bool operator >=( const ::timespec& a, const ::timespec& b ); +bool operator <( const ::timespec& a, const ::timespec& b ); +bool operator <=( const ::timespec& a, const ::timespec& b ); +bool operator ==( const ::timespec& a, const ::timespec& b ); +bool operator !=( const ::timespec& a, const ::timespec& b ); namespace xmt { +struct timespec : + public ::timespec +{ + timespec() + { tv_sec = 0; tv_nsec = 0; } + + timespec( time_t s, long ns ) + { tv_sec = s; tv_nsec = ns; } + + timespec( time_t s ) + { tv_sec = s; tv_nsec = 0; } + + timespec( const timespec& t ) + { tv_sec = t.tv_sec; tv_nsec = t.tv_nsec; } + + timespec( const ::timespec& t ) + { tv_sec = t.tv_sec; tv_nsec = t.tv_nsec; } + + timespec& operator =( const timespec& t ) + { tv_sec = t.tv_sec; tv_nsec = t.tv_nsec; return *this; } + + timespec& operator =( const ::timespec& t ) + { tv_sec = t.tv_sec; tv_nsec = t.tv_nsec; return *this; } + + timespec& operator =( time_t t ) + { tv_sec = t; tv_nsec = 0; return *this; } + + operator ::timespec() const + { return *this; } + + operator const ::timespec&() const + { return *this; } + + operator ::timespec&() + { return *this; } + + operator time_t() const + { return tv_sec; } + + operator double() const + { return tv_nsec == 0 ? static_cast<double>(tv_sec) : tv_sec + 1.0e-9 * tv_nsec; } +}; + // delay execution at least on time interval t -__FIT_DECLSPEC void delay( timespec *interval, timespec *remain ); +__FIT_DECLSPEC void delay( const ::timespec& interval, ::timespec& remain ); +__FIT_DECLSPEC void delay( const ::timespec& interval ); +inline void delay( const ::timespec *interval, ::timespec *remain ) +{ delay( *interval, *remain ); } +inline void delay( const ::timespec *interval ) +{ delay( *interval ); } // sleep at least up to time t -__FIT_DECLSPEC void sleep( timespec *abstime, timespec *real_time ); +__FIT_DECLSPEC void sleep( const ::timespec& abstime, ::timespec& real_time ); +__FIT_DECLSPEC void sleep( const ::timespec& abstime ); +inline void sleep( const ::timespec *abstime, ::timespec *real_time ) +{ sleep( *abstime, *real_time ); } +inline void sleep( const ::timespec *abstime ) +{ sleep( *abstime ); } // get precise time -__FIT_DECLSPEC void gettime( timespec *t ); +__FIT_DECLSPEC void gettime( ::timespec& t ); +inline void gettime( ::timespec *t ) +{ gettime( *t ); } } // namespace xmt Modified: trunk/complement/explore/include/mt/xmt.h =================================================================== --- trunk/complement/explore/include/mt/xmt.h 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/include/mt/xmt.h 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/14 17:08:37 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 03:03:00 ptr> /* * Copyright (c) 1997-1999, 2002-2006 @@ -1203,11 +1203,22 @@ #endif } - int wait_time( const timespec *abstime ); - int wait_delay( const timespec *abstime ); - int try_wait_time( const timespec *abstime ); - int try_wait_delay( const timespec *abstime ); + int wait_time( const ::timespec *abstime ); + int wait_time( const ::timespec& abstime ) + { return wait_time( &abstime ); } + int wait_delay( const ::timespec *abstime ); + int wait_delay( const ::timespec& abstime ) + { return wait_time( &abstime ); } + + int try_wait_time( const ::timespec *abstime ); + int try_wait_time( const ::timespec& abstime ) + { return try_wait_time( &abstime ); } + + int try_wait_delay( const ::timespec *abstime ); + int try_wait_delay( const ::timespec& abstime ) + { return try_wait_delay( &abstime ); } + int signal( bool _broadcast = false ) { __Locker<__Mutex<false,SCOPE> > _x1( _lock ); @@ -1310,8 +1321,12 @@ #endif } - __FIT_DECLSPEC int wait_time( const timespec *t ); // wait for time t, or signal - __FIT_DECLSPEC int wait_delay( const timespec *t ); // wait, timeout is delay t, or signal + __FIT_DECLSPEC int wait_time( const ::timespec *t ); // wait for time t, or signal + int wait_time( const ::timespec& t ) + { return wait_time( &t ); } + __FIT_DECLSPEC int wait_delay( const ::timespec *t ); // wait, timeout is delay t, or signal + int wait_delay( const ::timespec& t ) + { return wait_delay( &t ); } int try_wait() { @@ -1385,6 +1400,9 @@ __FIT_DECLSPEC void fork() throw( fork_in_parent, std::runtime_error ); __FIT_DECLSPEC void become_daemon() throw( fork_in_parent, std::runtime_error ); +__FIT_DECLSPEC void block_signal( int sig ); +__FIT_DECLSPEC void unblock_signal( int sig ); +__FIT_DECLSPEC void signal_handler( int sig, SIG_PF ); class Thread { @@ -1474,21 +1492,8 @@ #ifdef __FIT_UITHREADS static __FIT_DECLSPEC int join_all(); #endif - static __FIT_DECLSPEC void block_signal( int sig ); - static __FIT_DECLSPEC void unblock_signal( int sig ); - static __FIT_DECLSPEC void signal_handler( int sig, SIG_PF ); static __FIT_DECLSPEC void signal_exit( int sig ); // signal handler - // sleep at least up to time t - static void sleep( timespec *t, timespec *e = 0 ) - { xmt::sleep( t, e ); } - // delay execution at least on time interval t - static void delay( timespec *t, timespec *e = 0 ) - { xmt::delay( t, e ); } - // get precise time - static void gettime( timespec *t ) - { xmt::gettime( t ); } - bool good() const { return (_state == goodbit) && (_id != bad_thread_id); } bool bad() const @@ -1581,7 +1586,7 @@ }; template <bool SCOPE> -int __Condition<SCOPE>::try_wait_time( const timespec *abstime ) +int __Condition<SCOPE>::try_wait_time( const ::timespec *abstime ) { #if defined(__FIT_WIN32THREADS) || defined(__FIT_NOVELL_THREADS) MT_LOCK( _lock ); @@ -1607,16 +1612,15 @@ #endif #if defined(__FIT_UITHREADS) || defined(_PTHREADS) int ret = 0; - timespec _abstime = *abstime; while ( !_val ) { # ifdef _PTHREADS - ret = pthread_cond_timedwait( &_cond, &_lock._M_lock, &_abstime ); + ret = pthread_cond_timedwait( &_cond, &_lock._M_lock, abstime ); if ( ret == ETIMEDOUT ) { break; } # endif # ifdef __FIT_UITHREADS - ret = cond_timedwait( &_cond, /* &_lock.mutex */ &_lock._M_lock, &_abstime ); + ret = cond_timedwait( &_cond, /* &_lock.mutex */ &_lock._M_lock, abstime ); if ( ret == ETIME ) { ret = ETIMEDOUT; } else if ( ret == ETIMEDOUT ) { @@ -1644,7 +1648,7 @@ } template <bool SCOPE> -int __Condition<SCOPE>::try_wait_delay( const timespec *interval ) +int __Condition<SCOPE>::try_wait_delay( const ::timespec *interval ) { #if defined(__FIT_WIN32THREADS) || defined(__FIT_NOVELL_THREADS) MT_LOCK( _lock ); @@ -1669,21 +1673,20 @@ return 0; #endif #if defined(__FIT_UITHREADS) || defined(_PTHREADS) - timespec ct; + ::timespec ct; xmt::gettime( &ct ); ct += *interval; int ret = 0; - timespec _abstime = ct; while ( !_val ) { # ifdef _PTHREADS - ret = pthread_cond_timedwait( &_cond, &_lock._M_lock, &_abstime ); + ret = pthread_cond_timedwait( &_cond, &_lock._M_lock, &ct ); if ( ret == ETIMEDOUT ) { break; } # endif # ifdef __FIT_UITHREADS - ret = cond_timedwait( &_cond, /* &_lock.mutex */ &_lock._M_lock, &_abstime ); + ret = cond_timedwait( &_cond, /* &_lock.mutex */ &_lock._M_lock, &ct ); if ( ret == ETIME ) { ret = ETIMEDOUT; } else if ( ret == ETIMEDOUT ) { @@ -1711,7 +1714,7 @@ } template <bool SCOPE> -int __Condition<SCOPE>::wait_time( const timespec *abstime ) +int __Condition<SCOPE>::wait_time( const ::timespec *abstime ) { #ifdef __FIT_WIN32THREADS MT_LOCK( _lock ); @@ -1733,8 +1736,7 @@ #ifdef _PTHREADS MT_REENTRANT( _lock, _x1 ); // ?? _val = false; - timespec _abstime = *abstime; - int ret = pthread_cond_timedwait( &_cond, &_lock._M_lock, &_abstime ); + int ret = pthread_cond_timedwait( &_cond, &_lock._M_lock, abstime ); if ( ret == ETIMEDOUT ) { _val = true; } @@ -1744,9 +1746,8 @@ MT_REENTRANT( _lock, _x1 ); _val = false; int ret; - timespec _abstime = *abstime; while ( !_val ) { - ret = cond_timedwait( &_cond, /* &_lock.mutex */ &_lock._M_lock, &_abstime ); + ret = cond_timedwait( &_cond, /* &_lock.mutex */ &_lock._M_lock, abstime ); if ( ret == ETIME ) { _val = true; ret = ETIMEDOUT; @@ -1771,7 +1772,7 @@ } template <bool SCOPE> -int __Condition<SCOPE>::wait_delay( const timespec *interval ) +int __Condition<SCOPE>::wait_delay( const ::timespec *interval ) { #ifdef __FIT_WIN32THREADS MT_LOCK( _lock ); @@ -1790,7 +1791,7 @@ return 0; #endif #if defined(__FIT_UITHREADS) || defined(_PTHREADS) - timespec ct; + ::timespec ct; xmt::gettime( &ct ); ct += *interval; Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/13 18:07:06 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 01:27:36 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -397,7 +397,7 @@ c = me->_conn_pool.front(); me->_conn_pool.pop_front(); _non_empty = true; - xmt::Thread::gettime( &me->_tpop ); + xmt::gettime( &me->_tpop ); } me->_dlock.unlock(); @@ -434,7 +434,7 @@ c = me->_conn_pool.front(); me->_conn_pool.pop_front(); _non_empty = true; - xmt::Thread::gettime( &me->_tpop ); + xmt::gettime( &me->_tpop ); break; } me->_pool_cnd.set( false ); @@ -485,14 +485,14 @@ // queue not empty and not decrease me->mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); } else { - xmt::Thread::gettime( &now ); + xmt::gettime( &now ); if ( (tpop + delta) < now ) { // a long time was since last pop from queue me->mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); } } } - xmt::Thread::delay( &alarm ); + xmt::delay( &alarm ); } else { if ( me->_observer_cnd.try_wait_delay( &idle ) != 0 ) { MT_REENTRANT( me->_orlock, _1 ); Modified: trunk/complement/explore/include/stem/Cron.h =================================================================== --- trunk/complement/explore/include/stem/Cron.h 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/include/stem/Cron.h 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/08/04 00:02:55 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 03:20:55 ptr> /* * Copyright (c) 1998, 2002, 2003, 2005 @@ -7,16 +7,8 @@ * Copyright (c) 1999-2001 * ParallelGraphics Ltd. * - * Licensed under the Academic Free License version 2.1 + * Licensed under the Academic Free License version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ #ifndef __stem_Cron_h @@ -40,6 +32,7 @@ #include <ctime> #include <mt/xmt.h> +#include <mt/time.h> #include <queue> @@ -58,8 +51,8 @@ n( static_cast<unsigned>(infinite) ), arg( 0 ) { - start.tv_sec = immediate; start.tv_nsec = 0; - period.tv_sec = 0; period.tv_nsec = 0; + start = immediate; + period = 0; } CronEntry( const CronEntry& x ) : @@ -67,15 +60,15 @@ n( x.n ), arg( x.arg ) { - start.tv_sec = x.start.tv_sec; start.tv_nsec = x.start.tv_nsec; - period.tv_sec = x.period.tv_sec; period.tv_nsec = x.period.tv_nsec; + start = x.start; + period = x.period; } code_type code; // time_t start; - timespec start; + xmt::timespec start; // time_t end; - timespec period; + xmt::timespec period; uint32_t n; uint32_t arg; @@ -94,9 +87,9 @@ count( 0 ), arg( 0 ) { - expired.tv_sec = 0; expired.tv_nsec = 0; - start.tv_sec = 0; start.tv_nsec = 0; - period.tv_sec = 0; period.tv_nsec = 0; + expired = 0; + start = 0; + period = 0; } __CronEntry( const __CronEntry& x ) : @@ -106,55 +99,40 @@ count( x.count ), arg( x.arg ) { - expired.tv_sec = x.expired.tv_sec; expired.tv_nsec = x.expired.tv_nsec; - start.tv_sec = x.start.tv_sec; start.tv_nsec = x.start.tv_nsec; - period.tv_sec = x.period.tv_sec; period.tv_nsec = x.period.tv_nsec; + expired = x.expired; + start = x.start; + period = x.period; } - timespec expired; + xmt::timespec expired; code_type code; addr_type addr; - timespec start; - timespec period; + xmt::timespec start; + xmt::timespec period; unsigned n; unsigned count; unsigned arg; - -#if 0 - operator <( const __CronEntry& __x ) const - { return expired.tv_sec < __x.expired.tv_sec ? true : - expired.tv_sec > __x.expired.tv_sec ? false : - expired.tv_nsec < __x.expired.tv_nsec; } - operator >( const __CronEntry& __x ) const - { return expired.tv_sec > __x.expired.tv_sec ? true : - expired.tv_sec < __x.expired.tv_sec ? false : - expired.tv_nsec > __x.expired.tv_nsec; } - operator ==( const __CronEntry& __x ) const - { return expired.tv_sec == __x.expired.tv_sec && - expired.tv_nsec == __x.expired.tv_nsec; } -#endif }; inline bool operator <( const __CronEntry& __l, const __CronEntry& __r ) -{ return __l.expired.tv_sec < __r.expired.tv_sec ? true : - __l.expired.tv_sec > __r.expired.tv_sec ? false : - __l.expired.tv_nsec < __r.expired.tv_nsec; } +{ return __l.expired < __r.expired; } inline bool operator >( const __CronEntry& __l, const __CronEntry& __r ) -{ return __l.expired.tv_sec > __r.expired.tv_sec ? true : - __l.expired.tv_sec < __r.expired.tv_sec ? false : - __l.expired.tv_nsec > __r.expired.tv_nsec; } +{ return __l.expired > __r.expired; } inline bool operator ==( const __CronEntry& __l, const __CronEntry& __r ) -{ return __l.expired.tv_sec == __r.expired.tv_sec && - __l.expired.tv_nsec == __r.expired.tv_nsec; } +{ return __l.expired == __r.expired; } +inline +bool operator !=( const __CronEntry& __l, const __CronEntry& __r ) +{ return __l.expired != __r.expired; } + class Cron : public EventHandler { Modified: trunk/complement/explore/inquiry/makes/static-lib/Makefile =================================================================== --- trunk/complement/explore/inquiry/makes/static-lib/Makefile 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/inquiry/makes/static-lib/Makefile 2006-12-15 08:11:12 UTC (rev 1457) @@ -6,11 +6,15 @@ include Makefile.inc include ${SRCROOT}/Makefiles/top.mak +PHONY += qq # $(foreach ${LIBNAMES}) +qq: testx2 +testx2: DEFS += -Dtestx2 + define P_TEMPLATE $(1): $$($(1)_SRC_CPP) - echo "$$+ $$@ " + echo "$$+ $$@ $${DEFS}" endef $(foreach name,${LIBNAMES},$(eval $(call P_TEMPLATE,$(name)))) Modified: trunk/complement/explore/lib/DB/PgSQL/PgSQL.cc =================================================================== --- trunk/complement/explore/lib/DB/PgSQL/PgSQL.cc 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/lib/DB/PgSQL/PgSQL.cc 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,21 +1,14 @@ -// -*- C++ -*- Time-stamp: <05/09/11 12:01:55 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 01:45:37 ptr> /* - * * Copyright (c) 2002 * Petr Ovtchenkov * * Copyright (c) 1999-2001 * ParallelGraphics Ltd. * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. + * Licensed under the Academic Free License Version 3.0 * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ #include <config/feature.h> @@ -60,7 +53,7 @@ con_cond.set( false ); thr.launch( conn_proc, this ); timespec tm; - xmt::Thread::gettime( &tm ); + xmt::gettime( &tm ); tm.tv_sec += 10; // wait 10 secs @@ -119,7 +112,7 @@ if ( thr.good() ) { timespec tm; - xmt::Thread::gettime( &tm ); + xmt::gettime( &tm ); tm.tv_sec += 2; // thread already running, so wait only 2 secs @@ -128,9 +121,9 @@ _dberr << "Connect to DB timeout" << endl; } } else { - thr.launch( (__impl::Thread::entrance_type)conn_proc, (void *)this ); + thr.launch( (xmt::Thread::entrance_type)conn_proc, (void *)this ); timespec tm; - xmt::Thread::gettime( &tm ); + xmt::gettime( &tm ); tm.tv_sec += 5; // wait 5 secs Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/lib/mt/ChangeLog 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,3 +1,13 @@ +2006-12-15 Petr Ovtchenkov <pt...@is...> + + * time.h, time.cc: add timespec in xmt namespace, useful + for conversions and inline objects; clean some code in + timespec operations. + + * xmt.h: changes related to timespec in xmt namespace and in + global namespace; now 'delay' functions family only in xmt + namespace and go away from Thread class. + 2006-12-14 Petr Ovtchenkov <pt...@is...> * xmt.h, xmt.cc: move 'fork' and 'become_daemon' from Thread Modified: trunk/complement/explore/lib/mt/time.cc =================================================================== --- trunk/complement/explore/lib/mt/time.cc 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/lib/mt/time.cc 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/24 09:26:53 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 10:35:48 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -85,8 +85,8 @@ double d = a.tv_sec + 1.0e-9 * a.tv_nsec; d /= b; - c.tv_nsec = int(1.0e9 * modf( d, &d ) + 0.5); - c.tv_sec = int(d); + c.tv_nsec = static_cast<time_t>(1.0e9 * modf( d, &d ) + 0.5); + c.tv_sec = static_cast<long>(d); return c; } @@ -97,12 +97,50 @@ double d = a.tv_sec + 1.0e-9 * a.tv_nsec; d /= b; - c.tv_nsec = int(1.0e9 * modf( d, &d ) + 0.5); - c.tv_sec = int(d); + c.tv_nsec = static_cast<time_t>(1.0e9 * modf( d, &d ) + 0.5); + c.tv_sec = static_cast<long>(d); return c; } +timespec operator *( const timespec& a, unsigned b ) +{ + timespec c; +#if 0 + double d = a.tv_sec + 1.0e-9 * a.tv_nsec; + d *= b; + + c.tv_nsec = static_cast<time_t>(1.0e9 * modf( d, &d ) + 0.5); + c.tv_sec = static_cast<long>(d); +#else + c.tv_sec = a.tv_sec * b; + unsigned long long _tmp = c.tv_nsec; + _tmp *= b; + c.tv_sec += static_cast<time_t>(_tmp / 1000000000UL); + c.tv_nsec = static_cast<long>(_tmp % 1000000000UL); +#endif + return c; +} + +timespec operator *( const timespec& a, unsigned long b ) +{ + timespec c; +#if 0 + double d = a.tv_sec + 1.0e-9 * a.tv_nsec; + d *= b; + + c.tv_nsec = static_cast<time_t>(1.0e9 * modf( d, &d ) + 0.5); + c.tv_sec = static_cast<long>(d); +#else + c.tv_sec = a.tv_sec * b; + unsigned long long _tmp = c.tv_nsec; + _tmp *= b; + c.tv_sec += static_cast<time_t>(_tmp / 1000000000UL); + c.tv_nsec = static_cast<long>(_tmp % 1000000000UL); +#endif + return c; +} + timespec& operator +=( timespec& a, const timespec& b ) { a.tv_sec += b.tv_sec; @@ -133,8 +171,8 @@ double d = a.tv_sec + 1.0e-9 * a.tv_nsec; d /= b; - a.tv_nsec = int(1.0e9 * modf( d, &d ) + 0.5); - a.tv_sec = int(d); + a.tv_nsec = static_cast<time_t>(1.0e9 * modf( d, &d ) + 0.5); + a.tv_sec = static_cast<long>(d); return a; } @@ -144,12 +182,34 @@ double d = a.tv_sec + 1.0e-9 * a.tv_nsec; d /= b; - a.tv_nsec = int(1.0e9 * modf( d, &d ) + 0.5); - a.tv_sec = int(d); + a.tv_nsec = static_cast<time_t>(1.0e9 * modf( d, &d ) + 0.5); + a.tv_sec = static_cast<long>(d); return a; } +timespec& operator *=( timespec& a, unsigned b ) +{ + a.tv_sec *= b; + unsigned long long _tmp = a.tv_nsec; + _tmp *= b; + a.tv_sec += static_cast<time_t>(_tmp / 1000000000UL); + a.tv_nsec = static_cast<long>(_tmp % 1000000000UL); + + return a; +} + +timespec& operator *=( timespec& a, unsigned long b ) +{ + a.tv_sec *= b; + unsigned long long _tmp = a.tv_nsec; + _tmp *= b; + a.tv_sec += static_cast<time_t>(_tmp / 1000000000UL); + a.tv_nsec = static_cast<long>(_tmp % 1000000000UL); + + return a; +} + bool operator ==( const timespec& a, const timespec& b ) { return (a.tv_sec == b.tv_sec) && (a.tv_nsec == b.tv_nsec); @@ -207,97 +267,126 @@ namespace xmt { __FIT_DECLSPEC -void delay( timespec *interval, timespec *remain ) +void delay( const ::timespec& interval, ::timespec& remain ) { #ifdef __unix - nanosleep( interval, remain ); + nanosleep( &interval, &remain ); #endif #ifdef WIN32 - unsigned ms = interval->tv_sec * 1000 + interval->tv_nsec / 1000000; - Sleep( ms ); - if ( remain != 0 ) { // M$ not return remain time interval - remain->tv_sec = 0; - remain->tv_nsec = 0; - } + Sleep( interval.tv_sec * 1000 + interval.tv_nsec / 1000000 ); + remain.tv_sec = 0; + remain.tv_nsec = 0; #endif #ifdef __FIT_NETWARE - unsigned ms = interval->tv_sec * 1000 + interval->tv_nsec / 1000000; - ::delay( ms ); - if ( remain != 0 ) { // Novell not return remain time interval - remain->tv_sec = 0; - remain->tv_nsec = 0; - } + ::delay( interval.tv_sec * 1000 + interval.tv_nsec / 1000000 ); + remain.tv_sec = 0; + remain.tv_nsec = 0; #endif } __FIT_DECLSPEC -void sleep( timespec *abstime, timespec *real_time ) +void delay( const ::timespec& interval ) { #ifdef __unix - timespec ct; - gettime( &ct ); - timespec st = *abstime; + nanosleep( &interval, 0 ); +#endif +#ifdef WIN32 + Sleep( interval.tv_sec * 1000 + interval.tv_nsec / 1000000 ); +#endif +#ifdef __FIT_NETWARE + ::delay( interval.tv_sec * 1000 + interval.tv_nsec / 1000000 ); +#endif +} - if ( st > ct ) { +__FIT_DECLSPEC +void sleep( const ::timespec& abstime, ::timespec& real_time ) +{ +#ifdef __unix + ::timespec ct; + gettime( ct ); + + if ( abstime > ct ) { + xmt::timespec st( abstime ); st -= ct; - nanosleep( &st, real_time ); - if ( real_time != 0 ) { - *real_time += ct; - } - } else if ( real_time != 0 ) { - *real_time = ct; + nanosleep( static_cast<const ::timespec *>(&st), &real_time ); + real_time += ct; + } else { + real_time.tv_sec = ct.tv_sec; + real_time.tv_nsec = ct.tv_nsec; } #endif #ifdef WIN32 time_t ct = time( 0 ); - time_t _conv = abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000; + time_t _conv = abstime.tv_sec * 1000 + abstime.tv_nsec / 1000000; - unsigned ms = _conv >= ct ? _conv - ct : 1; - Sleep( ms ); - if ( real_time != 0 ) { // M$ not return elapsed time interval - real_time->tv_sec = abstime->tv_sec; - real_time->tv_nsec = abstime->tv_nsec; - } + Sleep( _conv >= ct ? _conv - ct : 1 ); + real_time.tv_sec = abstime.tv_sec; + real_time.tv_nsec = abstime.tv_nsec; #endif #ifdef __FIT_NETWARE time_t ct = time( 0 ); - time_t _conv = abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000; + time_t _conv = abstime.tv_sec * 1000 + abstime.tv_nsec / 1000000; - unsigned ms = _conv >= ct ? _conv - ct : 1; - ::delay( ms ); - if ( real_time != 0 ) { // Novell not return elapsed time interval - real_time->tv_sec = abstime->tv_sec; - real_time->tv_nsec = abstime->tv_nsec; + ::delay( _conv >= ct ? _conv - ct : 1 ); + // Novell not return elapsed time interval + real_time.tv_sec = abstime.tv_sec; + real_time.tv_nsec = abstime.tv_nsec; +#endif +} + +__FIT_DECLSPEC +void sleep( const ::timespec& abstime ) +{ +#ifdef __unix + ::timespec ct; + gettime( ct ); + + if ( abstime > ct ) { + xmt::timespec st( abstime ); + st -= ct; + nanosleep( static_cast<const ::timespec *>(&st), 0 ); } #endif +#ifdef WIN32 + time_t ct = time( 0 ); + time_t _conv = abstime.tv_sec * 1000 + abstime.tv_nsec / 1000000; + + Sleep( _conv >= ct ? _conv - ct : 1 ); +#endif +#ifdef __FIT_NETWARE + time_t ct = time( 0 ); + time_t _conv = abstime.tv_sec * 1000 + abstime.tv_nsec / 1000000; + + ::delay( _conv >= ct ? _conv - ct : 1 ); +#endif } __FIT_DECLSPEC -void gettime( timespec *t ) +void gettime( ::timespec& t ) { #if defined(__linux) || defined(__FreeBSD__) || defined(__OpenBSD__) timeval tv; gettimeofday( &tv, 0 ); - TIMEVAL_TO_TIMESPEC( &tv, t ); + TIMEVAL_TO_TIMESPEC( &tv, &t ); #elif defined( WIN32 ) union { FILETIME ft; // 100 ns intervals since Jan 1 1601 (UTC) __int64 t; } ft; GetSystemTimeAsFileTime( &ft.ft ); - t->tv_sec = int(ft.t / (__int64)10000000 - (__int64)(11644473600)); // 60 * 60 * 24 * 134774, 1970 - 1601 - t->tv_nsec = int(ft.t % (__int64)(10000000)) * 100; + t.tv_sec = int(ft.t / (__int64)10000000 - (__int64)(11644473600)); // 60 * 60 * 24 * 134774, 1970 - 1601 + t.tv_nsec = int(ft.t % (__int64)(10000000)) * 100; //time_t ct = time( 0 ); //t->tv_sec = ct; // ct / 1000; //t->tv_nsec = 0; // (ct % 1000) * 1000000; #elif defined(__sun) || defined(__hpux) - clock_gettime( CLOCK_REALTIME, t ); + clock_gettime( CLOCK_REALTIME, &t ); #elif defined(__FIT_NETWARE) time_t ct = time(0); // GetHighResolutionTimer (ret current time in 100 microsec increments) // GetSuperHighResolutionTimer() (ret current time in 838 nanosec increments) - t->tv_sec = ct; - t->tv_nsec = 0; + t.tv_sec = ct; + t.tv_nsec = 0; #else #error "You should implement OS-dependent precise clock" #endif Modified: trunk/complement/explore/lib/mt/xmt.cc =================================================================== --- trunk/complement/explore/lib/mt/xmt.cc 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/lib/mt/xmt.cc 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/14 17:12:53 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 10:10:57 ptr> /* * Copyright (c) 1997-1999, 2002-2006 @@ -171,7 +171,7 @@ __FIT_DECLSPEC -int Semaphore::wait_time( const timespec *abstime ) // wait for time t, or signal +int Semaphore::wait_time( const ::timespec *abstime ) // wait for time t, or signal { #ifdef __FIT_WIN32THREADS time_t ct = time( 0 ); @@ -204,7 +204,7 @@ } __FIT_DECLSPEC -int Semaphore::wait_delay( const timespec *interval ) // wait, timeout is delay t, or signal +int Semaphore::wait_delay( const ::timespec *interval ) // wait, timeout is delay t, or signal { #ifdef __FIT_WIN32THREADS unsigned ms = interval->tv_sec * 1000 + interval->tv_nsec / 1000000; @@ -219,7 +219,7 @@ #endif #ifdef _PTHREADS timespec st; - Thread::gettime( &st ); + xmt::gettime( &st ); st += *interval; # if !(defined(__FreeBSD__) || defined(__OpenBSD__)) return sem_timedwait( &_sem, &st ); @@ -623,8 +623,46 @@ #endif __FIT_DECLSPEC -void Thread::block_signal( int sig ) +void Thread::signal_exit( int sig ) { +#ifdef _PTHREADS + _uw_alloc_type *user_words = + static_cast<_uw_alloc_type *>(pthread_getspecific( Thread::_mt_key )); + if ( user_words == 0 ) { + // async signal unsafe? or wrong thread called? + // this a bad point, do nothing + return; + } + user_words += Thread::_self_idx; + Thread *me = reinterpret_cast<Thread *>(*reinterpret_cast<void **>(user_words)); + // _STLP_ASSERT( me->is_self() ); + + me->_state = badbit; + // follow part of _call + if ( (me->_flags & (daemon | detached)) != 0 ) { // otherwise join expected + me->_id = bad_thread_id; + } + me->_dealloc_uw(); // clear user words + void *_param = me->_param; + size_t _param_sz = me->_param_sz; + try { + if ( _param_sz > sizeof(void *) ) { // that's allocated + delete [] __STATIC_CAST(char *,_param); + _param_sz = 0; + _param = 0; + } + } + catch ( ... ) { + } +#endif + // well, this is suspicious, due to pthread_exit isn't async signal + // safe; what I should use here? + Thread::_exit( 0 ); +} + +__FIT_DECLSPEC +void block_signal( int sig ) +{ #ifdef __unix sigset_t sigset; @@ -640,7 +678,7 @@ } __FIT_DECLSPEC -void Thread::unblock_signal( int sig ) +void unblock_signal( int sig ) { #ifdef __unix sigset_t sigset; @@ -657,7 +695,7 @@ } __FIT_DECLSPEC -void Thread::signal_handler( int sig, SIG_PF handler ) +void signal_handler( int sig, SIG_PF handler ) { #ifdef __unix // catch SIGPIPE here struct sigaction act; @@ -672,44 +710,6 @@ } __FIT_DECLSPEC -void Thread::signal_exit( int sig ) -{ -#ifdef _PTHREADS - _uw_alloc_type *user_words = - static_cast<_uw_alloc_type *>(pthread_getspecific( _mt_key )); - if ( user_words == 0 ) { - // async signal unsafe? or wrong thread called? - // this a bad point, do nothing - return; - } - user_words += Thread::_self_idx; - Thread *me = reinterpret_cast<Thread *>(*reinterpret_cast<void **>(user_words)); - // _STLP_ASSERT( me->is_self() ); - - me->_state = badbit; - // follow part of _call - if ( (me->_flags & (daemon | detached)) != 0 ) { // otherwise join expected - me->_id = bad_thread_id; - } - me->_dealloc_uw(); // clear user words - void *_param = me->_param; - size_t _param_sz = me->_param_sz; - try { - if ( _param_sz > sizeof(void *) ) { // that's allocated - delete [] __STATIC_CAST(char *,_param); - _param_sz = 0; - _param = 0; - } - } - catch ( ... ) { - } -#endif - // well, this is suspicious, due to pthread_exit isn't async signal - // safe; what I should use here? - Thread::_exit( 0 ); -} - -__FIT_DECLSPEC void fork() throw( fork_in_parent, std::runtime_error ) { #ifdef __unix Modified: trunk/complement/explore/lib/stem/Cron.cc =================================================================== --- trunk/complement/explore/lib/stem/Cron.cc 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/lib/stem/Cron.cc 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,22 +1,14 @@ -// -*- C++ -*- Time-stamp: <06/08/04 00:01:51 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 03:12:28 ptr> /* - * Copyright (c) 1998, 2002, 2003, 2005 + * Copyright (c) 1998, 2002, 2003, 2005, 2006 * Petr Ovtchenkov * * Copyright (c) 1999-2001 * ParallelGraphics Ltd. * - * Licensed under the Academic Free License version 2.1 + * Licensed under the Academic Free License version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ #ifdef _MSC_VER @@ -71,16 +63,13 @@ en.code = ne.code; en.addr = entry.src(); - en.start.tv_sec = ne.start.tv_sec; - en.start.tv_nsec = ne.start.tv_nsec; + en.start = ne.start; en.n = ne.n; en.arg = ne.arg; if ( en.n == 1 ) { - en.period.tv_sec = 0; - en.period.tv_nsec = 0; + en.period = 0; } else { - en.period.tv_sec = ne.period.tv_sec; - en.period.tv_nsec = ne.period.tv_nsec; + en.period = ne.period; if ( en.n == 0 || en.period.tv_nsec >= 1000000000 || (en.period.tv_sec == 0 && en.period.tv_nsec == 0) ) return; @@ -91,8 +80,7 @@ en.start.tv_sec = current; } - en.expired.tv_sec = en.start.tv_sec; - en.expired.tv_nsec = en.start.tv_nsec; + en.expired = en.start; en.count = 0; MT_REENTRANT( _M_l, _x1 ); @@ -231,31 +219,13 @@ continue; } -#if !defined(_STLP_LONG_LONG) && !defined(_GLIBCXX_USE_LONG_LONG) - double _next = en.start.tv_sec + en.start.tv_nsec * 1.0e-9 + - (en.period.tv_sec + en.period.tv_nsec * 1.0e-9) * ++en.count; - en.expired.tv_nsec = static_cast<long>(1.0e9 * modf( _next, &_next )); - en.expired.tv_sec = static_cast<long>(_next); -#else -# ifdef _MSC_VER - __int64 -# else - long long -# endif - _d = en.period.tv_nsec; - _d *= ++en.count; - _d += en.start.tv_nsec; - en.expired.tv_sec = en.period.tv_sec; - en.expired.tv_sec *= en.count; - en.expired.tv_sec += en.start.tv_sec; - en.expired.tv_sec += unsigned(_d / 1000000000); - en.expired.tv_nsec = unsigned(_d % 1000000000); -#endif + en.expired = en.start; + en.expired += en.period * ++en.count; + // if loop infinite, always put Cron entry in stack, // otherwise check counter if ( en.n == CronEntry::infinite ) { - en.start.tv_sec = en.expired.tv_sec; - en.start.tv_nsec = en.expired.tv_nsec; + en.start = en.expired; en.count = 0; me._M_c.push( en ); } else if ( (en.count) < (en.n) ) { // This SC5.0 patch 107312-06 bug Modified: trunk/complement/explore/test/mt/flck.cc =================================================================== --- trunk/complement/explore/test/mt/flck.cc 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/test/mt/flck.cc 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,23 +1,14 @@ -// -*- C++ -*- Time-stamp: <06/08/04 11:21:10 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 10:43:07 ptr> /* - * * Copyright (c) 2004, 2006 * Petr Ovtchenkov * * Copyright (c) 2004 * Kaspersky Labs * - * Licensed under the Academic Free License Version 2.1 + * Licensed under the Academic Free License Version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ #include <boost/test/unit_test.hpp> @@ -74,12 +65,8 @@ ++cnt; m.unlock(); - timespec t; - t.tv_sec = 1; - t.tv_nsec = 0; + delay( xmt::timespec(1,0) ); - Thread::delay( &t ); - check = flck( fd, _F_UNLCK ); b.lock(); @@ -195,12 +182,8 @@ } } - timespec t; - t.tv_sec = 1; - t.tv_nsec = 0; + delay( xmt::timespec(1,0) ); - Thread::delay( &t ); - check = flck( fd, _F_UNLCK ); b.lock(); Modified: trunk/complement/explore/test/mt/lfs.cc =================================================================== --- trunk/complement/explore/test/mt/lfs.cc 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/test/mt/lfs.cc 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,23 +1,14 @@ -// -*- C++ -*- Time-stamp: <06/08/04 11:25:15 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 10:44:27 ptr> /* - * * Copyright (c) 2004, 2006 * Petr Ovtchenkov * * Copyright (c) 2004 * Kaspersky Lab * - * Licensed under the Academic Free License Version 2.1 + * Licensed under the Academic Free License Version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ #include <boost/test/unit_test.hpp> @@ -72,12 +63,8 @@ cnd.set( true, true ); - timespec t; - t.tv_sec = 1; - t.tv_nsec = 0; + delay( xmt::timespec(1,0) ); - Thread::delay( &t ); - s.unlock(); b.lock(); @@ -142,12 +129,8 @@ b.unlock(); } - timespec t; - t.tv_sec = 1; - t.tv_nsec = 0; + delay( xmt::timespec(1,0) ); - Thread::delay( &t ); - s.unlock(); b.lock(); BOOST_REQUIRE( s.good() ); @@ -190,12 +173,8 @@ cnd.set( true, true ); - timespec t; - t.tv_sec = 1; - t.tv_nsec = 0; + delay( xmt::timespec(1,0) ); - Thread::delay( &t ); - s << ulck; b.lock(); @@ -245,12 +224,8 @@ b.unlock(); } - timespec t; - t.tv_sec = 1; - t.tv_nsec = 0; + delay( xmt::timespec(1,0) ); - Thread::delay( &t ); - s >> ulck; b.lock(); BOOST_REQUIRE( s.good() ); Modified: trunk/complement/explore/test/mt/mutex_test.cc =================================================================== --- trunk/complement/explore/test/mt/mutex_test.cc 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/test/mt/mutex_test.cc 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,20 +1,11 @@ -// -*- C++ -*- Time-stamp: <06/08/04 10:59:26 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 10:37:09 ptr> /* - * * Copyright (c) 2002, 2003, 2006 * Petr Ovtchenkov * - * Licensed under the Academic Free License Version 2.1 + * Licensed under the Academic Free License Version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ #include <boost/test/unit_test.hpp> @@ -24,7 +15,7 @@ #include <mt/xmt.h> using namespace std; -using namespace __impl; +using namespace xmt; static Mutex m1; @@ -37,12 +28,8 @@ msync = 1; BOOST_CHECK( v == 0 ); - timespec t; - t.tv_sec = 1; - t.tv_nsec = 0; + delay( xmt::timespec( 1, 0 ) ); - Thread::delay( &t ); - BOOST_CHECK( v == 0 ); v = 1; @@ -78,12 +65,8 @@ BOOST_CHECK( v == 0 ); - timespec t; - t.tv_sec = 1; - t.tv_nsec = 0; + delay( xmt::timespec( 1, 0 ) ); - Thread::delay( &t ); - v = 1; m1.unlock(); Modified: trunk/complement/explore/test/mt/recursive_mutex.cc =================================================================== --- trunk/complement/explore/test/mt/recursive_mutex.cc 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/test/mt/recursive_mutex.cc 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,19 +1,11 @@ -// -*- C++ -*- Time-stamp: <06/08/04 11:07:52 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 10:39:45 ptr> /* * Copyright (c) 2003, 2006 * Petr Ovtchenkov * - * Licensed under the Academic Free License Version 2.1 + * Licensed under the Academic Free License Version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ @@ -64,12 +56,8 @@ m.lock(); v = 2; - timespec t; - t.tv_sec = 1; - t.tv_nsec = 0; - - Thread::sleep( &t ); + xmt::sleep( xmt::timespec(1,0) ); BOOST_CHECK( v == 2 ); m.unlock(); @@ -94,13 +82,8 @@ // cerr << "after lock in thread one" << endl; // pm.unlock(); - timespec t; + xmt::sleep( xmt::timespec(1,0) ); - t.tv_sec = 1; - t.tv_nsec = 0; - - Thread::sleep( &t ); - BOOST_CHECK( v == 1 ); recursive(); @@ -139,13 +122,7 @@ // pm.unlock(); BOOST_CHECK( v == 3 ); - - timespec t; - - t.tv_sec = 1; - t.tv_nsec = 0; - - Thread::sleep( &t ); + xmt::sleep( xmt::timespec(1,0) ); recursive(); // pm.lock(); Modified: trunk/complement/explore/test/mt/signal-1.cc =================================================================== --- trunk/complement/explore/test/mt/signal-1.cc 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/test/mt/signal-1.cc 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,19 +1,11 @@ -// -*- C++ -*- Time-stamp: <06/08/04 11:13:44 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 10:40:53 ptr> /* * Copyright (c) 2003, 2006 * Petr Ovtchenkov * - * Licensed under the Academic Free License Version 2.1 + * Licensed under the Academic Free License Version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ #include <boost/test/unit_test.hpp> @@ -55,11 +47,11 @@ Thread::ret_code thread_one( void * ) { - Thread::unblock_signal( SIGINT ); // we wait this signal + xmt::unblock_signal( SIGINT ); // we wait this signal // Default handler make exit() call: // Thread::signal_handler( SIGINT, SIG_DFL ); // That's why I set own handler: - Thread::signal_handler( SIGINT, handler ); + xmt::signal_handler( SIGINT, handler ); BOOST_CHECK( v == 1 ); @@ -70,13 +62,10 @@ // wait while set thread's pointer (from thread_two) - timespec t; + xmt::timespec t(1,0); - t.tv_sec = 1; - t.tv_nsec = 0; - while ( th_one == 0 ) { - Thread::sleep( &t ); + xmt::sleep( t ); } // pm.lock(); Modified: trunk/complement/explore/test/mt/signal-2.cc =================================================================== --- trunk/complement/explore/test/mt/signal-2.cc 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/test/mt/signal-2.cc 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,19 +1,11 @@ -// -*- C++ -*- Time-stamp: <06/08/04 11:16:33 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 10:41:46 ptr> /* * Copyright (c) 2003, 2006 * Petr Ovtchenkov * - * Licensed under the Academic Free License Version 2.1 + * Licensed under the Academic Free License Version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ #include <boost/test/unit_test.hpp> @@ -56,20 +48,17 @@ rt.iword = 0; try { - Thread::unblock_signal( SIGINT ); // we wait this signal + xmt::unblock_signal( SIGINT ); // we wait this signal // I set own handler, that throw signal: - Thread::signal_handler( SIGINT, handler ); + xmt::signal_handler( SIGINT, handler ); BOOST_CHECK( v == 1 ); // wait while set thread's pointer (from thread_two) - timespec t; + xmt::timespec t(1,0); - t.tv_sec = 1; - t.tv_nsec = 0; - while ( th_one == 0 ) { - Thread::sleep( &t ); + xmt::sleep( t ); } // pm.lock(); Modified: trunk/complement/explore/test/mt/spinlock_test.cc =================================================================== --- trunk/complement/explore/test/mt/spinlock_test.cc 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/test/mt/spinlock_test.cc 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,20 +1,11 @@ -// -*- C++ -*- Time-stamp: <06/08/04 11:05:07 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 10:38:16 ptr> /* - * * Copyright (c) 2002, 2003, 2006 * Petr Ovtchenkov * - * Licensed under the Academic Free License Version 2.1 + * Licensed under the Academic Free License Version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ #include <boost/test/unit_test.hpp> @@ -24,7 +15,7 @@ #include <mt/xmt.h> using namespace std; -using namespace __impl; +using namespace xmt; static int v = 0; @@ -36,12 +27,8 @@ sl1.lock(); BOOST_CHECK( v == 0 ); - timespec t; - t.tv_sec = 1; - t.tv_nsec = 0; + delay( xmt::timespec( 1, 0 ) ); - Thread::delay( &t ); - BOOST_CHECK( v == 0 ); v = 1; @@ -72,12 +59,8 @@ BOOST_CHECK( v == 0 ); - timespec t; - t.tv_sec = 1; - t.tv_nsec = 0; + delay( xmt::timespec( 1, 0 ) ); - Thread::delay( &t ); - v = 1; sl1.unlock(); Modified: trunk/complement/explore/test/sockios/client-wc.cc =================================================================== --- trunk/complement/explore/test/sockios/client-wc.cc 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/test/sockios/client-wc.cc 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,20 +1,11 @@ -// -*- C++ -*- Time-stamp: <06/08/04 12:01:50 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 10:49:16 ptr> /* - * * Copyright (c) 2004, 2006 * Petr Ovtchenkov * - * Licensed under the Academic Free License Version 2.1 + * Licensed under the Academic Free License Version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ #include <boost/test/test_tools.hpp> @@ -51,12 +42,8 @@ { s << "hello" << endl; - timespec t; - t.tv_sec = 1; - t.tv_nsec = 0; + xmt::delay( xmt::timespec( 1, 0 ) ); - Thread::delay( &t ); - s.close(); // ::shutdown( s.rdbuf()->fd(), 2 ); } @@ -117,12 +104,8 @@ BOOST_CHECK( buf == "hello" ); pr_lock.unlock(); - timespec t; - t.tv_sec = 5; - t.tv_nsec = 0; + xmt::delay( xmt::timespec( 5, 0 ) ); - Thread::delay( &t ); - // sock << 'a' << endl; /* Modified: trunk/complement/explore/test/sockios/read0_on_exec.cc =================================================================== --- trunk/complement/explore/test/sockios/read0_on_exec.cc 2006-12-14 14:23:00 UTC (rev 1456) +++ trunk/complement/explore/test/sockios/read0_on_exec.cc 2006-12-15 08:11:12 UTC (rev 1457) @@ -1,7 +1,6 @@ -// -*- C++ -*- Time-stamp: <06/11/28 09:33:13 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 10:50:48 ptr> /* - * * Copyright (c) 2006 * Petr Ovtchenkov * @@ -83,10 +82,7 @@ pr_lock.unlock(); // cerr << "ConnectionProcessor5::ConnectionProcessor5\n"; - timespec tm; - tm.tv_sec = 3; - tm.tv_nsec = 0; - Thread::delay( &tm ); + delay( xmt::timespec(3,0) ); int n = 1; // cerr << "ConnectionProcessor5::ConnectionProcessor5, write\n"; @@ -156,10 +152,7 @@ cnd.try_wait(); // wait for read call - timespec tm; - tm.tv_sec = 1; - tm.tv_nsec = 0; - Thread::delay( &tm ); + delay( xmt::timespec(1,0) ); // cerr << "system" << endl; system( "echo > /dev/null" ); // <------ key line This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |