Thread: [complement-svn] SF.net SVN: complement: [1458] trunk/complement/explore (Page 2)
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-12-15 12:26:49
|
Revision: 1458 http://svn.sourceforge.net/complement/?rev=1458&view=rev Author: complement Date: 2006-12-15 04:26:46 -0800 (Fri, 15 Dec 2006) Log Message: ----------- add setting signal handler with siginfo Modified Paths: -------------- trunk/complement/explore/include/mt/xmt.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/xmt.cc Added Paths: ----------- trunk/complement/explore/inquiry/shades/dump_term/ trunk/complement/explore/inquiry/shades/dump_term/Makefile trunk/complement/explore/inquiry/shades/dump_term/Makefile.inc trunk/complement/explore/inquiry/shades/dump_term/test.cc Modified: trunk/complement/explore/include/mt/xmt.h =================================================================== --- trunk/complement/explore/include/mt/xmt.h 2006-12-15 08:11:12 UTC (rev 1457) +++ trunk/complement/explore/include/mt/xmt.h 2006-12-15 12:26:46 UTC (rev 1458) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/15 03:03:00 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 14:35:45 ptr> /* * Copyright (c) 1997-1999, 2002-2006 @@ -124,6 +124,8 @@ # endif #endif // SIG_PF +typedef void siginfo_handler_type( int, siginfo_t *, void * ); + } // extern "C" namespace xmt { @@ -1402,7 +1404,8 @@ __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 ); +__FIT_DECLSPEC int signal_handler( int sig, SIG_PF ); +__FIT_DECLSPEC int signal_handler( int sig, siginfo_handler_type ); class Thread { Property changes on: trunk/complement/explore/inquiry/shades/dump_term ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/explore/inquiry/shades/dump_term/Makefile =================================================================== --- trunk/complement/explore/inquiry/shades/dump_term/Makefile (rev 0) +++ trunk/complement/explore/inquiry/shades/dump_term/Makefile 2006-12-15 12:26:46 UTC (rev 1458) @@ -0,0 +1,16 @@ +# -*- Makefile -*- Time-stamp: <06/12/15 13:47:56 ptr> + +SRCROOT := ../../.. + +include Makefile.inc +include ${SRCROOT}/Makefiles/top.mak + +INCLUDES += -I${CoMT_INCLUDE_DIR} + +release-shared : LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR}:${CoMT_LIB_DIR} +dbg-shared : LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR}:${CoMT_LIB_DIR} +stldbg-shared : LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR}:${CoMT_LIB_DIR} + +release-shared: LDLIBS = -L${CoMT_LIB_DIR} -lxmt +dbg-shared: LDLIBS = -L${CoMT_LIB_DIR} -lxmtg +stldbg-shared: LDLIBS = -L${CoMT_LIB_DIR} -lxmtstlg Added: trunk/complement/explore/inquiry/shades/dump_term/Makefile.inc =================================================================== --- trunk/complement/explore/inquiry/shades/dump_term/Makefile.inc (rev 0) +++ trunk/complement/explore/inquiry/shades/dump_term/Makefile.inc 2006-12-15 12:26:46 UTC (rev 1458) @@ -0,0 +1,4 @@ +# -*- makefile -*- Time-stamp: <04/01/12 15:37:40 ptr> + +PRGNAME = test +SRC_CC = test.cc Added: trunk/complement/explore/inquiry/shades/dump_term/test.cc =================================================================== --- trunk/complement/explore/inquiry/shades/dump_term/test.cc (rev 0) +++ trunk/complement/explore/inquiry/shades/dump_term/test.cc 2006-12-15 12:26:46 UTC (rev 1458) @@ -0,0 +1,77 @@ +#include <mt/xmt.h> +#include <iostream> + +using namespace std; +using namespace xmt; + +void h1( int sig ) +{ + cerr << "Signal: " << sig << endl; +} + +void h2( int sig, siginfo_t *si, void * ) +{ + cerr << "-----------------------------------------------\n" + << "my pid: " << xmt::getpid() << ", ppid: " << xmt::getppid() << "\n" + << "signal: " << sig << ", number " << si->si_signo + << " errno " << si->si_errno + << " code " << si->si_code << endl; + switch ( si->si_signo ) { + case SIGKILL: + case SIGTERM: + case SIGINT: + case SIGQUIT: + case SIGPIPE: + case SIGABRT: + case SIGALRM: + case SIGHUP: + cerr << "pid: " << si->si_pid + << "\nuid: " << si->si_uid + << endl; + break; + case SIGILL: + case SIGFPE: + case SIGSEGV: + case SIGBUS: + cerr << "Address: " << si->si_addr << endl; + break; + } +} + +class Superviser +{ + public: + ~Superviser(); +}; + +Superviser::~Superviser() +{ + cerr << "Good bye" << endl; + kill( xmt::getpid(), SIGABRT ); +} + +// Superviser s; + +int main() +{ + Condition cnd; + + cnd.set( false ); + signal_handler( SIGTERM, &h2 ); + signal_handler( SIGKILL, &h2 ); + signal_handler( SIGQUIT, &h2 ); + signal_handler( SIGINT, &h2 ); + signal_handler( SIGHUP, &h2 ); + signal_handler( SIGALRM, &h2 ); + signal_handler( SIGABRT, &h2 ); + signal_handler( SIGPIPE, &h2 ); + // signal_handler( SIGKILL, &h1 ); + // signal_handler( SIGSTOP, &h1 ); + // unblock_signal( SIGTERM ); + + cerr << "Hello, world!" << endl; + + cnd.wait(); + + return 0; +} Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2006-12-15 08:11:12 UTC (rev 1457) +++ trunk/complement/explore/lib/mt/ChangeLog 2006-12-15 12:26:46 UTC (rev 1458) @@ -2,12 +2,14 @@ * time.h, time.cc: add timespec in xmt namespace, useful for conversions and inline objects; clean some code in - timespec operations. + 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. + namespace and go away from Thread class; + * xmt.h, xmt.cc: add setting signal handler with siginfo. + 2006-12-14 Petr Ovtchenkov <pt...@is...> * xmt.h, xmt.cc: move 'fork' and 'become_daemon' from Thread Modified: trunk/complement/explore/lib/mt/xmt.cc =================================================================== --- trunk/complement/explore/lib/mt/xmt.cc 2006-12-15 08:11:12 UTC (rev 1457) +++ trunk/complement/explore/lib/mt/xmt.cc 2006-12-15 12:26:46 UTC (rev 1458) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/15 10:10:57 ptr> +// -*- C++ -*- Time-stamp: <06/12/15 14:39:47 ptr> /* * Copyright (c) 1997-1999, 2002-2006 @@ -695,7 +695,7 @@ } __FIT_DECLSPEC -void signal_handler( int sig, SIG_PF handler ) +int signal_handler( int sig, SIG_PF handler ) { #ifdef __unix // catch SIGPIPE here struct sigaction act; @@ -705,11 +705,30 @@ act.sa_flags = 0; // SA_RESTART; act.sa_handler = handler; - sigaction( sig, &act, 0 ); + return sigaction( sig, &act, 0 ); +#else + return -1; #endif // __unix } __FIT_DECLSPEC +int signal_handler( int sig, siginfo_handler_type handler ) +{ +#ifdef __unix // catch SIGPIPE here + struct sigaction act; + + sigemptyset( &act.sa_mask ); + sigaddset( &act.sa_mask, sig ); + + act.sa_flags = SA_SIGINFO; // SA_RESTART; + act.sa_sigaction = handler; + return sigaction( sig, &act, 0 ); +#else + return -1; +#endif // __unix +} + +__FIT_DECLSPEC void fork() throw( fork_in_parent, std::runtime_error ) { #ifdef __unix This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-12-26 16:13:03
|
Revision: 1462 http://svn.sourceforge.net/complement/?rev=1462&view=rev Author: complement Date: 2006-12-26 08:13:00 -0800 (Tue, 26 Dec 2006) Log Message: ----------- shared memory-based allocator; libxmt 1.9.4 Modified Paths: -------------- trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/test/mt/Makefile trunk/complement/explore/test/mt/mt_test.cc trunk/complement/explore/test/mt/mt_test.h trunk/complement/explore/test/mt/mt_test_suite.cc Added Paths: ----------- trunk/complement/explore/include/mt/shm.h trunk/complement/explore/lib/mt/shm.cc Added: trunk/complement/explore/include/mt/shm.h =================================================================== --- trunk/complement/explore/include/mt/shm.h (rev 0) +++ trunk/complement/explore/include/mt/shm.h 2006-12-26 16:13:00 UTC (rev 1462) @@ -0,0 +1,515 @@ +// -*- C++ -*- Time-stamp: <06/12/26 10:24:35 ptr> + +/* + * Copyright (c) 2006 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License version 3.0 + * + */ + +#ifndef __mt_shm_h +#define __mt_shm_h + +#include <sys/ipc.h> +#include <sys/shm.h> +#include <errno.h> +#include <fcntl.h> +#include <unistd.h> +#include <stdint.h> + +#include <stdexcept> + +#include <stl/type_traits.h> + +#include <mt/xmt.h> + +namespace xmt { + +struct shm_base +{ + enum open_type { + create = IPC_CREAT, + exclusive = IPC_EXCL + }; + + enum flags_type { + round = SHM_RND, + ro = SHM_RDONLY, + }; +}; + +class shm_bad_alloc : + public std::bad_alloc +{ + public: + shm_bad_alloc() throw() : + err( errno ) + {} + shm_bad_alloc( int s ) throw() : + err( s ) + {} + shm_bad_alloc( const shm_bad_alloc& a ) throw() : + err( a.err ) + {} + shm_bad_alloc& operator =( const shm_bad_alloc& r ) throw() + { err = r.err; return *this; } + virtual ~shm_bad_alloc() throw() + {} + virtual const char *what() const throw(); + + private: + int err; +}; + +template <class T> +struct ipc_sharable +{ + typedef typename std::__type_traits<T>::is_POD_type is_ipc_sharable; +}; + +template <int _Inst> class shm_alloc; + +namespace detail { + +template <int Inst> +class __shm_alloc : + public xmt::shm_base +{ + public: + typedef void * pointer; + typedef const void * const_pointer; + typedef size_t size_type; + typedef size_t difference_type; + + __shm_alloc() throw() + { } + + __shm_alloc( const char *name, size_type sz, int o, int mode, int f = 0, void *addr = 0 ) + { allocate( name, sz, o, mode, f, addr ); } + + __shm_alloc( key_t k, size_type sz, int o, int mode, int f = 0, void *addr = 0 ) + { allocate( k, sz, o, mode, f, addr ); } + + __shm_alloc( int id, int f = 0, void *addr = 0 ) + { allocate( id, f, addr ); } + + ~__shm_alloc() throw() + { + if ( _seg != reinterpret_cast<void *>(-1) ) { + shmdt( _seg ); + _seg = reinterpret_cast<void *>(-1); + } + } + + static pointer allocate( const char *name, size_type sz, int o, int mode, int f = 0, void *addr = 0 ); + static pointer allocate( key_t k, size_type sz, int o, int mode, int f = 0, void *addr = 0 ); + static pointer allocate( int id, int f = 0, void *addr = 0 ); + + static pointer reallocate( int f = 0, void *addr = 0 ); + + static void deallocate( bool force = false ) + { + if ( _seg != reinterpret_cast<void *>(-1) ) { + shmdt( _seg ); + _seg = reinterpret_cast<void *>(-1); + } + if ( _id != -1 ) { + if ( force || (shmctl( _id, IPC_STAT, &_ds ) == 0 && _ds.shm_nattch == 0) ) { + shmctl( _id, IPC_RMID, &_ds ); + _id = -1; + } + } + } + + static pointer address() throw() + { return _seg; } + + static size_type max_size() throw() + { return _id == -1 ? 0 : _ds.shm_segsz; } + + private: + static shmid_ds _ds; + static int _id; + static void *_seg; +}; + +template <int Inst> +shmid_ds __shm_alloc<Inst>::_ds; + +template <int Inst> +int __shm_alloc<Inst>::_id = -1; + +template <int Inst> +void *__shm_alloc<Inst>::_seg = reinterpret_cast<void *>(-1); + +template <int Inst> +typename __shm_alloc<Inst>::pointer __shm_alloc<Inst>::allocate( const char *name, size_type sz, int o, int mode, int f, void *addr ) +{ + if ( _id != -1 ) { + throw shm_bad_alloc( -1 ); + } + int of = 0; + if ( o & create ) { + of |= O_CREAT; + } + if ( o & exclusive ) { + of |= O_EXCL; + } + if ( f & SHM_RDONLY ) { + of |= O_RDONLY; + } else { + of |= O_RDWR; + } + bool rmfile = true; + if ( (o & create) && !(o & exclusive) ) { + int exist_fd = open( name, of & ~O_CREAT, (0777 & mode) ); + if ( exist_fd >= 0 ) { + rmfile = false; + ::close( exist_fd ); + } + } + int fd = open( name, of, (0777 & mode) ); + if ( fd < 0 ) { + throw shm_bad_alloc(); + } + close( fd ); + key_t k = ftok( name, Inst ); + if ( k == -1 ) { + if ( (o & create) && (rmfile || (o & exclusive)) ) { + unlink( name ); + } + throw shm_bad_alloc(); + } + return allocate( k, sz, o, mode, f, addr ); +} + +template <int Inst> +typename __shm_alloc<Inst>::pointer __shm_alloc<Inst>::allocate( key_t k, size_type sz, int o, int mode, int f, void *addr ) +{ + if ( _id != -1 ) { + throw shm_bad_alloc( -1 ); + } + + static const size_type psz = getpagesize(); + + _id = shmget( k, ((sz + sizeof(typename shm_alloc<Inst>::_master) + sizeof(typename shm_alloc<Inst>::_aheader) )/ psz + 1) * psz, o | (0777 & mode) ); + if ( _id == -1 ) { + throw shm_bad_alloc(); + } + if ( shmctl( _id, IPC_STAT, &_ds ) == -1 ) { + throw shm_bad_alloc(); + } + _seg = shmat( _id, addr, f ); + if ( _seg == reinterpret_cast<void *>(-1) ) { + if ( (o & create) && (o & exclusive) ) { + shmctl( _id, IPC_RMID, &_ds ); + } + throw shm_bad_alloc(); + } + + return _seg; +} + +template <int Inst> +typename __shm_alloc<Inst>::pointer __shm_alloc<Inst>::allocate( int id, int f, void *addr ) +{ + if ( _id != -1 ) { + throw shm_bad_alloc( -1 ); + } + if ( shmctl( id, IPC_STAT, &_ds ) == -1 ) { + throw shm_bad_alloc(); + } + _id = id; + _seg = shmat( _id, addr, f ); + if ( _seg == reinterpret_cast<void *>(-1) ) { + throw shm_bad_alloc(); + } + + return _seg; +} + +template <int Inst> +typename __shm_alloc<Inst>::pointer __shm_alloc<Inst>::reallocate( int f, void *addr ) +{ + if ( _id == -1 ) { + throw shm_bad_alloc( -1 ); + } + if ( shmctl( _id, IPC_STAT, &_ds ) == -1 ) { + throw shm_bad_alloc(); + } + _seg = shmat( _id, addr, f ); + if ( _seg == reinterpret_cast<void *>(-1) ) { + throw shm_bad_alloc(); + } + + return _seg; +} + +} // detail + +template <int _Inst> +class shm_alloc +{ + protected: + typedef void * pointer; + typedef const void * const_pointer; + typedef typename detail::__shm_alloc<_Inst>::size_type size_type; + + struct _master + { + uint64_t _magic; + size_type _first; + xmt::__Mutex<false,true> _lock; + }; + + struct _fheader + { + size_type _sz; + size_type _next; + }; + + struct _aheader + { + size_type _sz; + }; + + enum { + __align = sizeof(int) + }; + + + public: + static void allocate( const char *name, size_type sz, int o, int mode, int f = 0, void *addr = 0 ) + { + _master *m = reinterpret_cast<_master *>( _seg.allocate( name, sz, o, mode, f, addr ) ); + if ( m->_magic != MAGIC ) { + init( *m ); + } + } + + static void allocate( key_t k, size_type sz, int o, int mode, int f = 0, void *addr = 0 ) + { + _master *m = reinterpret_cast<_master *>( _seg.allocate( k, sz, o, mode, f, addr ) ); + if ( m->_magic != MAGIC ) { + init( *m ); + } + } + + static void deallocate( bool force = false ) + { _seg.deallocate( force ); } + + size_type max_size() const throw() + { return _seg.max_size() == 0 ? 0 : (_seg.max_size() - sizeof(_master) - sizeof(_aheader)); } + + protected: + static void *allocate( size_type n, void *hint = 0 ) + { + _master *m = reinterpret_cast<_master *>( _seg.address() ); + if ( m != reinterpret_cast<_master *>(-1) ) { + xmt::__Locker<xmt::__Mutex<false,true> > lk( m->_lock ); + return _traverse( &m->_first, n ); + } + + throw shm_bad_alloc( -2 ); + + return 0; + } + + static void deallocate( pointer p, size_type n ); + static void *_traverse( size_type *_prev, size_type n ); + + private: + static void init( _master& m ) + { + m._magic = MAGIC; + new ( &m._lock ) xmt::__Mutex<false,true>(); + xmt::__Locker<xmt::__Mutex<false,true> > lk( m._lock ); + m._first = sizeof( _master ); + _fheader& h = *new ( reinterpret_cast<char *>(&m) + sizeof(_master) ) _fheader(); + h._next = 0; + h._sz = _seg.max_size() - sizeof( _master ) - sizeof( _aheader ); + } + + private: + static const uint64_t MAGIC; + static detail::__shm_alloc<_Inst> _seg; + + friend class detail::__shm_alloc<_Inst>; +}; + +template <int _Inst> +void shm_alloc<_Inst>::deallocate( pointer p, size_type n ) +{ + n += (__align - n % __align) % __align; + _master *m = reinterpret_cast<_master *>( _seg.address() ); + if ( m != reinterpret_cast<_master *>(-1) && (reinterpret_cast<char *>(p) - reinterpret_cast<char *>(_seg.address())) < (_seg.max_size() + sizeof(_master) + sizeof(_aheader) ) ) { + xmt::__Locker<xmt::__Mutex<false,true> > lk( m->_lock ); + _aheader *a = reinterpret_cast<_aheader *>( reinterpret_cast<char *>(p) - sizeof(_aheader) ); + size_type off = reinterpret_cast<char *>(p) - reinterpret_cast<char *>(_seg.address()); + if ( m->_first == 0 ) { + m->_first = off - sizeof(_aheader); + reinterpret_cast<_fheader *>(a)->_next = 0; + } else { + _fheader *h; + for ( h = reinterpret_cast<_fheader *>(reinterpret_cast<char *>(_seg.address()) + m->_first); h->_next != 0; + h = reinterpret_cast<_fheader *>(reinterpret_cast<char *>(_seg.address()) + h->_next) ) { + if ( h->_next < off ) { // the case h->_next == off is illegal, due to shift on sizeof(_aheader) + continue; + } + if ( reinterpret_cast<char *>(&h->_next) + h->_sz + sizeof(_aheader) == p ) { // attach to prev block + if ( h->_next == (off + a->_sz) ) { // glue with following free block + _fheader *nextheader = reinterpret_cast<_fheader *>(reinterpret_cast<char *>(_seg.address()) + h->_next); + h->_sz += a->_sz + sizeof(_aheader) * 2 + nextheader->_sz; + h->_next = nextheader->_next; + } else { + h->_sz += a->_sz + sizeof(_aheader); + } + } else if ( h->_next == (off + a->_sz) ) { // glue with following free block + _fheader *nextheader = reinterpret_cast<_fheader *>(reinterpret_cast<char *>(_seg.address()) + h->_next); + reinterpret_cast<_fheader *>(a)->_next = nextheader->_next; + reinterpret_cast<_fheader *>(a)->_sz += sizeof(_aheader) + nextheader->_sz; + } else { + reinterpret_cast<_fheader *>(a)->_next = h->_next; + h->_next = off - sizeof(_aheader); + } + return; + } + // before first free block or after last free block + // Note, that list of free blocks not empty here! + if ( off > (reinterpret_cast<char *>(h) - reinterpret_cast<char *>(_seg.address())) ) { // become last free block + if ( reinterpret_cast<pointer>(reinterpret_cast<char *>(h) + sizeof(_aheader) * 2 + h->_sz) == p ) { + // glue with last free block + h->_sz += a->_sz + sizeof(_aheader); + } else { + h->_next = off - sizeof(_aheader); + reinterpret_cast<_fheader *>(a)->_next = 0; + } + } else { // become first free block + if ( m->_first == off + a->_sz ) { // glue with next free block + _fheader *nextheader = reinterpret_cast<_fheader *>(reinterpret_cast<char *>(_seg.address()) + m->_first); + reinterpret_cast<_fheader *>(a)->_next = nextheader->_next; + reinterpret_cast<_fheader *>(a)->_sz += sizeof(_aheader) + nextheader->_sz; + } else { // link to next free block + reinterpret_cast<_fheader *>(a)->_next = m->_first; + } + m->_first = off - sizeof(_aheader); + } + } + } +} + +template <int _Inst> +void *shm_alloc<_Inst>::_traverse( size_type *_prev, size_type n ) +{ + n += (__align - n % __align) % __align; + for ( _fheader *h = reinterpret_cast<_fheader *>(reinterpret_cast<char *>(_seg.address()) + *_prev); *_prev != 0; + _prev = &h->_next, h = reinterpret_cast<_fheader *>(reinterpret_cast<char *>(_seg.address()) + *_prev)) { + if ( h->_sz > (n + sizeof( _fheader )) ) { // reduce this free block, write new free header + *_prev += n + sizeof( _aheader ); + _fheader *hnew = reinterpret_cast<_fheader *>(reinterpret_cast<char *>(_seg.address()) + *_prev ); + hnew->_sz = h->_sz - n - sizeof( _aheader ); + hnew->_next = h->_next; + reinterpret_cast<_aheader *>(h)->_sz = n; + return reinterpret_cast<void *>(reinterpret_cast<char *>(h) + sizeof( _aheader )); + } else if ( h->_sz >= n ) { // this block is too small to split it; use it in whole + *_prev = h->_next; + reinterpret_cast<_aheader *>(h)->_sz = h->_sz; + return reinterpret_cast<void *>(reinterpret_cast<char *>(h) + sizeof( _aheader )); + } + } + + throw shm_bad_alloc( -3 ); + + return 0; +} + + +template <int _Inst> +const uint64_t shm_alloc<_Inst>::MAGIC = 0xaa99665500000000ULL + _Inst; + +template <int _Inst> +detail::__shm_alloc<_Inst> shm_alloc<_Inst>::_seg; + +template <class _Tp, int _Inst> +class allocator_shm : + public shm_alloc<_Inst> +{ + public: + typedef shm_alloc<_Inst> chunk_type; + typedef _Tp value_type; + typedef _Tp* pointer; + typedef const _Tp* const_pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + template <class _Tp1, int _Inst1> + struct rebind + { + typedef allocator_shm<_Tp1, _Inst1> other; + }; + + allocator_shm() throw() + {} + + template <class _Tp1, int _Inst1> + allocator_shm(const allocator_shm<_Tp1, _Inst1>&) throw() + {} + + allocator_shm(const allocator_shm<_Tp,_Inst>&) throw() + {} + + // allocator_shm(__move_source<allocator_shm<_Tp> > src) throw() + // {} + + ~allocator_shm() throw() + {} + + pointer address(reference __x) const + {return &__x;} + + const_pointer address(const_reference __x) const + { return &__x; } + + // __n is permitted to be 0. The C++ standard says nothing about what the return value is when __n == 0. + _Tp* allocate( size_type __n, const void* = 0 ) + { + if ( __n > max_size() ) { + throw shm_bad_alloc(); + } + if ( __n != 0 ) { + return reinterpret_cast<_Tp *>( chunk_type::allocate( __n * sizeof(value_type) ) ); + } + return 0; + } + // __p is permitted to be a null pointer, only if n==0. + void deallocate( pointer __p, size_type __n ) + { + if ( __p != 0 ) { + chunk_type::deallocate( __p, __n * sizeof(value_type) ); + } + } + // backwards compatibility + void deallocate( pointer __p ) const + { + if ( __p != 0 ) { + chunk_type::deallocate( __p, sizeof(value_type) ); + } + } + + size_type max_size() const throw() + { return chunk_type::max_size() / sizeof(value_type); } + + void construct(pointer __p, const_reference __val) + { _STLP_STD::_Copy_Construct(__p, __val); } + + void destroy(pointer __p) + { _STLP_STD::_Destroy(__p); } + +}; + +} // namespace xmt + +#endif // __mt_shm_h Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2006-12-18 17:29:25 UTC (rev 1461) +++ trunk/complement/explore/lib/mt/ChangeLog 2006-12-26 16:13:00 UTC (rev 1462) @@ -1,3 +1,9 @@ +2006-12-26 Petr Ovtchenkov <pt...@is...> + + * shm.h, shm.cc: shared memory-based allocator + + * libxmt: version 1.9.4 + 2006-12-15 Petr Ovtchenkov <pt...@is...> * time.h, time.cc: add timespec in xmt namespace, useful Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2006-12-18 17:29:25 UTC (rev 1461) +++ trunk/complement/explore/lib/mt/Makefile.inc 2006-12-26 16:13:00 UTC (rev 1462) @@ -3,6 +3,6 @@ LIBNAME = xmt MAJOR = 1 MINOR = 9 -PATCH = 3 -SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc +PATCH = 4 +SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc SRC_C = fl.c Added: trunk/complement/explore/lib/mt/shm.cc =================================================================== --- trunk/complement/explore/lib/mt/shm.cc (rev 0) +++ trunk/complement/explore/lib/mt/shm.cc 2006-12-26 16:13:00 UTC (rev 1462) @@ -0,0 +1,64 @@ +// -*- C++ -*- Time-stamp: <06/12/20 11:44:26 ptr> + +/* + * Copyright (c) 2006 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License version 3.0 + * + */ + +#include <mt/shm.h> + +namespace xmt { + +const char *shm_bad_alloc::what() const throw() +{ + switch ( err ) { + case 0: + return "All fine"; + case EACCES: + return "Permission denied"; + case EBADF: + return "Bad file number"; + case EFAULT: + return "Bad address"; + case ELOOP: + return "Too many symbolic links encountered"; + case ENAMETOOLONG: + return "File name too long"; + case ENOENT: + return "No such file or directory or segment"; + case ENOMEM: + return "Out of memory"; + case ENOTDIR: + return "Not a directory"; + case EEXIST: + return "File exists"; + case EINVAL: + return "Invalid argument"; + case ENFILE: + return "File table overflow"; + case ENOSPC: + return "No space left on device"; + case EPERM: + return "Operation not permitted"; + case EIDRM: + return "Identifier removed"; + case EOVERFLOW: + return "Value too large for defined data type"; + + case -1: + return "Address already assigned"; + case -2: + return "Shared memory segment not allocated"; + case -3: + return "Not enough space left in shared memory segment"; + case -4: + return "Reference file exists"; + } + + return "unknown"; +} + +} // namespace xmt Modified: trunk/complement/explore/test/mt/Makefile =================================================================== --- trunk/complement/explore/test/mt/Makefile 2006-12-18 17:29:25 UTC (rev 1461) +++ trunk/complement/explore/test/mt/Makefile 2006-12-26 16:13:00 UTC (rev 1462) @@ -29,9 +29,9 @@ dbg-shared: LDSEARCH += -L${CoMT_LIB_DIR_DBG} -Wl,-R${CoMT_LIB_DIR_DBG}:${STLPORT_LIB_DIR} endif -release-shared : LDLIBS = -lxmt -lboost_test_utf -stldbg-shared : LDLIBS = -lxmtstlg -lboost_test_utfstlg -dbg-shared : LDLIBS = -lxmtg -lboost_test_utfg +release-shared : LDLIBS = -lxmt -lboost_test_utf -lboost_fs +stldbg-shared : LDLIBS = -lxmtstlg -lboost_test_utfstlg -lboost_fsstlg +dbg-shared : LDLIBS = -lxmtg -lboost_test_utfg -lboost_fsg ifeq ($(OSNAME),freebsd) release-shared : LDLIBS += -lthr Modified: trunk/complement/explore/test/mt/mt_test.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test.cc 2006-12-18 17:29:25 UTC (rev 1461) +++ trunk/complement/explore/test/mt/mt_test.cc 2006-12-26 16:13:00 UTC (rev 1462) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/18 20:00:15 ptr> +// -*- C++ -*- Time-stamp: <06/12/26 10:45:51 ptr> /* * Copyright (c) 2006 @@ -13,13 +13,22 @@ #include "mt_test.h" #include <mt/xmt.h> +#include <mt/shm.h> #include <sys/shm.h> #include <sys/wait.h> #include <signal.h> +#include <boost/filesystem/operations.hpp> +#include <boost/filesystem/path.hpp> + +#include <iostream> + +using namespace std; + using namespace boost::unit_test_framework; +namespace fs = boost::filesystem; void mt_test::fork() { @@ -137,3 +146,120 @@ shmdt( buf ); shmctl( id, IPC_RMID, &ds ); } + +void mt_test::shm_segment() +{ + const char fname[] = "/tmp/mt_test.shm"; + try { + xmt::detail::__shm_alloc<0> seg( 5000, 1024, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); + + BOOST_CHECK( seg.address() != reinterpret_cast<void *>(-1) ); + seg.deallocate(); + BOOST_CHECK( seg.address() == reinterpret_cast<void *>(-1) ); + + BOOST_REQUIRE( !fs::exists( fname ) ); + + seg.allocate( fname, 1024, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); + BOOST_CHECK( seg.address() != reinterpret_cast<void *>(-1) ); + seg.deallocate(); + BOOST_CHECK( seg.address() == reinterpret_cast<void *>(-1) ); + BOOST_CHECK( fs::exists( fname ) ); // well, now I don't remove ref file, because shm segment may be created with another way + + // not exclusive, should pass + seg.allocate( fname, 1024, xmt::shm_base::create, 0660 ); + BOOST_CHECK( seg.address() != reinterpret_cast<void *>(-1) ); + try { + // This instance has segment in usage, should throw + seg.allocate( fname, 1024, 0, 0660 ); + BOOST_CHECK( false ); + } + catch ( xmt::shm_bad_alloc& err ) { + BOOST_CHECK( true ); // Ok + } + + /* + + I will treat another instanse (<1>) as interface to another + segment, so this sample not work. + + try { + // But this is another instanse, it's ok: + xmt::detail::__shm_alloc<1> seg1( fname, 1024, 0, 0660 ); + BOOST_CHECK( seg1.address() != reinterpret_cast<void *>(-1) ); + // Don't call seg1.deallocate() here, it destroy + } + catch ( xmt::shm_bad_alloc& err ) { + BOOST_CHECK( false ); // Fail + } + */ + + seg.deallocate(); + BOOST_CHECK( seg.address() == reinterpret_cast<void *>(-1) ); + + // ---- + try { + // exclusive, should throw + seg.allocate( fname, 1024, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); + BOOST_CHECK( false ); // Fail, should throw + } + catch ( xmt::shm_bad_alloc& err ) { + BOOST_CHECK( true ); // Ok + } + BOOST_CHECK( fs::exists( fname ) ); + // ---- + + fs::remove( fname ); + } + catch ( xmt::shm_bad_alloc& err ) { + BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); + } +} + +void mt_test::shm_alloc() +{ + const char fname[] = "/tmp/mt_test.shm"; + try { + xmt::shm_alloc<0> seg; + + seg.allocate( fname, 7000, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); + + { + xmt::allocator_shm<char,0> shmall; + size_t sz = shmall.max_size(); + char *ch1 = shmall.allocate( 3500 ); + BOOST_CHECK( ch1 != 0 ); + char *ch2 = shmall.allocate( 3500 ); + BOOST_CHECK( ch2 != 0 ); + try { + char *ch3 = shmall.allocate( 8 * 1024 - 7000 ); + BOOST_CHECK( false ); + } + catch ( xmt::shm_bad_alloc& err ) { + BOOST_CHECK( true ); + } + shmall.deallocate( ch1, 3500 ); + ch1 = shmall.allocate( 3500 ); + BOOST_CHECK( ch1 != 0 ); + shmall.deallocate( ch2, 3500 ); + ch2 = shmall.allocate( 3500 ); + BOOST_CHECK( ch2 != 0 ); + shmall.deallocate( ch1, 3500 ); + shmall.deallocate( ch2, 3500 ); + ch1 = shmall.allocate( 7000 ); + BOOST_CHECK( ch1 != 0 ); + shmall.deallocate( ch1, 7000 ); + ch1 = shmall.allocate( sz ); + BOOST_CHECK( ch1 != 0 ); + shmall.deallocate( ch1, sz ); + ch1 = shmall.allocate( 7000 ); + BOOST_CHECK( ch1 != 0 ); + shmall.deallocate( ch1, 7000 ); + } + seg.deallocate(); + fs::remove( fname ); + } + catch ( xmt::shm_bad_alloc& err ) { + BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); + } +} + Modified: trunk/complement/explore/test/mt/mt_test.h =================================================================== --- trunk/complement/explore/test/mt/mt_test.h 2006-12-18 17:29:25 UTC (rev 1461) +++ trunk/complement/explore/test/mt/mt_test.h 2006-12-26 16:13:00 UTC (rev 1462) @@ -15,6 +15,8 @@ { void fork(); void pid(); + void shm_segment(); + void shm_alloc(); }; #endif // __MT_TEST_H Modified: trunk/complement/explore/test/mt/mt_test_suite.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test_suite.cc 2006-12-18 17:29:25 UTC (rev 1461) +++ trunk/complement/explore/test/mt/mt_test_suite.cc 2006-12-26 16:13:00 UTC (rev 1462) @@ -20,9 +20,14 @@ test_case *fork_tc = BOOST_CLASS_TEST_CASE( &mt_test::fork, instance ); test_case *pid_tc = BOOST_CLASS_TEST_CASE( &mt_test::pid, instance ); + test_case *shm_segment_tc = BOOST_CLASS_TEST_CASE( &mt_test::shm_segment, instance ); + test_case *shm_alloc_tc = BOOST_CLASS_TEST_CASE( &mt_test::shm_alloc, instance ); pid_tc->depends_on( fork_tc ); + shm_alloc_tc->depends_on( shm_segment_tc ); add( fork_tc ); add( pid_tc ); + add( shm_segment_tc ); + add( shm_alloc_tc ); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-01-26 15:43:51
|
Revision: 1481 http://svn.sourceforge.net/complement/?rev=1481&view=rev Author: complement Date: 2007-01-26 07:43:49 -0800 (Fri, 26 Jan 2007) Log Message: ----------- fix check-* targets; change link options to allow tests before install Modified Paths: -------------- trunk/complement/explore/lib/mt/Makefile trunk/complement/explore/lib/sockios/Makefile trunk/complement/explore/lib/stem/Makefile trunk/complement/explore/test/mt/Makefile trunk/complement/explore/test/sockios/Makefile trunk/complement/explore/test/stem/Makefile Modified: trunk/complement/explore/lib/mt/Makefile =================================================================== --- trunk/complement/explore/lib/mt/Makefile 2007-01-26 13:58:54 UTC (rev 1480) +++ trunk/complement/explore/lib/mt/Makefile 2007-01-26 15:43:49 UTC (rev 1481) @@ -7,22 +7,22 @@ INCLUDES += -I$(SRCROOT)/include -check: install +check: all-shared $(MAKE) -C ../../test/mt (cd ../../test/mt; ${OUTPUT_DIR}/mt_ut) || exit 1 (cd ../../test/mt; ${OUTPUT_DIR_DBG}/mt_ut) || exit 1 (cd ../../test/mt; ${OUTPUT_DIR_STLDBG}/mt_ut) || exit 1 -check-release: install-release-shared +check-release-shared: release-shared $(MAKE) -C ../../test/mt release-shared (cd ../../test/mt; ${OUTPUT_DIR}/mt_ut) || exit 1 -check-dbg: install-dbg-shared +check-dbg-shared: dbg-shared $(MAKE) -C ../../test/mt dbg-shared (cd ../../test/mt; ${OUTPUT_DIR_DBG}/mt_ut) || exit 1 ifndef WITHOUT_STLPORT -check-stldbg: install-stldbg-shared +check-stldbg-shared: stldbg-shared $(MAKE) -C ../../test/mt stldbg-shared (cd ../../test/mt; ${OUTPUT_DIR_STLDBG}/mt_ut) || exit 1 endif Modified: trunk/complement/explore/lib/sockios/Makefile =================================================================== --- trunk/complement/explore/lib/sockios/Makefile 2007-01-26 13:58:54 UTC (rev 1480) +++ trunk/complement/explore/lib/sockios/Makefile 2007-01-26 15:43:49 UTC (rev 1481) @@ -8,22 +8,22 @@ INCLUDES += -I$(SRCROOT)/include -check: install +check: all-shared $(MAKE) -C ../../test/sockios (cd ../../test/sockios; ${OUTPUT_DIR}/sockios_ut) || exit 1 (cd ../../test/sockios; ${OUTPUT_DIR_DBG}/sockios_ut) || exit 1 (cd ../../test/sockios; ${OUTPUT_DIR_STLDBG}/sockios_ut) || exit 1 -check-release: install-release-shared +check-release-shared: release-shared $(MAKE) -C ../../test/sockios release-shared (cd ../../test/sockios; ${OUTPUT_DIR}/sockios_ut) || exit 1 -check-dbg: install-dbg-shared +check-dbg-shared: dbg-shared $(MAKE) -C ../../test/sockios dbg-shared (cd ../../test/sockios; ${OUTPUT_DIR_DBG}/sockios_ut) || exit 1 ifndef WITHOUT_STLPORT -check-stldbg: install-stldbg-shared +check-stldbg-shared: stldbg-shared $(MAKE) -C ../../test/sockios stldbg-shared (cd ../../test/sockios; ${OUTPUT_DIR_STLDBG}/sockios_ut) || exit 1 endif Modified: trunk/complement/explore/lib/stem/Makefile =================================================================== --- trunk/complement/explore/lib/stem/Makefile 2007-01-26 13:58:54 UTC (rev 1480) +++ trunk/complement/explore/lib/stem/Makefile 2007-01-26 15:43:49 UTC (rev 1481) @@ -16,22 +16,22 @@ stldbg-shared: DEFS += -D__FIT_STEM_TRACE=1 endif -check: install +check: all-shared $(MAKE) -C ../../test/stem (cd ../../test/stem; ${OUTPUT_DIR}/stem_ut) || exit 1 (cd ../../test/stem; ${OUTPUT_DIR_DBG}/stem_ut) || exit 1 (cd ../../test/stem; ${OUTPUT_DIR_STLDBG}/stem_ut) || exit 1 -check-release: install-release-shared +check-release-shared: release-shared $(MAKE) -C ../../test/stem release-shared (cd ../../test/stem; ${OUTPUT_DIR}/stem_ut) || exit 1 -check-dbg: install-dbg-shared +check-dbg-shared: dbg-shared $(MAKE) -C ../../test/stem dbg-shared (cd ../../test/stem; ${OUTPUT_DIR_DBG}/stem_ut) || exit 1 ifndef WITHOUT_STLPORT -check-stldbg: install-stldbg-shared +check-stldbg-shared: stldbg-shared $(MAKE) -C ../../test/stem stldbg-shared (cd ../../test/stem; ${OUTPUT_DIR_STLDBG}/stem_ut) || exit 1 endif Modified: trunk/complement/explore/test/mt/Makefile =================================================================== --- trunk/complement/explore/test/mt/Makefile 2007-01-26 13:58:54 UTC (rev 1480) +++ trunk/complement/explore/test/mt/Makefile 2007-01-26 15:43:49 UTC (rev 1481) @@ -17,16 +17,20 @@ # RPATH := ${RPATH}:$(realpath ${STLPORT_LIB_DIR}):$(realpath /usr/lib) # endif +LIBMT_DIR = ${CoMT_DIR}/lib/mt +LIBUTF_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/test/unit_test_framework +LIBFS_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/filesystem + ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${CoMT_LIB_DIR} -Wl,--rpath=${CoMT_LIB_DIR}:${STLPORT_LIB_DIR} -stldbg-shared: LDSEARCH += -L${CoMT_LIB_DIR_STLDBG} -Wl,--rpath=${CoMT_LIB_DIR_STLDBG}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${CoMT_LIB_DIR_DBG} -Wl,--rpath=${CoMT_LIB_DIR_DBG}:${STLPORT_LIB_DIR} +release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBUTF_DIR}/${OUTPUT_DIR} -L${LIBFS_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBUTF_DIR}/${OUTPUT_DIR}:${LIBFS_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBUTF_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBFS_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBUTF_DIR}/${OUTPUT_DIR_STLDBG}:${LIBFS_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBUTF_DIR}/${OUTPUT_DIR_DBG} -L${LIBFS_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBUTF_DIR}/${OUTPUT_DIR_DBG}:${LIBFS_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} endif ifeq ($(OSNAME),openbsd) -release-shared: LDSEARCH += -L${CoMT_LIB_DIR} -Wl,-R${CoMT_LIB_DIR}:${STLPORT_LIB_DIR} -stldbg-shared: LDSEARCH += -L${CoMT_LIB_DIR_STLDBG} -Wl,-R${CoMT_LIB_DIR_STLDBG}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${CoMT_LIB_DIR_DBG} -Wl,-R${CoMT_LIB_DIR_DBG}:${STLPORT_LIB_DIR} +release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} endif release-shared : LDLIBS = -lxmt -lboost_test_utf -lboost_fs Modified: trunk/complement/explore/test/sockios/Makefile =================================================================== --- trunk/complement/explore/test/sockios/Makefile 2007-01-26 13:58:54 UTC (rev 1480) +++ trunk/complement/explore/test/sockios/Makefile 2007-01-26 15:43:49 UTC (rev 1481) @@ -9,10 +9,16 @@ INCLUDES += -I$(SRCROOT)/include -I$(BOOST_INCLUDE_DIR) -LDSEARCH += -L${CoMT_LIB_DIR} +LIBMT_DIR = ${CoMT_DIR}/lib/mt +LIBSOCK_DIR = ${CoMT_DIR}/lib/sockios +LIBUTF_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/test/unit_test_framework +ifeq ($(OSNAME),linux) +release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBUTF_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBUTF_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBUTF_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBUTF_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBUTF_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBUTF_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +endif + release-shared : LDLIBS = -lxmt -lsockios -lboost_test_utf stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lboost_test_utfstlg dbg-shared : LDLIBS = -lxmtg -lsockiosg -lboost_test_utfg - -LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR}:${CoMT_LIB_DIR} Modified: trunk/complement/explore/test/stem/Makefile =================================================================== --- trunk/complement/explore/test/stem/Makefile 2007-01-26 13:58:54 UTC (rev 1480) +++ trunk/complement/explore/test/stem/Makefile 2007-01-26 15:43:49 UTC (rev 1481) @@ -10,19 +10,25 @@ include Makefile.inc include ${SRCROOT}/Makefiles/top.mak - INCLUDES += -I$(SRCROOT)/include -I$(BOOST_INCLUDE_DIR) -LDSEARCH = -L${STLPORT_LIB_DIR} -L${CoMT_LIB_DIR} +LIBMT_DIR = ${CoMT_DIR}/lib/mt +LIBSOCK_DIR = ${CoMT_DIR}/lib/sockios +LIBSTEM_DIR = ${CoMT_DIR}/lib/stem +LIBUTF_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/test/unit_test_framework +ifeq ($(OSNAME),linux) +release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBUTF_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBUTF_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBUTF_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBUTF_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBUTF_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBUTF_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +endif + release-shared : LDLIBS = -lxmt -lsockios -lstem -lboost_test_utf -ldl stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lboost_test_utfstlg -ldl dbg-shared : LDLIBS = -lxmtg -lsockiosg -lstemg -lboost_test_utfg -ldl dbg-shared: DEFS += -DDEBUG -LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR}:${CoMT_LIB_DIR} - PHONY += dl dl-dbg dl-stldbg dl: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-01-30 15:05:06
|
Revision: 1484 http://svn.sourceforge.net/complement/?rev=1484&view=rev Author: complement Date: 2007-01-30 07:04:59 -0800 (Tue, 30 Jan 2007) Log Message: ----------- pass ipc flag as template parameter for Semaphor Modified Paths: -------------- trunk/complement/explore/include/mt/xmt.h trunk/complement/explore/lib/mt/xmt.cc Modified: trunk/complement/explore/include/mt/xmt.h =================================================================== --- trunk/complement/explore/include/mt/xmt.h 2007-01-26 15:44:50 UTC (rev 1483) +++ trunk/complement/explore/include/mt/xmt.h 2007-01-30 15:04:59 UTC (rev 1484) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <06/12/15 14:35:45 ptr> +// -*- C++ -*- Time-stamp: <07/01/29 18:58:49 ptr> /* - * Copyright (c) 1997-1999, 2002-2006 + * Copyright (c) 1997-1999, 2002-2007 * Petr Ovtchenkov * * Portion Copyright (c) 1999-2001 @@ -1266,27 +1266,28 @@ typedef __Condition<false> Condition; -class Semaphore +template <bool SCOPE> +class __Semaphore { public: - Semaphore( int cnt = 1, bool ipc = false ) + __Semaphore( int cnt = 1 ) { #ifdef __FIT_WIN32THREADS _sem = CreateSemaphore( NULL, cnt, INT_MAX, 0 ); // check! _cnt = cnt; #endif #ifdef __FIT_UITHREADS - sema_init( &_sem, cnt, ipc ? USYNC_PROCESS : USYNC_THREAD, 0 ); + sema_init( &_sem, cnt, SCOPE ? USYNC_PROCESS : USYNC_THREAD, 0 ); #endif #ifdef _PTHREADS - sem_init( &_sem, ipc ? 1 : 0, cnt ); + sem_init( &_sem, SCOPE ? 1 : 0, cnt ); #endif #ifdef __FIT_NOVELL_THREADS _sem = OpenLocalSemaphore( cnt ); #endif } - ~Semaphore() + ~__Semaphore() { #ifdef __FIT_WIN32THREADS CloseHandle( _sem ); @@ -1396,10 +1397,76 @@ LONG _sem; #endif private: - Semaphore( const Semaphore& ) + __Semaphore( const __Semaphore& ) { } }; +typedef __Semaphore<false> Semaphore; + +template <bool SCOPE> +int __Semaphore<SCOPE>::wait_time( const ::timespec *abstime ) // wait for time t, or signal +{ +#ifdef __FIT_WIN32THREADS + time_t ct = time( 0 ); + time_t _conv = abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000; + + unsigned ms = _conv >= ct ? _conv - ct : 1; + + if ( WaitForSingleObject( _sem, ms ) == WAIT_OBJECT_0 ) { + return 0; + } + return -1; +#endif +#ifdef __FIT_UITHREADS +#warning "Fix me!" +#endif +#ifdef _PTHREADS +# if !(defined(__FreeBSD__) || defined(__OpenBSD__)) + return sem_timedwait( &_sem, abstime ); +# else + return -1; // not implemented +# endif +#endif +#ifdef __FIT_NOVELL_THREADS + time_t ct = time( 0 ); + time_t _conv = abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000; + + unsigned ms = _conv >= ct ? _conv - ct : 1; + return TimedWaitOnLocalSemaphore( _sem, ms ); +#endif +} + +template <bool SCOPE> +int __Semaphore<SCOPE>::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; + + if ( WaitForSingleObject( _sem, ms ) == WAIT_OBJECT_0 ) { + return 0; + } + return -1; +#endif +#ifdef __FIT_UITHREADS +#warning "Fix me!" +#endif +#ifdef _PTHREADS + timespec st; + xmt::gettime( &st ); + st += *interval; +# if !(defined(__FreeBSD__) || defined(__OpenBSD__)) + return sem_timedwait( &_sem, &st ); +# else + return -1; // not implemented +# endif +#endif +#ifdef __FIT_NOVELL_THREADS + unsigned ms = interval->tv_sec * 1000 + interval->tv_nsec / 1000000; + return TimedWaitOnLocalSemaphore( _sem, ms ); +#endif +} + + __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 ); Modified: trunk/complement/explore/lib/mt/xmt.cc =================================================================== --- trunk/complement/explore/lib/mt/xmt.cc 2007-01-26 15:44:50 UTC (rev 1483) +++ trunk/complement/explore/lib/mt/xmt.cc 2007-01-30 15:04:59 UTC (rev 1484) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/15 14:39:47 ptr> +// -*- C++ -*- Time-stamp: <07/01/29 18:53:22 ptr> /* * Copyright (c) 1997-1999, 2002-2006 @@ -169,70 +169,6 @@ using std::endl; #endif - -__FIT_DECLSPEC -int Semaphore::wait_time( const ::timespec *abstime ) // wait for time t, or signal -{ -#ifdef __FIT_WIN32THREADS - time_t ct = time( 0 ); - time_t _conv = abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000; - - unsigned ms = _conv >= ct ? _conv - ct : 1; - - if ( WaitForSingleObject( _sem, ms ) == WAIT_OBJECT_0 ) { - return 0; - } - return -1; -#endif -#ifdef __FIT_UITHREADS -#warning "Fix me!" -#endif -#ifdef _PTHREADS -# if !(defined(__FreeBSD__) || defined(__OpenBSD__)) - return sem_timedwait( &_sem, abstime ); -# else - return -1; // not implemented -# endif -#endif -#ifdef __FIT_NOVELL_THREADS - time_t ct = time( 0 ); - time_t _conv = abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000; - - unsigned ms = _conv >= ct ? _conv - ct : 1; - return TimedWaitOnLocalSemaphore( _sem, ms ); -#endif -} - -__FIT_DECLSPEC -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; - - if ( WaitForSingleObject( _sem, ms ) == WAIT_OBJECT_0 ) { - return 0; - } - return -1; -#endif -#ifdef __FIT_UITHREADS -#warning "Fix me!" -#endif -#ifdef _PTHREADS - timespec st; - xmt::gettime( &st ); - st += *interval; -# if !(defined(__FreeBSD__) || defined(__OpenBSD__)) - return sem_timedwait( &_sem, &st ); -# else - return -1; // not implemented -# endif -#endif -#ifdef __FIT_NOVELL_THREADS - unsigned ms = interval->tv_sec * 1000 + interval->tv_nsec / 1000000; - return TimedWaitOnLocalSemaphore( _sem, ms ); -#endif -} - char *Init_buf[32]; int& Thread::Init::_count( detail::Init_count ); // trick to avoid friend declarations This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-01-30 15:06:45
|
Revision: 1485 http://svn.sourceforge.net/complement/?rev=1485&view=rev Author: complement Date: 2007-01-30 07:06:35 -0800 (Tue, 30 Jan 2007) Log Message: ----------- named object manager for shared memory segment Modified Paths: -------------- trunk/complement/explore/include/mt/shm.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/test/mt/mt_test.cc trunk/complement/explore/test/mt/mt_test.h trunk/complement/explore/test/mt/mt_test_suite.cc Modified: trunk/complement/explore/include/mt/shm.h =================================================================== --- trunk/complement/explore/include/mt/shm.h 2007-01-30 15:04:59 UTC (rev 1484) +++ trunk/complement/explore/include/mt/shm.h 2007-01-30 15:06:35 UTC (rev 1485) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <06/12/26 10:24:35 ptr> +// -*- C++ -*- Time-stamp: <07/01/29 18:59:35 ptr> /* - * Copyright (c) 2006 + * Copyright (c) 2006, 2007 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -69,6 +69,30 @@ typedef typename std::__type_traits<T>::is_POD_type is_ipc_sharable; }; +template <> +struct ipc_sharable<xmt::__Condition<true> > +{ + typedef std::__true_type is_ipc_sharable; +}; + +template <> +struct ipc_sharable<xmt::__Semaphore<true> > +{ + typedef std::__true_type is_ipc_sharable; +}; + +template <> +struct ipc_sharable<xmt::__Mutex<false,true> > +{ + typedef std::__true_type is_ipc_sharable; +}; + +template <> +struct ipc_sharable<xmt::__Mutex<true,true> > +{ + typedef std::__true_type is_ipc_sharable; +}; + template <int _Inst> class shm_alloc; namespace detail { @@ -277,11 +301,11 @@ if ( _last == 255 ) { throw std::range_error( "too many named objects" ); } - if ( (reinterpret_cast<void *>(&obj) <= shm_alloc<_Inst>::_seg.address()) || - (reinterpret_cast<void *>(&obj) > (reinterpret_cast<char *>(shm_alloc<_Inst>::_seg.address()) + + if ( (reinterpret_cast<const void *>(&obj) <= shm_alloc<_Inst>::_seg.address()) || + (reinterpret_cast<const void *>(&obj) > (reinterpret_cast<char *>(shm_alloc<_Inst>::_seg.address()) + shm_alloc<_Inst>::max_size() + - sizeof(shm_alloc<_Inst>::_master) + - sizeof(shm_alloc<_Inst>::_aheader) )) ) { + sizeof(typename shm_alloc<_Inst>::_master) + + sizeof(typename shm_alloc<_Inst>::_aheader) )) ) { throw std::invalid_argument( std::string("object beyond this shared segment") ); } for ( int i = 0; _nm_table[i].name != -1; ++i ) { @@ -290,7 +314,7 @@ } } _nm_table[_last].name = name; - _nm_table[_last].offset = reinterpret_cast<char *>(&obj) - reinterpret_cast<char *>(shm_alloc<_Inst>::_seg.address()); + _nm_table[_last].offset = reinterpret_cast<const char *>(&obj) - reinterpret_cast<char *>(shm_alloc<_Inst>::_seg.address()); _nm_table[_last].count = 1; ++_last; } @@ -444,6 +468,23 @@ static size_type max_size() throw() { return _seg.max_size() == 0 ? 0 : (_seg.max_size() - sizeof(_master) - sizeof(_aheader)); } + static shm_name_mgr<_Inst>& name_mgr() + { + pointer p = _seg.address(); + if ( p != reinterpret_cast<pointer>(-1) ) { + _master *m = reinterpret_cast<_master *>( p ); + if ( m->_nm == 0 ) { + xmt::__Locker<xmt::__Mutex<false,true> > lk( m->_lock ); + void *nm = _traverse( &m->_first, sizeof(shm_name_mgr<_Inst>) ); + m->_nm = reinterpret_cast<char *>(nm) - reinterpret_cast<char *>(p); + return *new ( nm ) shm_name_mgr<_Inst>(); + } + return *reinterpret_cast<shm_name_mgr<_Inst> *>(reinterpret_cast<char *>(p) + m->_nm); + } + + throw shm_bad_alloc( -2 ); + } + protected: static void *allocate( size_type n, void *hint = 0 ) { Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-01-30 15:04:59 UTC (rev 1484) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-01-30 15:06:35 UTC (rev 1485) @@ -1,3 +1,11 @@ +2007-01-30 Petr Ovtchenkov <pt...@is...> + + * shm.h: add named objects manager in shared segment + memory allocator; + + * xmt.h, xmt.cc: unification Semaphore with Condition + and Mutex---ipc flag passed as template parameter. + 2006-12-26 Petr Ovtchenkov <pt...@is...> * shm.h, shm.cc: shared memory-based allocator Modified: trunk/complement/explore/test/mt/mt_test.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test.cc 2007-01-30 15:04:59 UTC (rev 1484) +++ trunk/complement/explore/test/mt/mt_test.cc 2007-01-30 15:06:35 UTC (rev 1485) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/26 10:45:51 ptr> +// -*- C++ -*- Time-stamp: <07/01/29 15:35:05 ptr> /* * Copyright (c) 2006 @@ -288,3 +288,137 @@ } } + +/* + * This test is similar mt_test::fork() above, but instead plain shm_* + * functions it use allocator based on shared memory segment + */ +void mt_test::fork_shm() +{ + const char fname[] = "/tmp/mt_test.shm"; + try { + xmt::shm_alloc<0> seg; + + 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 ); + try { + xmt::fork(); + + try { + + // Child code + fcnd.try_wait(); + + } + catch ( ... ) { + } + + exit( 0 ); + } + catch ( xmt::fork_in_parent& child ) { + try { + BOOST_CHECK( child.pid() > 0 ); + + fcnd.set( true ); + + int stat; + BOOST_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + } + catch ( ... ) { + } + } + catch ( ... ) { + } + + (&fcnd)->~__Condition<true>(); + shm.deallocate( reinterpret_cast<char *>(&fcnd), sizeof(xmt::__Condition<true>) ); + seg.deallocate(); + fs::remove( fname ); + } + catch ( xmt::shm_bad_alloc& err ) { + BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); + } +} + +/* + * Test: how to take named object + */ +void mt_test::shm_named_obj() +{ + const char fname[] = "/tmp/mt_test.shm"; + enum { + test_Condition_Object = 1 + }; + try { + xmt::shm_alloc<0> seg; + + 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::__Condition<true>& fcnd = *new ( shm.allocate( 1 ) ) xmt::__Condition<true>(); + nm.named( fcnd, test_Condition_Object ); + fcnd.set( false ); + + try { + xmt::fork(); + + try { + + // Child code + xmt::shm_alloc<0> seg_ch; + + if ( seg_ch.max_size() == 0 ) { // just illustration, if seg and seg_ch + // (really xmt::shm_alloc<0>) + // in totally different address spaces + // in our case xmt::shm_name_mgr<0> instance derived from parent + // process + seg.allocate( fname, 4*4096, 0, 0660 ); + } + + 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 ); + } + catch ( const xmt::shm_bad_alloc& err ) { + BOOST_CHECK_MESSAGE( false, "Fail in child: " << err.what() ); + } + catch ( const std::invalid_argument& err ) { + BOOST_CHECK_MESSAGE( false, "Fail in child: " << err.what() ); + } + catch ( ... ) { + BOOST_CHECK_MESSAGE( false, "Fail in child" ); + } + + exit( 0 ); + } + catch ( xmt::fork_in_parent& child ) { + try { + BOOST_CHECK( child.pid() > 0 ); + + fcnd.try_wait(); + + int stat; + BOOST_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + } + catch ( ... ) { + BOOST_CHECK_MESSAGE( false, "Fail in parent" ); + } + } + catch ( ... ) { + BOOST_CHECK_MESSAGE( false, "Fail in fork" ); + } + + (&fcnd)->~__Condition<true>(); + shm.deallocate( &fcnd, 1 ); + seg.deallocate(); + fs::remove( fname ); + } + catch ( xmt::shm_bad_alloc& err ) { + BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); + } +} Modified: trunk/complement/explore/test/mt/mt_test.h =================================================================== --- trunk/complement/explore/test/mt/mt_test.h 2007-01-30 15:04:59 UTC (rev 1484) +++ trunk/complement/explore/test/mt/mt_test.h 2007-01-30 15:06:35 UTC (rev 1485) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/18 19:49:04 ptr> +// -*- C++ -*- Time-stamp: <07/01/29 13:49:41 ptr> /* * Copyright (c) 2006 @@ -17,6 +17,8 @@ void pid(); void shm_segment(); void shm_alloc(); + void fork_shm(); + void shm_named_obj(); }; #endif // __MT_TEST_H Modified: trunk/complement/explore/test/mt/mt_test_suite.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test_suite.cc 2007-01-30 15:04:59 UTC (rev 1484) +++ trunk/complement/explore/test/mt/mt_test_suite.cc 2007-01-30 15:06:35 UTC (rev 1485) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/18 19:58:56 ptr> +// -*- C++ -*- Time-stamp: <07/01/29 15:36:45 ptr> /* * Copyright (c) 2006 @@ -22,12 +22,18 @@ test_case *pid_tc = BOOST_CLASS_TEST_CASE( &mt_test::pid, instance ); test_case *shm_segment_tc = BOOST_CLASS_TEST_CASE( &mt_test::shm_segment, instance ); test_case *shm_alloc_tc = BOOST_CLASS_TEST_CASE( &mt_test::shm_alloc, instance ); + test_case *fork_shm_tc = BOOST_CLASS_TEST_CASE( &mt_test::fork_shm, instance ); + test_case *shm_nm_obj_tc = BOOST_CLASS_TEST_CASE( &mt_test::shm_named_obj, instance ); pid_tc->depends_on( fork_tc ); shm_alloc_tc->depends_on( shm_segment_tc ); + fork_shm_tc->depends_on( shm_alloc_tc ); + shm_nm_obj_tc->depends_on( fork_shm_tc ); add( fork_tc ); add( pid_tc ); add( shm_segment_tc ); add( shm_alloc_tc ); + add( fork_shm_tc, 0, 5 ); + add( shm_nm_obj_tc, 0, 5 ); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-01-31 08:03:17
|
Revision: 1489 http://svn.sourceforge.net/complement/?rev=1489&view=rev Author: complement Date: 2007-01-31 00:03:15 -0800 (Wed, 31 Jan 2007) Log Message: ----------- really erase iterators from _conn_pool; remove sockstream from processing, if it was closed during 'connect' processing. Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/lib/sockios/ChangeLog trunk/complement/explore/lib/sockios/Makefile.inc trunk/complement/explore/test/sockios/sockios_test.cc Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2007-01-30 15:14:56 UTC (rev 1488) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2007-01-31 08:03:15 UTC (rev 1489) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <06/12/15 01:27:36 ptr> +// -*- C++ -*- Time-stamp: <07/01/31 09:43:59 ptr> /* - * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 + * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 * Petr Ovtchenkov * * Portion Copyright (c) 1999-2001 @@ -100,6 +100,7 @@ // cerr << __FILE__ << ":" << __LINE__ << endl; // } if ( j->revents != 0 ) { + xmt::Locker _l( _c_lock ); // We should distinguish closed socket from income message typename container_type::iterator i = find_if( _M_c.begin(), _M_c.end(), bind2nd( _M_comp, j->fd ) ); @@ -114,7 +115,7 @@ i = _M_c.begin(); while ( (i = find_if( i, _M_c.end(), bind2nd( _M_comp, -1 ) )) != _M_c.end() ) { _dlock.lock(); - std::remove( _conn_pool.begin(), _conn_pool.end(), i ); + _conn_pool.erase( std::remove( _conn_pool.begin(), _conn_pool.end(), i ), _conn_pool.end() ); _dlock.unlock(); _M_c.erase( i++ ); } @@ -124,7 +125,7 @@ _pfd.erase( j ); j = _pfd.begin() + (d - 1); _dlock.lock(); - std::remove( _conn_pool.begin(), _conn_pool.end(), i ); + _conn_pool.erase( std::remove( _conn_pool.begin(), _conn_pool.end(), i ), _conn_pool.end() ); _dlock.unlock(); _M_c.erase( i ); } else { @@ -141,7 +142,7 @@ _pfd.erase( j ); j = _pfd.begin() + (d - 1); _dlock.lock(); - std::remove( _conn_pool.begin(), _conn_pool.end(), i ); + _conn_pool.erase( std::remove( _conn_pool.begin(), _conn_pool.end(), i ), _conn_pool.end() ); _dlock.unlock(); _M_c.erase( i ); } else { // normal data available for reading @@ -216,10 +217,10 @@ } try { - _Connect *cl_new; + xmt::Locker _l( _c_lock ); _M_c.push_back( _Connect() ); _M_c.back().open( _sd, addr.any ); - cl_new = &_M_c.back(); + _Connect *cl_new = &_M_c.back(); if ( cl_new->s.rdbuf()->in_avail() > 0 ) { // this is the case when user read from sockstream // in ctor above; push processing of this stream @@ -418,6 +419,13 @@ sock_base::socket_type rfd = stream.rdbuf()->fd(); ::write( me->_cfd, reinterpret_cast<const char *>(&rfd), sizeof(sock_base::socket_type) ); } + } else { + me->_dlock.lock(); + me->_conn_pool.erase( std::remove( me->_conn_pool.begin(), me->_conn_pool.end(), c ), me->_conn_pool.end() ); + me->_dlock.unlock(); + + xmt::Locker _l( me->_c_lock ); + me->_M_c.erase( c ); } } } Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2007-01-30 15:14:56 UTC (rev 1488) +++ trunk/complement/explore/include/sockios/sockmgr.h 2007-01-31 08:03:15 UTC (rev 1489) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/13 17:38:44 ptr> +// -*- C++ -*- Time-stamp: <07/01/31 08:55:49 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -289,7 +289,7 @@ _Sequence _M_c; _Compare _M_comp; pfd_equal _pfdcomp; - // xmt::Mutex _c_lock; + xmt::Mutex _c_lock; _fd_sequence _pfd; int _cfd; // sock_base::socket_type Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2007-01-30 15:14:56 UTC (rev 1488) +++ trunk/complement/explore/lib/sockios/ChangeLog 2007-01-31 08:03:15 UTC (rev 1489) @@ -1,3 +1,11 @@ +2007-01-31 Petr Ovtchenkov <pt...@is...> + + * sockmgr.h, sockmgr.cc: really erase iterators + from _conn_pool; remove sockstream from processing, + if it was closed during 'connect' processing. + + * libsockios: Version 1.10.2 + 2006-12-13 Petr Ovtchenkov <pt...@is...> * sockmgr.h, sockmgr.cc: container now single owner Modified: trunk/complement/explore/lib/sockios/Makefile.inc =================================================================== --- trunk/complement/explore/lib/sockios/Makefile.inc 2007-01-30 15:14:56 UTC (rev 1488) +++ trunk/complement/explore/lib/sockios/Makefile.inc 2007-01-31 08:03:15 UTC (rev 1489) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <06/11/29 18:47:25 ptr> +# -*- Makefile -*- Time-stamp: <07/01/31 10:07:17 ptr> LIBNAME = sockios MAJOR = 1 MINOR = 10 -PATCH = 1 +PATCH = 2 SRC_CC = _sockstream.cc _sockmgr.cc SRC_C = freebsd/getaddrinfo.c \ freebsd/ns_parse.c \ Modified: trunk/complement/explore/test/sockios/sockios_test.cc =================================================================== --- trunk/complement/explore/test/sockios/sockios_test.cc 2007-01-30 15:14:56 UTC (rev 1488) +++ trunk/complement/explore/test/sockios/sockios_test.cc 2007-01-31 08:03:15 UTC (rev 1489) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <07/01/30 11:45:52 ptr> +// -*- C++ -*- Time-stamp: <07/01/31 10:55:45 ptr> /* * - * Copyright (c) 2002, 2003, 2005, 2006 + * Copyright (c) 2002, 2003, 2005-2007 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -375,23 +375,23 @@ long_msg_processor::long_msg_processor( std::sockstream& ) { - cerr << "long_msg_processor::long_msg_processor" << endl; + // cerr << "long_msg_processor::long_msg_processor" << endl; } void long_msg_processor::connect( std::sockstream& s ) { - cerr << "long_msg_processor::connect" << endl; + // cerr << "long_msg_processor::connect" << endl; string l; getline( s, l ); - cerr << "Is good? " << s.good() << endl; + // cerr << "Is good? " << s.good() << endl; } void long_msg_processor::close() { - cerr << "long_msg_processor::close()" << endl; + // cerr << "long_msg_processor::close()" << endl; cnd->set( true ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-01-31 14:49:59
|
Revision: 1497 http://svn.sourceforge.net/complement/?rev=1497&view=rev Author: complement Date: 2007-01-31 06:49:58 -0800 (Wed, 31 Jan 2007) Log Message: ----------- sockmgr with select not maintained a long time: turn it off on linux Modified Paths: -------------- trunk/complement/explore/include/config/_linux.h trunk/complement/explore/test/sockios/unit_test.cc Modified: trunk/complement/explore/include/config/_linux.h =================================================================== --- trunk/complement/explore/include/config/_linux.h 2007-01-31 13:28:07 UTC (rev 1496) +++ trunk/complement/explore/include/config/_linux.h 2007-01-31 14:49:58 UTC (rev 1497) @@ -1,21 +1,10 @@ /* Time-stamp: <05/12/12 10:47:37 ptr> */ /* - * - * Copyright (c) 2003-2005 + * Copyright (c) 2003-2007 * Petr Ovtchenkov * - * Licensed under the Academic Free License Version 2.1 - * - * 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. - * + * Licensed under the Academic Free License Version 3.0 */ #ifndef __config__linux_h @@ -70,4 +59,10 @@ # error "__BYTE_ORDER neither __BIG_ENDIAN nor __LITTLE_ENDIAN; Fix me!" #endif +/* select-based socket manager not supported a long time, and produce errors on x64 + * I turn off usage of select +*/ + +#define __FIT_NO_SELECT + #endif /* __config__linux_h */ Modified: trunk/complement/explore/test/sockios/unit_test.cc =================================================================== --- trunk/complement/explore/test/sockios/unit_test.cc 2007-01-31 13:28:07 UTC (rev 1496) +++ trunk/complement/explore/test/sockios/unit_test.cc 2007-01-31 14:49:58 UTC (rev 1497) @@ -252,9 +252,9 @@ #endif } +#ifndef __FIT_NO_SELECT void test_client_server_select_local_ack() { -#ifndef __FIT_NO_POLL try { // server listen localhost (127.0.0.1), but not listen ext interface: sockmgr_stream_MP_SELECT<ConnectionProcessor> srv( 0x7f000001, port ); // start server @@ -269,10 +269,8 @@ BOOST_ERROR( "host not found by name" ); pr_lock.unlock(); } -#else - BOOST_ERROR( "poll-based sockmgr not implemented on this platform" ); -#endif } +#endif void udp_test_client_server_poll() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-02-01 10:00:23
|
Revision: 1500 http://svn.sourceforge.net/complement/?rev=1500&view=rev Author: complement Date: 2007-02-01 02:00:21 -0800 (Thu, 01 Feb 2007) Log Message: ----------- reduce amount of code; try to 'join' to already closed threads, wait other in loop Modified Paths: -------------- trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/thr_mgr.cc trunk/complement/explore/test/mt/mt_test_suite.cc Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-01-31 14:50:54 UTC (rev 1499) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-02-01 10:00:21 UTC (rev 1500) @@ -1,3 +1,12 @@ +2007-02-01 Petr Ovtchenkov <pt...@is...> + + * thr_mgr.cc: reduce amount of code; try to 'join' to already + closed threads, wait other in loop. [this is attempt to find + workaround for deadlock within glibc, but speedup release + already free resources too] + + * libxmt: version 1.9.5 + 2007-01-30 Petr Ovtchenkov <pt...@is...> * shm.h: add named objects manager in shared segment Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2007-01-31 14:50:54 UTC (rev 1499) +++ trunk/complement/explore/lib/mt/Makefile.inc 2007-02-01 10:00:21 UTC (rev 1500) @@ -1,8 +1,8 @@ -# -*- Makefile -*- Time-stamp: <06/11/29 01:59:50 ptr> +# -*- Makefile -*- Time-stamp: <07/02/01 11:14:39 ptr> LIBNAME = xmt MAJOR = 1 MINOR = 9 -PATCH = 4 +PATCH = 5 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/thr_mgr.cc =================================================================== --- trunk/complement/explore/lib/mt/thr_mgr.cc 2007-01-31 14:50:54 UTC (rev 1499) +++ trunk/complement/explore/lib/mt/thr_mgr.cc 2007-02-01 10:00:21 UTC (rev 1500) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <06/12/13 17:54:09 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 11:18:04 ptr> /* - * Copyright (c) 1997-1999, 2002, 2005, 2006 + * Copyright (c) 1997-1999, 2002, 2005-2007 * Petr Ovtchenkov * * Portion Copyright (c) 1999-2001 @@ -26,6 +26,25 @@ { return !__x->good(); } }; +struct rm_if_bad_thread : + public unary_function<Thread *,bool> +{ + bool operator()(Thread *__x); +}; + +bool rm_if_bad_thread::operator()(Thread *__x) +{ + if ( __x == 0 ) { + return true; + } + if ( !__x->good() ) { + __x->join(); + delete __x; + return true; + } + return false; +} + __FIT_DECLSPEC ThreadMgr::~ThreadMgr() { ThreadMgr::join(); @@ -33,70 +52,39 @@ __FIT_DECLSPEC void ThreadMgr::join() { - Locker lk( _lock ); - container_type::iterator i = _M_c.begin(); + // xmt::block_signal( SIGINT ); + // xmt::block_signal( SIGTERM ); + // xmt::block_signal( SIGPIPE ); + // xmt::block_signal( SIGCHLD ); + // xmt::block_signal( SIGPOLL ); - while ( i != _M_c.end() ) { - if ( (*i)->good() ) { - // (*i)->kill( SIGTERM ); - } - (*i)->join(); - delete *i; - _M_c.erase( i++ ); + Locker lk( _lock ); + _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); + while ( !_M_c.empty() ) { + xmt::delay( xmt::timespec(0,100000000) ); + _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); } } - __FIT_DECLSPEC void ThreadMgr::launch( Thread::entrance_type entrance, const void *p, size_t psz, unsigned flags, size_t stack_sz ) { - MT_REENTRANT( _lock, _x1 ); - container_type::iterator i = _M_c.begin(); - - while ( i != _M_c.end() ) { - if ( !(*i)->good() ) { - (*i)->join(); - delete *i; - _M_c.erase( i++ ); - } else { - ++i; - } - } - + Locker lk( _lock ); + _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); _M_c.push_back( new Thread( entrance, p, psz, flags, stack_sz ) ); } __FIT_DECLSPEC void ThreadMgr::garbage_collector() { - MT_REENTRANT( _lock, _x1 ); - container_type::iterator i = _M_c.begin(); - - while ( i != _M_c.end() ) { - if ( !(*i)->good() ) { - (*i)->join(); - delete *i; - _M_c.erase( i++ ); - } else { - ++i; - } - } + Locker lk( _lock ); + _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); } ThreadMgr::container_type::size_type ThreadMgr::size() { - MT_REENTRANT( _lock, _x1 ); - container_type::iterator i = _M_c.begin(); - - while ( i != _M_c.end() ) { - if ( !(*i)->good() ) { - (*i)->join(); - delete *i; - _M_c.erase( i++ ); - } else { - ++i; - } - } + Locker lk( _lock ); + _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); return _M_c.size(); } Modified: trunk/complement/explore/test/mt/mt_test_suite.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test_suite.cc 2007-01-31 14:50:54 UTC (rev 1499) +++ trunk/complement/explore/test/mt/mt_test_suite.cc 2007-02-01 10:00:21 UTC (rev 1500) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/01/29 15:36:45 ptr> +// -*- C++ -*- Time-stamp: <07/01/31 23:51:46 ptr> /* - * Copyright (c) 2006 + * Copyright (c) 2006, 2007 * Petr Ovtchenkov * * Licensed under the Academic Free License Version 3.0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-02-01 10:03:29
|
Revision: 1501 http://svn.sourceforge.net/complement/?rev=1501&view=rev Author: complement Date: 2007-02-01 02:03:27 -0800 (Thu, 01 Feb 2007) Log Message: ----------- clean container with sockstreams, to force 'close' call for all connections during server close process; try to block some signals during close Modified Paths: -------------- trunk/complement/explore/include/config/_linux.h trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/lib/sockios/ChangeLog trunk/complement/explore/test/sockios/sockios_test.cc Modified: trunk/complement/explore/include/config/_linux.h =================================================================== --- trunk/complement/explore/include/config/_linux.h 2007-02-01 10:00:21 UTC (rev 1500) +++ trunk/complement/explore/include/config/_linux.h 2007-02-01 10:03:27 UTC (rev 1501) @@ -1,10 +1,12 @@ -/* Time-stamp: <05/12/12 10:47:37 ptr> */ +/* Time-stamp: <07/01/31 23:51:12 ptr> */ /* + * * Copyright (c) 2003-2007 * Petr Ovtchenkov * - * Licensed under the Academic Free License Version 3.0 + * Licensed under the Academic Free License version 3.0 + * */ #ifndef __config__linux_h @@ -17,7 +19,7 @@ /* * Include this first, due to <features.h> unconditionally redefine * a lot of macros. -*/ + */ #include <features.h> @@ -59,9 +61,10 @@ # error "__BYTE_ORDER neither __BIG_ENDIAN nor __LITTLE_ENDIAN; Fix me!" #endif -/* select-based socket manager not supported a long time, and produce errors on x64 - * I turn off usage of select -*/ +/* + * select-based socket manager not maintained a long time, and produce + * errors on x86_64, so I turn off usage of select + */ #define __FIT_NO_SELECT Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2007-02-01 10:00:21 UTC (rev 1500) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2007-02-01 10:03:27 UTC (rev 1501) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/01/31 09:43:59 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 10:04:23 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -359,10 +359,17 @@ me->mgr.join(); + me->_M_c.clear(); // FIN still may not come yet; forse close + return rtc; // throw; } + xmt::block_signal( SIGINT ); + xmt::block_signal( SIGPIPE ); + xmt::block_signal( SIGCHLD ); + xmt::block_signal( SIGPOLL ); + me->_dlock.lock(); me->_follow = false; me->_pool_cnd.set( true, true ); @@ -377,6 +384,8 @@ me->mgr.join(); + me->_M_c.clear(); // FIN still may not come yet; forse close + return rtc; } @@ -456,6 +465,7 @@ } catch ( ... ) { } + return rtc; } Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2007-02-01 10:00:21 UTC (rev 1500) +++ trunk/complement/explore/include/sockios/sockmgr.h 2007-02-01 10:03:27 UTC (rev 1501) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/01/31 08:55:49 ptr> +// -*- C++ -*- Time-stamp: <07/01/31 23:52:05 ptr> /* - * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 + * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 * Petr Ovtchenkov * * Portion Copyright (c) 1999-2001 Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2007-02-01 10:00:21 UTC (rev 1500) +++ trunk/complement/explore/lib/sockios/ChangeLog 2007-02-01 10:03:27 UTC (rev 1501) @@ -1,3 +1,11 @@ +2007-02-01 Petr Ovtchenkov <pt...@is...> + + * sockmgr.cc: clean container with sockstreams, + to force 'close' call for all connections during server + close process; try to block some signals during close. + + * libsockios: Version 1.10.3 + 2007-01-31 Petr Ovtchenkov <pt...@is...> * sockmgr.h, sockmgr.cc: really erase iterators @@ -2,3 +10,3 @@ from _conn_pool; remove sockstream from processing, - if it was closed during 'connect' processing. + if it was closed during 'connect' processing; Modified: trunk/complement/explore/test/sockios/sockios_test.cc =================================================================== --- trunk/complement/explore/test/sockios/sockios_test.cc 2007-02-01 10:00:21 UTC (rev 1500) +++ trunk/complement/explore/test/sockios/sockios_test.cc 2007-02-01 10:03:27 UTC (rev 1501) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/01/31 10:55:45 ptr> +// -*- C++ -*- Time-stamp: <07/01/31 23:47:57 ptr> /* * @@ -141,7 +141,7 @@ { public: Cnt( sockstream& ) - { xmt::Locker lk(lock); ++cnt; } + { xmt::Locker lk(lock); ++cnt; ++visits; } ~Cnt() { xmt::Locker lk(lock); --cnt; } @@ -152,19 +152,22 @@ void close() { } + static int get_visits() + { xmt::Locker lk(lock); return visits; } + static xmt::Mutex lock; static int cnt; + static int visits; }; xmt::Mutex Cnt::lock; int Cnt::cnt = 0; +int Cnt::visits = 0; void sockios_test::ctor_dtor() { - // Check, that naumber of ctors of Cnt is the same as number of called dtors - // i.e. all created Cnt freed. - // due to async nature of communication, no way to check Cnt::cnt - // before server stop. + // Check, that number of ctors of Cnt is the same as number of called dtors + // i.e. all created Cnt was released. { sockmgr_stream_MP<Cnt> srv( port ); @@ -178,6 +181,12 @@ BOOST_CHECK( s1.good() ); BOOST_CHECK( s1.is_open() ); + while ( Cnt::get_visits() == 0 ) { + xmt::delay( xmt::timespec(0,10000) ); + } + Cnt::lock.lock(); + BOOST_CHECK( Cnt::cnt == 1 ); + Cnt::lock.unlock(); } srv.close(); @@ -185,9 +194,14 @@ Cnt::lock.lock(); BOOST_CHECK( Cnt::cnt == 0 ); + Cnt::visits = 0; Cnt::lock.unlock(); - } + + Cnt::lock.lock(); + BOOST_CHECK( Cnt::cnt == 0 ); + Cnt::lock.unlock(); + { sockmgr_stream_MP<Cnt> srv( port ); @@ -207,6 +221,12 @@ BOOST_CHECK( s1.is_open() ); BOOST_CHECK( s2.good() ); BOOST_CHECK( s2.is_open() ); + while ( Cnt::get_visits() < 2 ) { + xmt::delay( xmt::timespec(0,10000) ); + } + Cnt::lock.lock(); + BOOST_CHECK( Cnt::cnt == 2 ); + Cnt::lock.unlock(); } srv.close(); @@ -215,8 +235,11 @@ Cnt::lock.lock(); BOOST_CHECK( Cnt::cnt == 0 ); Cnt::lock.unlock(); - } + + Cnt::lock.lock(); + BOOST_CHECK( Cnt::cnt == 0 ); + Cnt::lock.unlock(); } class loader This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-02-01 17:23:08
|
Revision: 1502 http://svn.sourceforge.net/complement/?rev=1502&view=rev Author: complement Date: 2007-02-01 09:23:03 -0800 (Thu, 01 Feb 2007) Log Message: ----------- add 'signal' to thr_mgr---send signal to all good threads in pool; use fact, that thread's join in Thread destructor now. join in Thread destructor; timespec multiplication on double added Modified Paths: -------------- trunk/complement/explore/include/mt/thr_mgr.h trunk/complement/explore/include/mt/time.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/thr_mgr.cc trunk/complement/explore/lib/mt/time.cc trunk/complement/explore/lib/mt/xmt.cc Modified: trunk/complement/explore/include/mt/thr_mgr.h =================================================================== --- trunk/complement/explore/include/mt/thr_mgr.h 2007-02-01 10:03:27 UTC (rev 1501) +++ trunk/complement/explore/include/mt/thr_mgr.h 2007-02-01 17:23:03 UTC (rev 1502) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/13 17:41:15 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 18:39:25 ptr> /* * Copyright (c) 1997-1999, 2002, 2005, 2006 @@ -40,6 +40,7 @@ void launch( Thread::entrance_type entrance, const void *p = 0, size_t psz = 0, unsigned flags = 0, size_t stack_sz = 0 ); __FIT_DECLSPEC void garbage_collector(); __FIT_DECLSPEC void join(); + __FIT_DECLSPEC void signal( int ); container_type::size_type size(); Modified: trunk/complement/explore/include/mt/time.h =================================================================== --- trunk/complement/explore/include/mt/time.h 2007-02-01 10:03:27 UTC (rev 1501) +++ trunk/complement/explore/include/mt/time.h 2007-02-01 17:23:03 UTC (rev 1502) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/15 10:21:37 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 18:35:14 ptr> /* * Copyright (c) 2002, 2006 @@ -57,6 +57,7 @@ ::timespec operator /( const ::timespec& a, unsigned long b ); ::timespec operator *( const ::timespec& a, unsigned b ); ::timespec operator *( const ::timespec& a, unsigned long b ); +::timespec operator *( const ::timespec& a, double b ); inline ::timespec operator *( unsigned b, const ::timespec& a ) { return a * b; } inline ::timespec operator *( unsigned long b, const ::timespec& a ) @@ -69,6 +70,7 @@ ::timespec& operator /=( ::timespec& a, unsigned long b ); ::timespec& operator *=( ::timespec& a, unsigned b ); ::timespec& operator *=( ::timespec& a, unsigned long b ); +::timespec& operator *=( ::timespec& a, double b ); bool operator >( const ::timespec& a, const ::timespec& b ); bool operator >=( const ::timespec& a, const ::timespec& b ); Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-02-01 10:03:27 UTC (rev 1501) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-02-01 17:23:03 UTC (rev 1502) @@ -3,8 +3,14 @@ * thr_mgr.cc: reduce amount of code; try to 'join' to already closed threads, wait other in loop. [this is attempt to find workaround for deadlock within glibc, but speedup release - already free resources too] + already free resources too]; add 'signal'---send signal to all + good threads in pool; use fact, that thread's join in Thread + destructor now. + * xmt.cc: join in Thread destructor. + + * time.h, time.cc: timespec multiplication on double added. + * libxmt: version 1.9.5 2007-01-30 Petr Ovtchenkov <pt...@is...> Modified: trunk/complement/explore/lib/mt/thr_mgr.cc =================================================================== --- trunk/complement/explore/lib/mt/thr_mgr.cc 2007-02-01 10:03:27 UTC (rev 1501) +++ trunk/complement/explore/lib/mt/thr_mgr.cc 2007-02-01 17:23:03 UTC (rev 1502) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/01 11:18:04 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 20:17:50 ptr> /* * Copyright (c) 1997-1999, 2002, 2005-2007 @@ -15,8 +15,12 @@ #include <algorithm> #include <functional> +// #include <iostream> + namespace xmt { +// int _supercount = 0; + using namespace std; struct bad_thread : @@ -26,6 +30,13 @@ { return !__x->good(); } }; +struct good_thread : + public unary_function<Thread *,bool> +{ + bool operator()(const Thread *__x) const + { return (__x != 0) && (__x->good()); } +}; + struct rm_if_bad_thread : public unary_function<Thread *,bool> { @@ -37,14 +48,27 @@ if ( __x == 0 ) { return true; } - if ( !__x->good() ) { - __x->join(); + if ( __x->bad() ) { + // --_supercount; delete __x; return true; } return false; } +struct thread_signal : + public binary_function<Thread *,int,void> +{ + void operator()(const Thread *__x, int sig ) const; +}; + +void thread_signal::operator()(const Thread *__x, int sig ) const +{ + if ( __x != 0 ) { + const_cast<Thread *>(__x)->kill( sig ); + } +} + __FIT_DECLSPEC ThreadMgr::~ThreadMgr() { ThreadMgr::join(); @@ -58,12 +82,17 @@ // xmt::block_signal( SIGCHLD ); // xmt::block_signal( SIGPOLL ); - Locker lk( _lock ); + _lock.lock(); _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); while ( !_M_c.empty() ) { - xmt::delay( xmt::timespec(0,100000000) ); + _lock.unlock(); + xmt::delay( xmt::timespec(0,50000000) ); + _lock.lock(); _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); + // cerr << "### " << _supercount << " " << _M_c.size() << endl; } + // _supercount = 0; + _lock.unlock(); } __FIT_DECLSPEC @@ -72,6 +101,7 @@ Locker lk( _lock ); _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); _M_c.push_back( new Thread( entrance, p, psz, flags, stack_sz ) ); + // ++_supercount; } __FIT_DECLSPEC @@ -84,8 +114,17 @@ ThreadMgr::container_type::size_type ThreadMgr::size() { Locker lk( _lock ); - _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); - return _M_c.size(); + // ThreadMgr::container_type::size_type sz = count_if( _M_c.begin(), _M_c.end(), good_thread() ); + // cerr << "Sz: " << sz << endl; + + return count_if( _M_c.begin(), _M_c.end(), good_thread() ); } +__FIT_DECLSPEC void ThreadMgr::signal( int sig ) +{ + // cerr << "Signal!" << endl; + Locker lk( _lock ); + for_each( _M_c.begin(), _M_c.end(), bind2nd( thread_signal(), sig ) ); +} + } // namespace xmt Modified: trunk/complement/explore/lib/mt/time.cc =================================================================== --- trunk/complement/explore/lib/mt/time.cc 2007-02-01 10:03:27 UTC (rev 1501) +++ trunk/complement/explore/lib/mt/time.cc 2007-02-01 17:23:03 UTC (rev 1502) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/15 10:35:48 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 18:34:48 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -141,6 +141,16 @@ return c; } +timespec operator *( const timespec& a, double b ) +{ + timespec c; + double d = (a.tv_sec + 1.0e-9 * a.tv_nsec) * b; + + c.tv_nsec = static_cast<long>(1.0e9 * modf( d, &d ) + 0.5); + c.tv_sec = static_cast<time_t>(d); + return c; +} + timespec& operator +=( timespec& a, const timespec& b ) { a.tv_sec += b.tv_sec; @@ -210,6 +220,16 @@ return a; } +timespec& operator *=( timespec& a, double b ) +{ + double d = (a.tv_sec + 1.0e-9 * a.tv_nsec) * b; + + a.tv_nsec = static_cast<long>(1.0e9 * modf( d, &d ) + 0.5); + a.tv_sec = static_cast<time_t>(d); + + return a; +} + bool operator ==( const timespec& a, const timespec& b ) { return (a.tv_sec == b.tv_sec) && (a.tv_nsec == b.tv_nsec); Modified: trunk/complement/explore/lib/mt/xmt.cc =================================================================== --- trunk/complement/explore/lib/mt/xmt.cc 2007-02-01 10:03:27 UTC (rev 1501) +++ trunk/complement/explore/lib/mt/xmt.cc 2007-02-01 17:23:03 UTC (rev 1502) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/01/29 18:53:22 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 19:35:59 ptr> /* - * Copyright (c) 1997-1999, 2002-2006 + * Copyright (c) 1997-1999, 2002-2007 * Petr Ovtchenkov * * Portion Copyright (c) 1999-2001 @@ -363,6 +363,8 @@ __FIT_DECLSPEC Thread::Thread( Thread::entrance_type entrance, const void *p, size_t psz, unsigned __f, size_t stack_sz ) : + _id( bad_thread_id ), + _state( badbit ), _entrance( entrance ), _param( 0 ), _param_sz( 0 ), @@ -377,6 +379,7 @@ __FIT_DECLSPEC Thread::~Thread() { + Thread::join(); ((Init *)Init_buf)->~Init(); // _STLP_ASSERT( _id == bad_thread_id ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-02-01 17:24:53
|
Revision: 1503 http://svn.sourceforge.net/complement/?rev=1503&view=rev Author: complement Date: 2007-02-01 09:24:46 -0800 (Thu, 01 Feb 2007) Log Message: ----------- start connect_processor threads only from 'observer' thread; threads pool managed only from 'observer' thread; 'observer' thread not in threads pool, it start from 'loop'; libsockios: Version 1.10.4 Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/lib/sockios/ChangeLog trunk/complement/explore/lib/sockios/Makefile.inc Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2007-02-01 17:23:03 UTC (rev 1502) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2007-02-01 17:24:46 UTC (rev 1503) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/01 10:04:23 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 19:50:14 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -321,48 +321,31 @@ _Self_type *me = static_cast<_Self_type *>(p); me->loop_id.pword( _idx ) = me; // push pointer to self for signal processing xmt::Thread::ret_code rtc; + xmt::Thread::ret_code rtc_observer; rtc.iword = 0; + rtc_observer.iword = 0; + xmt::Thread thr_observer; + try { me->_loop_cnd.set( true ); me->_follow = true; - me->_observer_run = false; while ( (me->*me->_accept)() ) { - if ( me->mgr.size() < 2 ) { - me->mgr.launch( connect_processor, me ); + if ( thr_observer.bad() ) { + if ( thr_observer.is_join_req() ) { + rtc_observer = thr_observer.join(); + if ( rtc_observer.iword != 0 ) { + rtc.iword = -2; // there was connect_processor that was killed + } + } + thr_observer.launch( observer, me, 0, PTHREAD_STACK_MIN * 2 ); } - me->_orlock.lock(); - if ( !me->_observer_run ) { - me->_observer_run = true; - me->_orlock.unlock(); - me->mgr.launch( observer, me, 0, 0, PTHREAD_STACK_MIN * 2 ); - } else { - me->_orlock.unlock(); - } } } catch ( ... ) { - me->_dlock.lock(); - me->_follow = false; - me->_pool_cnd.set( true, true ); - me->_observer_cnd.set( true ); - me->_dlock.unlock(); - - // me->_c_lock.lock(); - ::close( me->_cfd ); - ::close( me->_pfd[1].fd ); - me->close(); - // me->_c_lock.unlock(); rtc.iword = -1; - - me->mgr.join(); - - me->_M_c.clear(); // FIN still may not come yet; forse close - - return rtc; - // throw; } xmt::block_signal( SIGINT ); @@ -381,11 +364,13 @@ ::close( me->_pfd[1].fd ); me->close(); // me->_c_lock.unlock(); + rtc_observer = thr_observer.join(); - me->mgr.join(); + me->_M_c.clear(); // FIN still may not come yet; force close + if ( rtc_observer.iword != 0 && rtc.iword == 0 ) { + rtc.iword = -2; // there was connect_processor that was killed + } - me->_M_c.clear(); // FIN still may not come yet; forse close - return rtc; } @@ -464,6 +449,7 @@ } while ( me->_is_follow() && idle_count < 2 ); } catch ( ... ) { + rtc.iword = -1; } return rtc; @@ -487,6 +473,10 @@ std::fill( pool_size, pool_size + 3, 0 ); try { + xmt::ThreadMgr mgr; + + mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); + do { // std::swap( pool_size[0], pool_size[1] ); std::rotate( pool_size, pool_size, pool_size + 3 ); @@ -496,37 +486,45 @@ tpop = me->_tpop; } if ( pool_size[2] != 0 ) { - if ( me->_thr_limit > me->mgr.size() ) { + if ( me->_thr_limit > mgr.size() ) { if ( (pool_size[0] - 2 * pool_size[1] + pool_size[2]) > 0 || - pool_size[2] > 32 + pool_size[2] > me->_thr_limit /* pool_size[1] > 3 && pool_size[0] <= pool_size[1] */ ) { // queue not empty and not decrease - me->mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); + mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); } else { 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 */ ); + mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); } } } + mgr.garbage_collector(); xmt::delay( &alarm ); } else { - if ( me->_observer_cnd.try_wait_delay( &idle ) != 0 ) { - MT_REENTRANT( me->_orlock, _1 ); - me->_observer_run = false; - + if ( /* me->_is_follow() && */ me->_observer_cnd.try_wait_delay( &idle ) != 0 && mgr.size() == 0 ) { return rtc; } } } while ( me->_is_follow() ); + + int count = 24; + while ( mgr.size() > 0 && count > 0 ) { + me->_pool_cnd.set( true, true ); + xmt::delay( &alarm ); + alarm *= 1.2; + --count; + } + if ( mgr.size() > 0 ) { + mgr.signal( SIGTERM ); + rtc.iword = -1; + } } catch ( ... ) { + rtc.iword = -1; } - MT_REENTRANT( me->_orlock, _1 ); - me->_observer_run = false; - return rtc; } Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2007-02-01 17:23:03 UTC (rev 1502) +++ trunk/complement/explore/include/sockios/sockmgr.h 2007-02-01 17:24:46 UTC (rev 1503) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/01/31 23:52:05 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 16:10:07 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -297,15 +297,11 @@ xmt::Condition _pool_cnd; xmt::Mutex _dlock; timespec _tpop; - xmt::ThreadMgr mgr; xmt::Mutex _flock; bool _follow; xmt::Condition _observer_cnd; - xmt::Mutex _orlock; - bool _observer_run; - timespec _busylimit; // start new thread to process incoming // requests, if processing thread busy // more then _busylimit Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2007-02-01 17:23:03 UTC (rev 1502) +++ trunk/complement/explore/lib/sockios/ChangeLog 2007-02-01 17:24:46 UTC (rev 1503) @@ -6,6 +6,13 @@ * libsockios: Version 1.10.3 + * sockmgr.h, sockmgr.cc: start connect_processor threads + only from 'observer' thread; threads pool managed only + from 'observer' thread; 'observer' thread not in threads + pool, it start from 'loop'; + + * libsockios: Version 1.10.4 + 2007-01-31 Petr Ovtchenkov <pt...@is...> * sockmgr.h, sockmgr.cc: really erase iterators Modified: trunk/complement/explore/lib/sockios/Makefile.inc =================================================================== --- trunk/complement/explore/lib/sockios/Makefile.inc 2007-02-01 17:23:03 UTC (rev 1502) +++ trunk/complement/explore/lib/sockios/Makefile.inc 2007-02-01 17:24:46 UTC (rev 1503) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <07/01/31 10:07:17 ptr> +# -*- Makefile -*- Time-stamp: <07/02/01 19:53:51 ptr> LIBNAME = sockios MAJOR = 1 MINOR = 10 -PATCH = 2 +PATCH = 4 SRC_CC = _sockstream.cc _sockmgr.cc SRC_C = freebsd/getaddrinfo.c \ freebsd/ns_parse.c \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-02-02 18:54:54
|
Revision: 1504 http://svn.sourceforge.net/complement/?rev=1504&view=rev Author: complement Date: 2007-02-02 10:54:52 -0800 (Fri, 02 Feb 2007) Log Message: ----------- remove _state field, unuseful; add thread id for RIP---_id used for living thread [and show that thread alive], while _rip_id used in join only libxmt: version 1.10.0 Modified Paths: -------------- trunk/complement/explore/include/mt/thr_mgr.h trunk/complement/explore/include/mt/xmt.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/thr_mgr.cc trunk/complement/explore/lib/mt/xmt.cc trunk/complement/explore/test/mt/mt_test.cc trunk/complement/explore/test/mt/mt_test.h trunk/complement/explore/test/mt/mt_test_suite.cc Modified: trunk/complement/explore/include/mt/thr_mgr.h =================================================================== --- trunk/complement/explore/include/mt/thr_mgr.h 2007-02-01 17:24:46 UTC (rev 1503) +++ trunk/complement/explore/include/mt/thr_mgr.h 2007-02-02 18:54:52 UTC (rev 1504) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/01 18:39:25 ptr> +// -*- C++ -*- Time-stamp: <07/02/02 20:54:44 ptr> /* * Copyright (c) 1997-1999, 2002, 2005, 2006 @@ -42,7 +42,7 @@ __FIT_DECLSPEC void join(); __FIT_DECLSPEC void signal( int ); - container_type::size_type size(); + container_type::size_type size() const; protected: _Sequence _M_c; Modified: trunk/complement/explore/include/mt/xmt.h =================================================================== --- trunk/complement/explore/include/mt/xmt.h 2007-02-01 17:24:46 UTC (rev 1503) +++ trunk/complement/explore/include/mt/xmt.h 2007-02-02 18:54:52 UTC (rev 1504) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/01/29 18:58:49 ptr> +// -*- C++ -*- Time-stamp: <07/02/02 21:32:58 ptr> /* * Copyright (c) 1997-1999, 2002-2007 @@ -1565,11 +1565,11 @@ static __FIT_DECLSPEC void signal_exit( int sig ); // signal handler bool good() const - { return (_state == goodbit) && (_id != bad_thread_id); } + { /* Locker lk( _llock ); */ return (_id != bad_thread_id); } bool bad() const - { return (_state != goodbit) || (_id == bad_thread_id); } - bool is_join_req() // if true, you can (and should) use join() - { return (_id != bad_thread_id) && ((_flags & (daemon | detached)) == 0); } + { /* Locker lk( _llock ); */ return (_id == bad_thread_id); } + bool is_join_req() const // if true, you can (and should) use join() + { /* Locker lk( _llock ); */ return (_rip_id != bad_thread_id) && ((_flags & (daemon | detached)) == 0); } __FIT_DECLSPEC bool is_self(); @@ -1597,6 +1597,8 @@ Thread( const Thread& ) { } + bool _not_run() const + { /* Locker lk( _llock ); */ return _id == bad_thread_id; } void _create( const void *p, size_t psz ) throw( std::runtime_error); static void *_call( void *p ); @@ -1617,12 +1619,11 @@ static int _idx; // user words index static int _self_idx; // user words index, that word point to self static Mutex _idx_lock; - static Mutex _start_lock; static thread_key_type& _mt_key; size_t uw_alloc_size; thread_id_type _id; - int _state; // state flags + thread_id_type _rip_id; #ifdef _PTHREADS # ifndef __hpux // sorry, POSIX threads don't have suspend/resume calls, so it should @@ -1641,7 +1642,7 @@ size_t _param_sz; unsigned _flags; size_t _stack_sz; // stack size, if not 0 - // Mutex _params_lock; --- no needs + // Mutex _llock; friend class Init; // extern "C", wrap for thread_create #ifdef __unix Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-02-01 17:24:46 UTC (rev 1503) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-02-02 18:54:52 UTC (rev 1504) @@ -1,3 +1,20 @@ +2007-02-02 Petr Ovtchenkov <pt...@is...> + + * xmt.h, xmt.cc: remove _state field, unuseful; add thread + id for RIP---_id used for living thread [and show that + thread alive], while _rip_id used in join only; this reflect + two independent [well, almost independent] states---thread + run/not run and thread require join/not require join. + When I trying to made all operations with _id and _rip_id + with MT guards, the speed of sockstreams was VERY slow, + so I remove ones; atomics in a few places? + Here remains one thing---what I should do, if I made few + Threads and then fork? + + * thr_mgr.cc: sync with changes in xmt[.h.cc]. + + * libxmt: version 1.10.0 + 2007-02-01 Petr Ovtchenkov <pt...@is...> * thr_mgr.cc: reduce amount of code; try to 'join' to already Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2007-02-01 17:24:46 UTC (rev 1503) +++ trunk/complement/explore/lib/mt/Makefile.inc 2007-02-02 18:54:52 UTC (rev 1504) @@ -1,8 +1,8 @@ -# -*- Makefile -*- Time-stamp: <07/02/01 11:14:39 ptr> +# -*- Makefile -*- Time-stamp: <07/02/02 20:56:56 ptr> LIBNAME = xmt MAJOR = 1 -MINOR = 9 -PATCH = 5 +MINOR = 10 +PATCH = 0 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/thr_mgr.cc =================================================================== --- trunk/complement/explore/lib/mt/thr_mgr.cc 2007-02-01 17:24:46 UTC (rev 1503) +++ trunk/complement/explore/lib/mt/thr_mgr.cc 2007-02-02 18:54:52 UTC (rev 1504) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/01 20:17:50 ptr> +// -*- C++ -*- Time-stamp: <07/02/02 20:55:08 ptr> /* * Copyright (c) 1997-1999, 2002, 2005-2007 @@ -17,6 +17,8 @@ // #include <iostream> +// extern int my_thr_cnt; + namespace xmt { // int _supercount = 0; @@ -48,14 +50,29 @@ if ( __x == 0 ) { return true; } + // cerr << (void *)__x << " "; if ( __x->bad() ) { + // cerr << "delete\n"; // --_supercount; delete __x; return true; } + // cerr << "?\n"; return false; } +struct rm_thread : + public unary_function<Thread *,bool> +{ + bool operator()(Thread *__x); +}; + +bool rm_thread::operator()(Thread *__x) +{ + delete __x; + return true; +} + struct thread_signal : public binary_function<Thread *,int,void> { @@ -82,14 +99,20 @@ // xmt::block_signal( SIGCHLD ); // xmt::block_signal( SIGPOLL ); + /* + * This 'soft' variant better, than walk through _M_c and call 'delete' + * (that assume join); following approach remain chance to see size() + * somewhere else, and, may be make some action, because it not block + * on join within lock all the time. + */ _lock.lock(); _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); while ( !_M_c.empty() ) { + // cerr << "### " << _supercount << " " << _M_c.size() << " " << my_thr_cnt << endl; _lock.unlock(); xmt::delay( xmt::timespec(0,50000000) ); _lock.lock(); _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); - // cerr << "### " << _supercount << " " << _M_c.size() << endl; } // _supercount = 0; _lock.unlock(); @@ -100,6 +123,8 @@ { Locker lk( _lock ); _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); + // Thread *t = new Thread( entrance, p, psz, flags, stack_sz ); + // cerr << (void *)t << " created\n"; _M_c.push_back( new Thread( entrance, p, psz, flags, stack_sz ) ); // ++_supercount; } @@ -111,7 +136,7 @@ _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); } -ThreadMgr::container_type::size_type ThreadMgr::size() +ThreadMgr::container_type::size_type ThreadMgr::size() const { Locker lk( _lock ); // ThreadMgr::container_type::size_type sz = count_if( _M_c.begin(), _M_c.end(), good_thread() ); Modified: trunk/complement/explore/lib/mt/xmt.cc =================================================================== --- trunk/complement/explore/lib/mt/xmt.cc 2007-02-01 17:24:46 UTC (rev 1503) +++ trunk/complement/explore/lib/mt/xmt.cc 2007-02-02 18:54:52 UTC (rev 1504) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/01 19:35:59 ptr> +// -*- C++ -*- Time-stamp: <07/02/02 21:34:56 ptr> /* * Copyright (c) 1997-1999, 2002-2007 @@ -230,7 +230,6 @@ int Thread::_idx = 0; int Thread::_self_idx = 0; Mutex Thread::_idx_lock; -Mutex Thread::_start_lock; #ifdef __FIT_WIN32THREADS const Thread::thread_id_type Thread::bad_thread_id = INVALID_HANDLE_VALUE; @@ -350,7 +349,7 @@ __FIT_DECLSPEC Thread::Thread( unsigned __f ) : _id( bad_thread_id ), - _state( badbit ), + _rip_id( bad_thread_id ), _entrance( 0 ), _param( 0 ), _param_sz( 0 ), @@ -364,7 +363,7 @@ __FIT_DECLSPEC Thread::Thread( Thread::entrance_type entrance, const void *p, size_t psz, unsigned __f, size_t stack_sz ) : _id( bad_thread_id ), - _state( badbit ), + _rip_id( bad_thread_id ), _entrance( entrance ), _param( 0 ), _param_sz( 0 ), @@ -373,6 +372,7 @@ uw_alloc_size( 0 ) { new( Init_buf ) Init(); + // Locker lk( _llock ); _create( p, psz ); } @@ -380,6 +380,14 @@ Thread::~Thread() { Thread::join(); + + if ( (_flags & (daemon | detached)) != 0 ) { // not joinable + // Locker lk( _llock ); + if ( _id != bad_thread_id ) { // still run? + cerr << "Crash on daemon thread exit expected, threas id " << _id << endl; + } + } + ((Init *)Init_buf)->~Init(); // _STLP_ASSERT( _id == bad_thread_id ); @@ -390,14 +398,15 @@ __FIT_DECLSPEC bool Thread::is_self() { + // Locker lk( _llock ); #ifdef _PTHREADS - return good() && (_id == pthread_self()); + return (_id != bad_thread_id) && (_id == pthread_self()); #elif defined(__FIT_UITHREADS) - return good() && (_id == thr_self()); + return (_id != bad_thread_id) && (_id == thr_self()); #elif defined(__FIT_NOVELL_THREADS) - return good() && (_id == GetThreadID()); + return (_id != bad_thread_id) && (_id == GetThreadID()); #elif defined(__FIT_WIN32THREADS) - return good() && (_id == GetCurrentThread()); + return (_id != bad_thread_id) && (_id == GetCurrentThread()); #else # error "Fix me! (replace pthread_self())" #endif @@ -406,8 +415,9 @@ __FIT_DECLSPEC void Thread::launch( entrance_type entrance, const void *p, size_t psz, size_t stack_sz ) { + // Locker lk( _llock ); _stack_sz = stack_sz; - if ( _id == bad_thread_id ) { + if ( _not_run() ) { _entrance = entrance; _create( p, psz ); } @@ -420,31 +430,34 @@ #ifdef __FIT_WIN32THREADS rt.iword = 0; - if ( _id != bad_thread_id ) { + if ( !_not_run() ) { WaitForSingleObject( _id, -1 ); GetExitCodeThread( _id, &rt.iword ); CloseHandle( _id ); + // Locker lk( _llock ); _id = bad_thread_id; } #endif // __FIT_WIN32THREADS #if defined(__FIT_UITHREADS) || defined(_PTHREADS) rt.pword = 0; - if ( _id != bad_thread_id && (_flags & (daemon | detached) ) == 0 ) { + if ( is_join_req() ) { # ifdef _PTHREADS - pthread_join( _id, &rt.pword ); + pthread_join( _rip_id, &rt.pword ); # endif # ifdef __FIT_UITHREADS - thr_join( _id, 0, &rt.pword ); + thr_join( _rip_id, 0, &rt.pword ); # endif - _id = bad_thread_id; + // Locker lk( _llock ); + _rip_id = bad_thread_id; } #endif // __FIT_UITHREADS || PTHREADS #ifdef __FIT_NOVELL_THREADS rt.iword = 0; - if ( _id != bad_thread_id ) { + if ( !_not_run() ) { _thr_join.wait(); - _id = bad_thread_id; + // Locker lk( _llock ); + _rip_id = bad_thread_id; } #endif // __FIT_NOVELL_THREADS @@ -454,7 +467,8 @@ __FIT_DECLSPEC int Thread::suspend() { - if ( _id != bad_thread_id ) { + if ( good() ) { + // to do: fix possible race with _id, when it used here #ifdef __FIT_WIN32THREADS return SuspendThread( _id ); #endif @@ -484,7 +498,8 @@ __FIT_DECLSPEC int Thread::resume() { - if ( _id != bad_thread_id ) { + if ( good() ) { + // to do: fix possible race with _id, when it used here #ifdef __FIT_WIN32THREADS return ResumeThread( _id ); #endif @@ -514,6 +529,8 @@ __FIT_DECLSPEC int Thread::kill( int sig ) { + // Locker lk( _llock ); + if ( _id != bad_thread_id ) { #ifdef __FIT_UITHREADS return thr_kill( _id, sig ); @@ -576,9 +593,11 @@ 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 + // Locker lk( me->_llock ); // !!!!??? in the signal handler? + me->_rip_id = me->_id = bad_thread_id; + } else { me->_id = bad_thread_id; } me->_dealloc_uw(); // clear user words @@ -750,38 +769,33 @@ // pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED ); // pthread_attr_setschedpolicy(&attr,SCHED_OTHER); } - // _start_lock.lock(); // allow finish new thread creation before this - // thread will start to run err = pthread_create( &_id, _flags != 0 || _stack_sz != 0 ? &attr : 0, _xcall, this ); - if ( err == 0 ) { - _state = goodbit; + if ( err != 0 ) { + _rip_id = _id = bad_thread_id; + } else { + _rip_id = _id; } - // _start_lock.unlock(); if ( _flags != 0 || _stack_sz != 0 ) { pthread_attr_destroy( &attr ); } #endif #ifdef __FIT_UITHREADS - // _start_lock.lock(); err = thr_create( 0, 0, _xcall, this, _flags, &_id ); - // _start_lock.unlock(); #endif #ifdef __FIT_WIN32THREADS - // _start_lock.lock(); - _id = CreateThread( 0, 0, _xcall, this, (_flags & suspended), &_thr_id ); + _rip_id = _id = CreateThread( 0, 0, _xcall, this, (_flags & suspended), &_thr_id ); err = GetLastError(); - // _start_lock.unlock(); #endif #ifdef __FIT_NOVELL_THREADS - // _start_lock.lock(); _id = BeginThread( _xcall, 0, 65536, this ); if ( _id == bad_thread_id ) { err = errno; // not ::errno, due to #define errno *__get_errno_ptr() if ( (_flags & detached) == 0 ) { _thr_join.signal(); } + } else { + _rip_id = _id; } - // _start_lock.unlock(); #endif if ( err != 0 ) { @@ -821,9 +835,7 @@ void *Thread::_call( void *p ) { - // _start_lock.lock(); // allow finish thread creation in parent thread Thread *me = static_cast<Thread *>(p); - // me->_state = goodbit; // After exit of me->_entrance, there is may be no more *me itself, // so it's members may be unaccessible. Don't use me->"*" after call @@ -854,29 +866,37 @@ // In most cases for Linux there are problems with signals processing, // so I don't set it default more // signal_handler( SIGTERM, signal_exit ); // set handler for sanity - // _start_lock.unlock(); try { ret = me->_entrance( _param ); - me->_state = badbit; + // I should make me->_id = bad_thread_id; here... // This is in conflict what I say in the begin of this function. // So don't delete Thread before it termination! if ( (me->_flags & (daemon | detached)) != 0 ) { // otherwise join expected + // Locker lk( me->_llock ); #ifdef __FIT_WIN32THREADS CloseHandle( me->_id ); #endif me->_id = bad_thread_id; + me->_rip_id = bad_thread_id; + } else { + // Locker lk( me->_llock ); + me->_id = bad_thread_id; } me->_dealloc_uw(); // free user words } catch ( std::exception& e ) { - me->_state = badbit; if ( (me->_flags & (daemon | detached)) != 0 ) { // otherwise join expected + // Locker lk( me->_llock ); #ifdef __FIT_WIN32THREADS CloseHandle( me->_id ); #endif me->_id = bad_thread_id; + me->_rip_id = bad_thread_id; + } else { + // Locker lk( me->_llock ); + me->_id = bad_thread_id; } me->_dealloc_uw(); // free user words #ifndef _WIN32 @@ -885,13 +905,18 @@ ret.iword = -1; } catch ( int sig ) { - me->_state = badbit; if ( (me->_flags & (daemon | detached)) != 0 ) { // otherwise join expected + // Locker lk( me->_llock ); #ifdef __FIT_WIN32THREADS CloseHandle( me->_id ); #endif me->_id = bad_thread_id; + me->_rip_id = bad_thread_id; + } else { + // Locker lk( me->_llock ); + me->_id = bad_thread_id; } + me->_dealloc_uw(); // free user words // const char *_sig_ = strsignal( sig ); #ifndef _WIN32 @@ -900,12 +925,16 @@ ret.iword = sig; } catch ( ... ) { - me->_state = badbit; if ( (me->_flags & (daemon | detached)) != 0 ) { // otherwise join expected + // Locker lk( me->_llock ); #ifdef __FIT_WIN32THREADS CloseHandle( me->_id ); #endif me->_id = bad_thread_id; + me->_rip_id = bad_thread_id; + } else { + // Locker lk( me->_llock ); + me->_id = bad_thread_id; } me->_dealloc_uw(); // free user words #ifndef _WIN32 Modified: trunk/complement/explore/test/mt/mt_test.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test.cc 2007-02-01 17:24:46 UTC (rev 1503) +++ trunk/complement/explore/test/mt/mt_test.cc 2007-02-02 18:54:52 UTC (rev 1504) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/01/29 15:35:05 ptr> +// -*- C++ -*- Time-stamp: <07/02/02 20:53:03 ptr> /* * Copyright (c) 2006 @@ -14,6 +14,7 @@ #include <mt/xmt.h> #include <mt/shm.h> +#include <mt/thr_mgr.h> #include <sys/shm.h> #include <sys/wait.h> @@ -422,3 +423,38 @@ BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); } } + + +static int my_thr_cnt = 0; +static xmt::Mutex lock; + +xmt::Thread::ret_code thread_mgr_entry_call( void * ) +{ + lock.lock(); + ++my_thr_cnt; + lock.unlock(); + + xmt::Thread::ret_code rt; + rt.iword = 0; + + lock.lock(); + --my_thr_cnt; + lock.unlock(); + + return rt; +} + +void mt_test::thr_mgr() +{ + xmt::ThreadMgr mgr; + + for ( int i = 0; i < 200; ++i ) { + mgr.launch( thread_mgr_entry_call, (void *)this, 0, 0, 0 ); + } + + // cerr << "Join!\n"; + mgr.join(); + + BOOST_CHECK( my_thr_cnt == 0 ); + BOOST_CHECK( mgr.size() == 0 ); +} Modified: trunk/complement/explore/test/mt/mt_test.h =================================================================== --- trunk/complement/explore/test/mt/mt_test.h 2007-02-01 17:24:46 UTC (rev 1503) +++ trunk/complement/explore/test/mt/mt_test.h 2007-02-02 18:54:52 UTC (rev 1504) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/01/29 13:49:41 ptr> +// -*- C++ -*- Time-stamp: <07/02/02 16:45:13 ptr> /* * Copyright (c) 2006 @@ -19,6 +19,7 @@ void shm_alloc(); void fork_shm(); void shm_named_obj(); + void thr_mgr(); }; #endif // __MT_TEST_H Modified: trunk/complement/explore/test/mt/mt_test_suite.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test_suite.cc 2007-02-01 17:24:46 UTC (rev 1503) +++ trunk/complement/explore/test/mt/mt_test_suite.cc 2007-02-02 18:54:52 UTC (rev 1504) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/01/31 23:51:46 ptr> +// -*- C++ -*- Time-stamp: <07/02/02 17:15:47 ptr> /* * Copyright (c) 2006, 2007 @@ -25,6 +25,8 @@ test_case *fork_shm_tc = BOOST_CLASS_TEST_CASE( &mt_test::fork_shm, instance ); test_case *shm_nm_obj_tc = BOOST_CLASS_TEST_CASE( &mt_test::shm_named_obj, instance ); + test_case *thr_mgr_tc = BOOST_CLASS_TEST_CASE( &mt_test::thr_mgr, instance ); + pid_tc->depends_on( fork_tc ); shm_alloc_tc->depends_on( shm_segment_tc ); fork_shm_tc->depends_on( shm_alloc_tc ); @@ -36,4 +38,6 @@ add( shm_alloc_tc ); add( fork_shm_tc, 0, 5 ); add( shm_nm_obj_tc, 0, 5 ); + + add( thr_mgr_tc ); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-02-05 10:05:51
|
Revision: 1506 http://svn.sourceforge.net/complement/?rev=1506&view=rev Author: complement Date: 2007-02-05 02:05:46 -0800 (Mon, 05 Feb 2007) Log Message: ----------- fix tags generation Modified Paths: -------------- trunk/complement/explore/Makefiles/gmake/depend.mak trunk/complement/explore/inquiry/STLport/multimap/Makefile Modified: trunk/complement/explore/Makefiles/gmake/depend.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/depend.mak 2007-02-05 08:58:40 UTC (rev 1505) +++ trunk/complement/explore/Makefiles/gmake/depend.mak 2007-02-05 10:05:46 UTC (rev 1506) @@ -1,4 +1,4 @@ -# Time-stamp: <07/01/23 14:58:21 ptr> +# Time-stamp: <07/02/05 12:57:11 ptr> # # Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 # Petr Ovtchenkov @@ -35,9 +35,9 @@ @cat -s $(_ALL_DEP) /dev/null > $(DEPENDS_COLLECTION) TAGS: $(OUTPUT_DIRS) ${_DASH_DEP} - @etags -i -m `cat -s $(_ALL_DEP) /dev/null | sed 's/^.*://;s/\\\\$$//' | uniq -u` + @cat -s $(_ALL_DEP) /dev/null | sed -e 's/^.*://;s/^ *//;s/\\$$//;s/ $$//;s/ /\n/g' | sort | uniq | xargs etags -i -m tags: $(OUTPUT_DIRS) ${_DASH_DEP} - @ctags -d --globals --declarations -t -w `cat -s $(_ALL_DEP) /dev/null | sed 's/^.*://;s/\\\\$$//' | uniq -u` + @cat -s $(_ALL_DEP) /dev/null | sed -e 's/^.*://;s/^ *//;s/\\$$//;s/ $$//;s/ /\n/g' | sort | uniq | ctags -d --globals --declarations -t -w -include $(DEPENDS_COLLECTION) Modified: trunk/complement/explore/inquiry/STLport/multimap/Makefile =================================================================== --- trunk/complement/explore/inquiry/STLport/multimap/Makefile 2007-02-05 08:58:40 UTC (rev 1505) +++ trunk/complement/explore/inquiry/STLport/multimap/Makefile 2007-02-05 10:05:46 UTC (rev 1506) @@ -2,6 +2,7 @@ SRCROOT := ../../.. COMPILER_NAME := gcc +STLPORT_DIR := /export/home/ptr/STLport.lab/STLport.5_0 include Makefile.inc include ${SRCROOT}/Makefiles/top.mak This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-02-06 10:14:03
|
Revision: 1510 http://svn.sourceforge.net/complement/?rev=1510&view=rev Author: complement Date: 2007-02-06 02:13:58 -0800 (Tue, 06 Feb 2007) Log Message: ----------- add Barrier; add yield; libxmt 1.10.1 Modified Paths: -------------- trunk/complement/explore/COPYRIGHTS trunk/complement/explore/include/mt/xmt.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/test/mt/Makefile.inc trunk/complement/explore/test/mt/mt_test.cc trunk/complement/explore/test/mt/mt_test.h trunk/complement/explore/test/mt/mt_test_suite.cc trunk/complement/explore/test/mt/unit_test.cc Removed Paths: ------------- trunk/complement/explore/test/mt/join.cc trunk/complement/explore/test/mt/mutex_test.cc trunk/complement/explore/test/mt/recursive_mutex.cc trunk/complement/explore/test/mt/spinlock_test.cc Modified: trunk/complement/explore/COPYRIGHTS =================================================================== --- trunk/complement/explore/COPYRIGHTS 2007-02-05 13:09:03 UTC (rev 1509) +++ trunk/complement/explore/COPYRIGHTS 2007-02-06 10:13:58 UTC (rev 1510) @@ -1,4 +1,4 @@ -Copyright (c) 1997-1999, 2001-2006 Petr Ovtchenkov +Copyright (c) 1997-1999, 2001-2007 Petr Ovtchenkov Portion Copyright (c) 1999-2001 Parallel Graphics Ltd. Modified: trunk/complement/explore/include/mt/xmt.h =================================================================== --- trunk/complement/explore/include/mt/xmt.h 2007-02-05 13:09:03 UTC (rev 1509) +++ trunk/complement/explore/include/mt/xmt.h 2007-02-06 10:13:58 UTC (rev 1510) @@ -39,6 +39,7 @@ # ifdef _PTHREADS # include <pthread.h> # include <semaphore.h> +# include <sched.h> # else # include <thread.h> # include <synch.h> @@ -1466,7 +1467,43 @@ #endif } +template <bool SCOPE> +class __Barrier +{ + public: + __Barrier( unsigned cnt = 2 ) + { +#ifdef _PTHREADS + pthread_barrierattr_t attr; + pthread_barrierattr_init( &attr ); + pthread_barrierattr_setpshared( &attr, SCOPE ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE ); + pthread_barrier_init( &_barr, &attr, cnt ); + pthread_barrierattr_destroy( &attr ); +#endif + } + ~__Barrier() + { +#ifdef _PTHREADS + pthread_barrier_destroy( &_barr ); +#endif + } + + int wait() + { +#ifdef _PTHREADS + return pthread_barrier_wait( &_barr ); +#endif + } + + private: +#ifdef _PTHREADS + pthread_barrier_t _barr; +#endif +}; + +typedef __Barrier<false> Barrier; + __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 ); @@ -1563,6 +1600,10 @@ static __FIT_DECLSPEC int join_all(); #endif static __FIT_DECLSPEC void signal_exit( int sig ); // signal handler +#if defined(_PTHREADS) + static int yield() + { return sched_yield(); } +#endif bool good() const { /* Locker lk( _llock ); */ return (_id != bad_thread_id); } Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-02-05 13:09:03 UTC (rev 1509) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-02-06 10:13:58 UTC (rev 1510) @@ -1,3 +1,9 @@ +2007-02-06 Petr Ovtchenkov <pt...@is...> + + * xmt.h: add Barrier; add yield; + + * libxmt: version 1.10.1 + 2007-02-02 Petr Ovtchenkov <pt...@is...> * xmt.h, xmt.cc: remove _state field, unuseful; add thread Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2007-02-05 13:09:03 UTC (rev 1509) +++ trunk/complement/explore/lib/mt/Makefile.inc 2007-02-06 10:13:58 UTC (rev 1510) @@ -3,6 +3,6 @@ LIBNAME = xmt MAJOR = 1 MINOR = 10 -PATCH = 0 +PATCH = 1 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc SRC_C = fl.c Modified: trunk/complement/explore/test/mt/Makefile.inc =================================================================== --- trunk/complement/explore/test/mt/Makefile.inc 2007-02-05 13:09:03 UTC (rev 1509) +++ trunk/complement/explore/test/mt/Makefile.inc 2007-02-06 10:13:58 UTC (rev 1510) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <06/12/16 00:37:10 ptr> +# -*- makefile -*- Time-stamp: <07/02/06 10:04:25 ptr> PRGNAME = mt_ut -SRC_CC = unit_test.cc timespec.cc mutex_test.cc spinlock_test.cc \ - recursive_mutex.cc join.cc signal-1.cc signal-2.cc signal-3.cc flck.cc lfs.cc \ +SRC_CC = unit_test.cc timespec.cc \ + signal-1.cc signal-2.cc signal-3.cc flck.cc lfs.cc \ mt_test.cc mt_test_suite.cc Deleted: trunk/complement/explore/test/mt/join.cc =================================================================== --- trunk/complement/explore/test/mt/join.cc 2007-02-05 13:09:03 UTC (rev 1509) +++ trunk/complement/explore/test/mt/join.cc 2007-02-06 10:13:58 UTC (rev 1510) @@ -1,48 +0,0 @@ -// -*- C++ -*- Time-stamp: <06/08/04 11:09:21 ptr> - -/* - * Copyright (c) 2003, 2006 - * Petr Ovtchenkov - * - * Licensed under the Academic Free License Version 2.1 - * - * 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> - -using namespace boost::unit_test_framework; - -#include <mt/xmt.h> - -using namespace xmt; - -static int x = 0; - -Thread::ret_code thread_entry_call( void * ) -{ - x = 1; - - Thread::ret_code rt; - rt.iword = 0; - - return rt; -} - -void join_test() -{ - BOOST_CHECK( x == 0 ); - - Thread t( thread_entry_call ); - - t.join(); - - BOOST_CHECK( x == 1 ); -} Modified: trunk/complement/explore/test/mt/mt_test.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test.cc 2007-02-05 13:09:03 UTC (rev 1509) +++ trunk/complement/explore/test/mt/mt_test.cc 2007-02-06 10:13:58 UTC (rev 1510) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/02/02 20:53:03 ptr> +// -*- C++ -*- Time-stamp: <07/02/06 10:36:47 ptr> /* - * Copyright (c) 2006 + * Copyright (c) 2006, 2007 * Petr Ovtchenkov * * Licensed under the Academic Free License Version 3.0 @@ -31,6 +31,334 @@ using namespace boost::unit_test_framework; namespace fs = boost::filesystem; +/* ****************************************************** + * Degenerative case: check that one thread pass throw + * own barrier. + */ +void mt_test::barrier() +{ + xmt::Barrier b( 1 ); + + b.wait(); +} + +/* ****************************************************** + * Start thread, join it. + */ + +static int x = 0; + +xmt::Thread::ret_code thread_entry_call( void * ) +{ + x = 1; + + xmt::Thread::ret_code rt; + rt.iword = 0; + + return rt; +} + +void mt_test::join_test() +{ + BOOST_CHECK( x == 0 ); + + xmt::Thread t( thread_entry_call ); + + t.join(); + + BOOST_CHECK( x == 1 ); +} + +/* ****************************************************** + * Start two threads, align ones on barrier, join. + */ + +xmt::Thread::ret_code thread2_entry_call( void *p ) +{ + xmt::Thread::ret_code rt; + rt.iword = 0; + + xmt::Barrier& b = *reinterpret_cast<xmt::Barrier *>(p); + b.wait(); + + return rt; +} + +void mt_test::barrier2() +{ + xmt::Barrier b; + + xmt::Thread t1( thread2_entry_call, &b ); + xmt::Thread t2( thread2_entry_call, &b ); + + t2.join(); + t1.join(); +} + +/* ****************************************************** + * Start two threads, align ones on barrier; one thread + * relinquish control to other; join (within Thread dtors) + */ + +xmt::Thread::ret_code thread3_entry_call( void *p ) +{ + xmt::Thread::ret_code rt; + rt.iword = 0; + + xmt::Barrier& b = *reinterpret_cast<xmt::Barrier *>(p); + b.wait(); + BOOST_CHECK( xmt::Thread::yield() == 0 ); + + return rt; +} + +void mt_test::yield() +{ + xmt::Barrier b; + + xmt::Thread t1( thread2_entry_call, &b ); + xmt::Thread t2( thread3_entry_call, &b ); + // .join()'s are in Thread's destructors +} + +/* ****************************************************** + * Test for plain mutex. + * + * Start two threads, align ones on barrier, thr2 relinquish + * control to thr1; + * thr1 acquire lock, try to yield control to thr2 (that + * should be blocked on m1); + * Correct order checked by values of x. + */ + +static xmt::Mutex m1; + +xmt::Thread::ret_code thr1( void *p ) +{ + xmt::Barrier& b = *reinterpret_cast<xmt::Barrier *>(p); + b.wait(); + + m1.lock(); + BOOST_CHECK( x == 0 ); + + xmt::Thread::yield(); + + BOOST_CHECK( x == 0 ); + x = 1; + + m1.unlock(); + + xmt::Thread::ret_code rt; + rt.iword = 0; + + return rt; +} + +xmt::Thread::ret_code thr2( void *p ) +{ + xmt::Barrier& b = *reinterpret_cast<xmt::Barrier *>(p); + b.wait(); + xmt::Thread::yield(); + + m1.lock(); + BOOST_CHECK( x == 1 ); + x = 2; + m1.unlock(); + + xmt::Thread::ret_code rt; + rt.iword = 0; + + return rt; +} + +void mt_test::mutex_test() +{ + x = 0; + xmt::Barrier b; + + xmt::Thread t1( thr1, &b ); + xmt::Thread t2( thr2, &b ); + + t1.join(); + t2.join(); + + BOOST_CHECK( x == 2 ); +} + +/* ****************************************************** + * Test for spinlocks. + * + * Start two threads, align ones on barrier, thr2 relinquish + * control to thr1; + * thr1 acquire lock, try to yield control to thr2 (that + * should be blocked on sl1); + * Correct order checked by values of x. + */ + +#ifdef __FIT_PTHREAD_SPINLOCK +static xmt::Spinlock sl1; + +xmt::Thread::ret_code thr1s( void *p ) +{ + xmt::Barrier& b = *reinterpret_cast<xmt::Barrier *>(p); + b.wait(); + + sl1.lock(); + BOOST_CHECK( x == 0 ); + + xmt::Thread::yield(); + + BOOST_CHECK( x == 0 ); + x = 1; + + sl1.unlock(); + + xmt::Thread::ret_code rt; + rt.iword = 0; + + return rt; +} + +xmt::Thread::ret_code thr2s( void *p ) +{ + xmt::Barrier& b = *reinterpret_cast<xmt::Barrier *>(p); + b.wait(); + xmt::Thread::yield(); + + sl1.lock(); + BOOST_CHECK( x == 1 ); + x = 2; + sl1.unlock(); + + xmt::Thread::ret_code rt; + rt.iword = 0; + + return rt; +} + +#endif + +void mt_test::spinlock_test() +{ +#ifdef __FIT_PTHREAD_SPINLOCK + x = 0; + xmt::Barrier b; + + xmt::Thread t1( thr1s, &b ); + xmt::Thread t2( thr2s, &b ); + + t1.join(); + t2.join(); + + BOOST_CHECK( x == 2 ); +#endif +} + +/* ****************************************************** */ + +/* + * Test for recursive-safe mutexes (detect deadlock) + * + * 1. Start thread 1. Acquire lock on m2. + * + * 2. Start thread 2. Yield control to thread 1, to be sure that thread 1 + * acquire lock on m2 first. Acquire lock on m2. + * Due to m2 locked in thread 1, waiting on m2.lock. + * + * 3. Thread 1 relinquish control to thread 2, to give it chance. + * + * 4. From thread 1 call function 'recursive', where acquire lock on m2, + * relinquish control to thread2, and then release m2. + * If mutex recursive-safe, function 'recursive' will finished correctly. + * Otherwise, deedlock will happen on m2.lock in 'recursive'. + * + * 5. Release m2 in thread 1. + * + * 6. Pass through m2 lock in thread 2. Call function 'recursive', + * where acquire lock on m2, relinquish control, and then release m2. See item 4 before. + * + * 7. Release m2 in thread 2. + * + * 8. Test finished. + * + */ + +xmt::__Mutex<true,false> m2; + +void recursive() +{ + m2.lock(); + + x = 2; + xmt::Thread::yield(); + BOOST_CHECK( x == 2 ); + + m2.unlock(); +} + +xmt::Thread::ret_code thr1r( void *p ) +{ + xmt::Barrier& b = *reinterpret_cast<xmt::Barrier *>(p); + b.wait(); + + m2.lock(); + + BOOST_CHECK( x == 0 ); + x = 1; + xmt::Thread::yield(); + BOOST_CHECK( x == 1 ); + recursive(); + BOOST_CHECK( x == 2 ); + x = 3; + + m2.unlock(); + + xmt::Thread::ret_code rt; + + rt.iword = 0; + + return rt; +} + +xmt::Thread::ret_code thr2r( void *p ) +{ + xmt::Barrier& b = *reinterpret_cast<xmt::Barrier *>(p); + b.wait(); + + xmt::Thread::yield(); + + m2.lock(); + + BOOST_CHECK( x == 3 ); + xmt::Thread::yield(); + recursive(); + BOOST_CHECK( x == 2 ); + + m2.unlock(); + + xmt::Thread::ret_code rt; + + rt.iword = 0; + + return rt; +} + +void mt_test::recursive_mutex_test() +{ + x = 0; + xmt::Barrier b; + + xmt::Thread t1( thr1r, &b ); + xmt::Thread t2( thr2r, &b ); + + t1.join(); + t2.join(); + + BOOST_CHECK( x == 2 ); +} + +/* ****************************************************** */ + void mt_test::fork() { shmid_ds ds; @@ -86,6 +414,8 @@ shmctl( id, IPC_RMID, &ds ); } +/* ****************************************************** */ + void mt_test::pid() { shmid_ds ds; @@ -148,6 +478,8 @@ shmctl( id, IPC_RMID, &ds ); } +/* ****************************************************** */ + void mt_test::shm_segment() { const char fname[] = "/tmp/mt_test.shm"; @@ -216,6 +548,8 @@ } } +/* ****************************************************** */ + void mt_test::shm_alloc() { const char fname[] = "/tmp/mt_test.shm"; @@ -290,7 +624,7 @@ } -/* +/* ****************************************************** * This test is similar mt_test::fork() above, but instead plain shm_* * functions it use allocator based on shared memory segment */ @@ -344,8 +678,8 @@ } } -/* - * Test: how to take named object +/* ****************************************************** + * Test: how to take named object in shared memory segment */ void mt_test::shm_named_obj() { @@ -425,13 +759,23 @@ } +/* ****************************************************** + * Thread pool (aka ThreadMgr) test. + * + * Start 200 threads under ThreadMgr; check that all threads + * started, check that all theads finished, no garbage in + * ThreadMgr remains. + */ + static int my_thr_cnt = 0; +static int my_thr_scnt = 0; static xmt::Mutex lock; xmt::Thread::ret_code thread_mgr_entry_call( void * ) { lock.lock(); ++my_thr_cnt; + ++my_thr_scnt; lock.unlock(); xmt::Thread::ret_code rt; @@ -455,6 +799,7 @@ // cerr << "Join!\n"; mgr.join(); + BOOST_CHECK( my_thr_scnt == 200 ); BOOST_CHECK( my_thr_cnt == 0 ); BOOST_CHECK( mgr.size() == 0 ); } Modified: trunk/complement/explore/test/mt/mt_test.h =================================================================== --- trunk/complement/explore/test/mt/mt_test.h 2007-02-05 13:09:03 UTC (rev 1509) +++ trunk/complement/explore/test/mt/mt_test.h 2007-02-06 10:13:58 UTC (rev 1510) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/02/02 16:45:13 ptr> +// -*- C++ -*- Time-stamp: <07/02/06 09:48:27 ptr> /* - * Copyright (c) 2006 + * Copyright (c) 2006, 2007 * Petr Ovtchenkov * * Licensed under the Academic Free License Version 3.0 @@ -11,8 +11,17 @@ #ifndef __MT_TEST_H #define __MT_TEST_H -struct mt_test +class mt_test { + public: + void barrier(); + void join_test(); + void barrier2(); + void yield(); + void mutex_test(); + void spinlock_test(); + void recursive_mutex_test(); + void fork(); void pid(); void shm_segment(); @@ -20,6 +29,10 @@ void fork_shm(); void shm_named_obj(); void thr_mgr(); + + private: + // static xmt::Thread::ret_code thread_entry_call( void * ); + // static int x; }; #endif // __MT_TEST_H Modified: trunk/complement/explore/test/mt/mt_test_suite.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test_suite.cc 2007-02-05 13:09:03 UTC (rev 1509) +++ trunk/complement/explore/test/mt/mt_test_suite.cc 2007-02-06 10:13:58 UTC (rev 1510) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/02 17:15:47 ptr> +// -*- C++ -*- Time-stamp: <07/02/06 10:06:37 ptr> /* * Copyright (c) 2006, 2007 @@ -11,6 +11,8 @@ #include "mt_test_suite.h" #include "mt_test.h" +#include <config/feature.h> + using namespace boost::unit_test_framework; mt_test_suite::mt_test_suite() : @@ -18,6 +20,15 @@ { boost::shared_ptr<mt_test> instance( new mt_test() ); + test_case *barrier_tc = BOOST_CLASS_TEST_CASE( &mt_test::barrier, instance ); + test_case *join_tc = BOOST_CLASS_TEST_CASE( &mt_test::join_test, instance ); + test_case *barrier2_tc = BOOST_CLASS_TEST_CASE( &mt_test::barrier2, instance ); + test_case *yield_tc = BOOST_CLASS_TEST_CASE( &mt_test::yield, instance ); + test_case *mutex_test_tc = BOOST_CLASS_TEST_CASE( &mt_test::mutex_test, instance ); +#ifdef __FIT_PTHREAD_SPINLOCK + test_case *spinlock_test_tc = BOOST_CLASS_TEST_CASE( &mt_test::spinlock_test, instance ); +#endif + test_case *recursive_mutex_test_tc = BOOST_CLASS_TEST_CASE( &mt_test::recursive_mutex_test, instance ); test_case *fork_tc = BOOST_CLASS_TEST_CASE( &mt_test::fork, instance ); test_case *pid_tc = BOOST_CLASS_TEST_CASE( &mt_test::pid, instance ); test_case *shm_segment_tc = BOOST_CLASS_TEST_CASE( &mt_test::shm_segment, instance ); @@ -27,11 +38,30 @@ test_case *thr_mgr_tc = BOOST_CLASS_TEST_CASE( &mt_test::thr_mgr, instance ); + barrier2_tc->depends_on( barrier_tc ); + barrier2_tc->depends_on( join_tc ); + yield_tc->depends_on( barrier2_tc ); + mutex_test_tc->depends_on( yield_tc ); +#ifdef __FIT_PTHREAD_SPINLOCK + spinlock_test_tc->depends_on( yield_tc ); +#endif + recursive_mutex_test_tc->depends_on( mutex_test_tc ); + pid_tc->depends_on( fork_tc ); shm_alloc_tc->depends_on( shm_segment_tc ); fork_shm_tc->depends_on( shm_alloc_tc ); shm_nm_obj_tc->depends_on( fork_shm_tc ); + add( barrier_tc, 0, 2 ); + add( join_tc ); + add( barrier2_tc, 0, 3 ); + add( yield_tc, 0, 3 ); + add( mutex_test_tc, 0, 3 ); +#ifdef __FIT_PTHREAD_SPINLOCK + add( spinlock_test_tc, 0, 3 ); +#endif + add( recursive_mutex_test_tc, 0, 3 ); + add( fork_tc ); add( pid_tc ); add( shm_segment_tc ); Deleted: trunk/complement/explore/test/mt/mutex_test.cc =================================================================== --- trunk/complement/explore/test/mt/mutex_test.cc 2007-02-05 13:09:03 UTC (rev 1509) +++ trunk/complement/explore/test/mt/mutex_test.cc 2007-02-06 10:13:58 UTC (rev 1510) @@ -1,121 +0,0 @@ -// -*- C++ -*- Time-stamp: <06/12/15 10:37:09 ptr> - -/* - * Copyright (c) 2002, 2003, 2006 - * Petr Ovtchenkov - * - * Licensed under the Academic Free License Version 3.0 - * - */ - -#include <boost/test/unit_test.hpp> - -using namespace boost::unit_test_framework; - -#include <mt/xmt.h> - -using namespace std; -using namespace xmt; - -static Mutex m1; - -static int v = 0; -static volatile int msync = 0; - -xmt::Thread::ret_code thr1( void * ) -{ - m1.lock(); - msync = 1; - BOOST_CHECK( v == 0 ); - - delay( xmt::timespec( 1, 0 ) ); - - BOOST_CHECK( v == 0 ); - v = 1; - - m1.unlock(); - - xmt::Thread::ret_code rt; - rt.iword = 0; - - return rt; -} - -xmt::Thread::ret_code thr2( void * ) -{ - int j = 0; - while ( !msync ) { - ++j; - } - m1.lock(); - BOOST_CHECK( v == 1); - v = 2; - m1.unlock(); - - xmt::Thread::ret_code rt; - rt.iword = 0; - - return rt; -} - -xmt::Thread::ret_code thr3( void * ) -{ - m1.lock(); - msync = 1; - - BOOST_CHECK( v == 0 ); - - delay( xmt::timespec( 1, 0 ) ); - - v = 1; - - m1.unlock(); - xmt::Thread::ret_code rt; - rt.iword = 0; - - return rt; -} - -xmt::Thread::ret_code thr4( void * ) -{ -#ifndef _WIN32 // no trylock - int j = 0; - while ( !msync ) { - ++j; - } - if ( m1.trylock() == 0 ) { - BOOST_CHECK( v == 1 ); - m1.unlock(); - BOOST_ERROR( "m1.trylock() return zero!" ); - } -#endif // _WIN32 - - xmt::Thread::ret_code rt; - rt.iword = 0; - - return rt; -} - - -void mutex_test() -{ - v = 0; - Thread t1( thr1 ); - Thread t2( thr2 ); - - t1.join(); - t2.join(); - - msync = 0; - - BOOST_CHECK( v == 2 ); - -#ifndef _WIN32 - v = 0; - Thread t3( thr3 ); - Thread t4( thr4 ); - - t3.join(); - t4.join(); -#endif // _WIN32 -} Deleted: trunk/complement/explore/test/mt/recursive_mutex.cc =================================================================== --- trunk/complement/explore/test/mt/recursive_mutex.cc 2007-02-05 13:09:03 UTC (rev 1509) +++ trunk/complement/explore/test/mt/recursive_mutex.cc 2007-02-06 10:13:58 UTC (rev 1510) @@ -1,170 +0,0 @@ -// -*- C++ -*- Time-stamp: <06/12/15 10:39:45 ptr> - -/* - * Copyright (c) 2003, 2006 - * Petr Ovtchenkov - * - * Licensed under the Academic Free License Version 3.0 - * - */ - - -/* - * Test for recursive-safe mutexes (detect deadlock) - * - * 1. Start thread 1. Acquire lock on m. Sleep hread 1 sec. - * - * 2. Start thread 2. Acquire lock on m. Due to m locked - * in thread 1, waiting on m.lock. - * - * 3. From thread 1 call function 'recursive', where acquire lock on m, - * sleep 1 sec, and release m. - * If mutex recursive-safe, function 'recursive' will finished correctly. - * Otherwise, deedlock will happen on m.lock in 'recursive'. - * - * 4. Release m in thread 1. - * - * 5. Pass through m lock in thread 2. Call function 'recursive', - * where acquire lock on m, sleep 1 sec, and release m. See item 3 before. - * - * 6. Release m in thread 2. - * - * 7. Program finished. - * - */ - -#include <boost/test/unit_test.hpp> - -using namespace boost::unit_test_framework; - -#include <mt/xmt.h> -#include <iostream> - -using namespace xmt; -using namespace std; - -// Mutex pm; - -__Mutex<true,false> m; -static int v = 0; - -void recursive() -{ - // pm.lock(); - // cerr << "before lock recursive" << endl; - // pm.unlock(); - - m.lock(); - v = 2; - - xmt::sleep( xmt::timespec(1,0) ); - BOOST_CHECK( v == 2 ); - m.unlock(); - - // pm.lock(); - // cerr << "after lock recursive" << endl; - // pm.unlock(); -} - -Thread::ret_code thread_one( void * ) -{ - // pm.lock(); - // cerr << "before lock in thread one" << endl; - // pm.unlock(); - - m.lock(); - - BOOST_CHECK( v == 0 ); - - v = 1; - - // pm.lock(); - // cerr << "after lock in thread one" << endl; - // pm.unlock(); - - xmt::sleep( xmt::timespec(1,0) ); - - BOOST_CHECK( v == 1 ); - - recursive(); - - // pm.lock(); - // cerr << "before unlock in thread one" << endl; - // pm.unlock(); - - BOOST_CHECK( v == 2 ); - - v = 3; - - m.unlock(); - - // pm.lock(); - // cerr << "after unlock in thread one" << endl; - // pm.unlock(); - - Thread::ret_code rt; - - rt.iword = 0; - - return rt; -} - -Thread::ret_code thread_two( void * ) -{ - // pm.lock(); - // cerr << "before lock in thread two" << endl; - // pm.unlock(); - - m.lock(); - - // pm.lock(); - // cerr << "after lock in thread two" << endl; - // pm.unlock(); - BOOST_CHECK( v == 3 ); - - xmt::sleep( xmt::timespec(1,0) ); - recursive(); - - // pm.lock(); - // cerr << "before unlock in thread two" << endl; - // pm.unlock(); - - BOOST_CHECK( v == 2 ); - - m.unlock(); - - // pm.lock(); - // cerr << "after unlock in thread two" << endl; - // pm.unlock(); - - Thread::ret_code rt; - - rt.iword = 0; - - return rt; -} - - -void recursive_mutex_test() -{ - // pm.lock(); - // cerr << "main: create thread one" << endl; - // pm.unlock(); - - Thread t1( thread_one ); - - // pm.lock(); - // cerr << "main: create thread two" << endl; - // pm.unlock(); - - Thread t2( thread_two ); - - t1.join(); - t2.join(); - - // pm.lock(); - // cerr << "main: End" << endl; - // pm.unlock(); - - // return 0; -} Deleted: trunk/complement/explore/test/mt/spinlock_test.cc =================================================================== --- trunk/complement/explore/test/mt/spinlock_test.cc 2007-02-05 13:09:03 UTC (rev 1509) +++ trunk/complement/explore/test/mt/spinlock_test.cc 2007-02-06 10:13:58 UTC (rev 1510) @@ -1,106 +0,0 @@ -// -*- C++ -*- Time-stamp: <06/12/15 10:38:16 ptr> - -/* - * Copyright (c) 2002, 2003, 2006 - * Petr Ovtchenkov - * - * Licensed under the Academic Free License Version 3.0 - * - */ - -#include <boost/test/unit_test.hpp> - -using namespace boost::unit_test_framework; - -#include <mt/xmt.h> - -using namespace std; -using namespace xmt; - -static int v = 0; - -#ifdef __FIT_PTHREAD_SPINLOCK -static Spinlock sl1; - -xmt::Thread::ret_code thr1_sl( void * ) -{ - sl1.lock(); - BOOST_CHECK( v == 0 ); - - delay( xmt::timespec( 1, 0 ) ); - - BOOST_CHECK( v == 0 ); - v = 1; - - sl1.unlock(); - - xmt::Thread::ret_code rt; - rt.iword = 0; - - return rt; -} - -xmt::Thread::ret_code thr2_sl( void * ) -{ - sl1.lock(); - BOOST_CHECK( v == 1); - v = 2; - sl1.unlock(); - - xmt::Thread::ret_code rt; - rt.iword = 0; - - return rt; -} - -xmt::Thread::ret_code thr3_sl( void * ) -{ - sl1.lock(); - - BOOST_CHECK( v == 0 ); - - delay( xmt::timespec( 1, 0 ) ); - - v = 1; - - sl1.unlock(); - - xmt::Thread::ret_code rt; - rt.iword = 0; - - return rt; -} - -xmt::Thread::ret_code thr4_sl( void * ) -{ - if ( sl1.trylock() == 0 ) { - BOOST_CHECK( v == 1 ); - sl1.unlock(); - BOOST_ERROR( "m1.trylock() return zero!" ); - } - - xmt::Thread::ret_code rt; - rt.iword = 0; - - return rt; -} - -void spinlock_test() -{ - v = 0; - Thread t1( thr1_sl ); - Thread t2( thr2_sl ); - - t1.join(); - t2.join(); - - BOOST_CHECK( v == 2 ); - - v = 0; - Thread t3( thr3_sl ); - Thread t4( thr4_sl ); - - t3.join(); - t4.join(); -} -#endif // __FIT_PTHREAD_SPINLOCK Modified: trunk/complement/explore/test/mt/unit_test.cc =================================================================== --- trunk/complement/explore/test/mt/unit_test.cc 2007-02-05 13:09:03 UTC (rev 1509) +++ trunk/complement/explore/test/mt/unit_test.cc 2007-02-06 10:13:58 UTC (rev 1510) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/16 00:36:47 ptr> +// -*- C++ -*- Time-stamp: <07/02/06 10:08:47 ptr> /* * Copyright (c) 2002, 2003, 2004, 2006 @@ -16,12 +16,6 @@ using namespace boost::unit_test_framework; void timespec_diff(); -void join_test(); -void mutex_test(); -#ifdef __FIT_PTHREAD_SPINLOCK -void spinlock_test(); -#endif // __FIT_PTHREAD_SPINLOCK -void recursive_mutex_test(); void signal_1_test(); void signal_2_test(); void signal_3_test(); @@ -38,12 +32,6 @@ test_suite *ts = BOOST_TEST_SUITE( "libxmt test" ); ts->add( BOOST_TEST_CASE( ×pec_diff ) ); - ts->add( BOOST_TEST_CASE( &join_test ) ); - ts->add( BOOST_TEST_CASE( &mutex_test ) ); -#ifdef __FIT_PTHREAD_SPINLOCK - ts->add( BOOST_TEST_CASE( &spinlock_test ) ); -#endif - ts->add( BOOST_TEST_CASE( &recursive_mutex_test ) ); ts->add( BOOST_TEST_CASE( &signal_1_test ) ); // You can't throw exception from signal handler // (stack saved/restored, that confuse stack unwind); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-02-09 10:27:15
|
Revision: 1520 http://svn.sourceforge.net/complement/?rev=1520&view=rev Author: complement Date: 2007-02-09 02:27:13 -0800 (Fri, 09 Feb 2007) Log Message: ----------- process-shared barrier may be allocated in shared memory segment; libxmt version 1.10.2 Modified Paths: -------------- trunk/complement/explore/include/mt/shm.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/test/mt/mt_test.cc Modified: trunk/complement/explore/include/mt/shm.h =================================================================== --- trunk/complement/explore/include/mt/shm.h 2007-02-09 10:24:23 UTC (rev 1519) +++ trunk/complement/explore/include/mt/shm.h 2007-02-09 10:27:13 UTC (rev 1520) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/01/29 18:59:35 ptr> +// -*- C++ -*- Time-stamp: <07/02/07 10:11:34 ptr> /* * Copyright (c) 2006, 2007 @@ -82,6 +82,12 @@ }; template <> +struct ipc_sharable<xmt::__Barrier<true> > +{ + typedef std::__true_type is_ipc_sharable; +}; + +template <> struct ipc_sharable<xmt::__Mutex<false,true> > { typedef std::__true_type is_ipc_sharable; Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-02-09 10:24:23 UTC (rev 1519) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-02-09 10:27:13 UTC (rev 1520) @@ -1,3 +1,10 @@ +2007-02-08 Petr Ovtchenkov <pt...@is...> + + * shm.h: process-shared barrier may be allocated in shared + memory segment; + + * libxmt: version 1.10.2 + 2007-02-06 Petr Ovtchenkov <pt...@is...> * xmt.h: add Barrier; add yield; Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2007-02-09 10:24:23 UTC (rev 1519) +++ trunk/complement/explore/lib/mt/Makefile.inc 2007-02-09 10:27:13 UTC (rev 1520) @@ -3,6 +3,6 @@ LIBNAME = xmt MAJOR = 1 MINOR = 10 -PATCH = 1 +PATCH = 2 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc SRC_C = fl.c Modified: trunk/complement/explore/test/mt/mt_test.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test.cc 2007-02-09 10:24:23 UTC (rev 1519) +++ trunk/complement/explore/test/mt/mt_test.cc 2007-02-09 10:27:13 UTC (rev 1520) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/06 10:36:47 ptr> +// -*- C++ -*- Time-stamp: <07/02/07 08:29:41 ptr> /* * Copyright (c) 2006, 2007 @@ -32,7 +32,7 @@ namespace fs = boost::filesystem; /* ****************************************************** - * Degenerative case: check that one thread pass throw + * Degenerate case: check that one thread pass throw * own barrier. */ void mt_test::barrier() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-02-09 10:31:13
|
Revision: 1521 http://svn.sourceforge.net/complement/?rev=1521&view=rev Author: complement Date: 2007-02-09 02:31:07 -0800 (Fri, 09 Feb 2007) Log Message: ----------- use deque instead of queue for events in main dispetcher; this allow to use container's swap, not exchange via temporary objects [via copy]; destroy and create EvManager in child process after fork, if there are was EvManager; libstem version 4.4.0 use same name for all variants of dlopen'd within test Modified Paths: -------------- trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/include/stem/EventHandler.h trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Makefile.inc trunk/complement/explore/lib/stem/_EventHandler.cc trunk/complement/explore/test/stem/Makefile trunk/complement/explore/test/stem/dl/Makefile trunk/complement/explore/test/stem/dl/loadable_stem.cc trunk/complement/explore/test/stem/unit_test.cc Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2007-02-09 10:27:13 UTC (rev 1520) +++ trunk/complement/explore/include/stem/EvManager.h 2007-02-09 10:31:07 UTC (rev 1521) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/04 17:32:31 ptr> +// -*- C++ -*- Time-stamp: <07/02/08 16:38:05 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -22,7 +22,7 @@ #include <string> #include <map> -#include <queue> +#include <deque> #include <mt/xmt.h> #include <mt/uid.h> @@ -96,7 +96,7 @@ tracefault = 4 }; - typedef std::queue< Event > queue_type; + typedef std::deque< Event > queue_type; __FIT_DECLSPEC EvManager(); __FIT_DECLSPEC ~EvManager(); @@ -156,7 +156,7 @@ void push( const Event& e ) { MT_REENTRANT( _lock_queue, _x1 ); - in_ev_queue.push( e ); + in_ev_queue.push_back( e ); _cnd_queue.set( true ); } Modified: trunk/complement/explore/include/stem/EventHandler.h =================================================================== --- trunk/complement/explore/include/stem/EventHandler.h 2007-02-09 10:27:13 UTC (rev 1520) +++ trunk/complement/explore/include/stem/EventHandler.h 2007-02-09 10:31:07 UTC (rev 1521) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/30 20:50:13 ptr> +// -*- C++ -*- Time-stamp: <07/02/08 17:24:21 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -553,6 +553,9 @@ ~Init(); private: static void _guard( int ); + static void __at_fork_prepare(); + static void __at_fork_child(); + static void __at_fork_parent(); }; __FIT_DECLSPEC EventHandler(); Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2007-02-09 10:27:13 UTC (rev 1520) +++ trunk/complement/explore/lib/stem/ChangeLog 2007-02-09 10:31:07 UTC (rev 1521) @@ -1,3 +1,15 @@ +2007-02-08 Petr Ovtchenkov <pt...@is...> + + * EvManager.h, EvManager.cc: use deque instead of queue; + this allow to use container's swap, not exchange via temporary + objects [via copy]; + + * EventHandler.h, _EventHandler.cc: destroy and create + EvManager in child process after fork, if there are was + EvManager; + + * libstem: library version 4.4.0 + 2006-12-13 Petr Ovtchenkov <pt...@is...> * NetTransport.h, NetTransport.cc: NetTransportMgr Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2007-02-09 10:27:13 UTC (rev 1520) +++ trunk/complement/explore/lib/stem/EvManager.cc 2007-02-09 10:31:07 UTC (rev 1521) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/04 19:08:21 ptr> +// -*- C++ -*- Time-stamp: <07/02/08 16:38:41 ptr> /* * @@ -85,11 +85,11 @@ while ( me.not_finished() ) { MT_LOCK( me._lock_queue ); - swap( me.in_ev_queue, me.out_ev_queue ); + me.in_ev_queue.swap( me.out_ev_queue ); MT_UNLOCK( me._lock_queue ); while ( !me.out_ev_queue.empty() ) { me.Send( me.out_ev_queue.front() ); - me.out_ev_queue.pop(); + me.out_ev_queue.pop_front(); } MT_LOCK( me._lock_queue ); if ( me.in_ev_queue.empty() && me.not_finished() ) { Modified: trunk/complement/explore/lib/stem/Makefile.inc =================================================================== --- trunk/complement/explore/lib/stem/Makefile.inc 2007-02-09 10:27:13 UTC (rev 1520) +++ trunk/complement/explore/lib/stem/Makefile.inc 2007-02-09 10:31:07 UTC (rev 1521) @@ -2,7 +2,7 @@ LIBNAME = stem MAJOR = 4 -MINOR = 3 +MINOR = 4 PATCH = 0 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 2007-02-09 10:27:13 UTC (rev 1520) +++ trunk/complement/explore/lib/stem/_EventHandler.cc 2007-02-09 10:31:07 UTC (rev 1521) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 20:32:35 ptr> +// -*- C++ -*- Time-stamp: <07/02/08 17:27:44 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -29,20 +29,21 @@ EvManager *EventHandler::_mgr = 0; Names *EventHandler::_ns = 0; -#if 0 // depends where fork happens: in the EvManager loop (stack) or not. -extern "C" void __at_fork_prepare() +static int *_rcount = 0; +#if 1 // depends where fork happens: in the EvManager loop (stack) or not. +void EventHandler::Init::__at_fork_prepare() { } -extern "C" void __at_fork_child() +void EventHandler::Init::__at_fork_child() { - if ( EventHandler::Init::_count != 0 ) { - // delete EventHandler::_mgr; + if ( *_rcount != 0 ) { + delete EventHandler::_mgr; EventHandler::_mgr = new( EventHandler::_mgr ) EvManager(); } } -extern "C" void __at_fork_parent() +void EventHandler::Init::__at_fork_parent() { } #endif @@ -54,6 +55,10 @@ if ( direction ) { if ( _count++ == 0 ) { +#ifdef _PTHREADS + _rcount = &_count; + pthread_atfork( __at_fork_prepare, __at_fork_parent, __at_fork_child ); +#endif EventHandler::_mgr = new EvManager(); EventHandler::_ns = new Names( ns_addr, "ns" ); } @@ -61,8 +66,10 @@ --_count; if ( _count == 1 ) { delete EventHandler::_ns; + EventHandler::_ns = 0; } else if ( _count == 0 ) { delete EventHandler::_mgr; + EventHandler::_mgr = 0; } } } Modified: trunk/complement/explore/test/stem/Makefile =================================================================== --- trunk/complement/explore/test/stem/Makefile 2007-02-09 10:27:13 UTC (rev 1520) +++ trunk/complement/explore/test/stem/Makefile 2007-02-09 10:31:07 UTC (rev 1521) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <06/12/13 01:07:22 ptr> +# -*- Makefile -*- Time-stamp: <07/02/07 12:28:46 ptr> SRCROOT := ../.. COMPILER_NAME := gcc @@ -18,16 +18,16 @@ LIBUTF_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/test/unit_test_framework ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBUTF_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBUTF_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBUTF_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBUTF_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBUTF_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBUTF_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBUTF_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -Wl,--rpath=./dl/${OUTPUT_DIR}:${LIBMT_DIR}/${OUTPUT_DIR}:${LIBUTF_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBUTF_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}:${LIBUTF_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBUTF_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}:${LIBUTF_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} endif release-shared : LDLIBS = -lxmt -lsockios -lstem -lboost_test_utf -ldl stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lboost_test_utfstlg -ldl dbg-shared : LDLIBS = -lxmtg -lsockiosg -lstemg -lboost_test_utfg -ldl -dbg-shared: DEFS += -DDEBUG +# dbg-shared: DEFS += -DDEBUG PHONY += dl dl-dbg dl-stldbg @@ -39,3 +39,6 @@ dl-stldbg: ${MAKE} -C dl stldbg-shared + +depend clean distclean mostlyclean maintainer-clean:: + ${MAKE} -C dl $@ Modified: trunk/complement/explore/test/stem/dl/Makefile =================================================================== --- trunk/complement/explore/test/stem/dl/Makefile 2007-02-09 10:27:13 UTC (rev 1520) +++ trunk/complement/explore/test/stem/dl/Makefile 2007-02-09 10:31:07 UTC (rev 1521) @@ -1,18 +1,28 @@ -# -*- Makefile -*- Time-stamp: <06/08/04 12:09:33 ptr> +# -*- Makefile -*- Time-stamp: <07/02/07 12:13:04 ptr> SRCROOT := ../../.. COMPILER_NAME := gcc +DBG_SUFFIX := +STLDBG_SUFFIX := +INSTALL_TAGS := + include Makefile.inc include ${SRCROOT}/Makefiles/top.mak +LIBSTEM_DIR = ${CoMT_DIR}/lib/stem - INCLUDES += -I$(SRCROOT)/include -I$(BOOST_INCLUDE_DIR) #LDSEARCH = -L${STLPORT_LIB_DIR} -L${CoMT_LIB_DIR} +release-shared: LDSEARCH += -L${LIBSTEM_DIR}/${OUTPUT_DIR} +stldbg-shared: LDSEARCH += -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} +dbg-shared: LDSEARCH += -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} #release-shared : LDLIBS = -lxmt -lsockios -lstem -lboost_test_utf +release-shared: LDLIBS = -lstem #stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lboost_test_utfstlg +stldbg-shared: LDLIBS = -lstemstlg #dbg-shared : LDLIBS = -lxmtg -lsockiosg -lstemg -lboost_test_utfg +dbg-shared: LDLIBS = -lstemg #LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR}:${CoMT_LIB_DIR} Modified: trunk/complement/explore/test/stem/dl/loadable_stem.cc =================================================================== --- trunk/complement/explore/test/stem/dl/loadable_stem.cc 2007-02-09 10:27:13 UTC (rev 1520) +++ trunk/complement/explore/test/stem/dl/loadable_stem.cc 2007-02-09 10:31:07 UTC (rev 1521) @@ -9,9 +9,9 @@ * */ -#include <boost/test/unit_test.hpp> +// #include <boost/test/unit_test.hpp> -using namespace boost::unit_test_framework; +// using namespace boost::unit_test_framework; #include "../NodeDL.h" Modified: trunk/complement/explore/test/stem/unit_test.cc =================================================================== --- trunk/complement/explore/test/stem/unit_test.cc 2007-02-09 10:27:13 UTC (rev 1520) +++ trunk/complement/explore/test/stem/unit_test.cc 2007-02-09 10:31:07 UTC (rev 1521) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/13 02:08:08 ptr> +// -*- C++ -*- Time-stamp: <07/02/07 13:05:32 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -14,6 +14,7 @@ #include <iostream> #include <mt/xmt.h> +#include <mt/shm.h> #include <stem/EventHandler.h> #include <stem/Names.h> @@ -35,7 +36,6 @@ using namespace __gnu_cxx; #endif -#include <sys/shm.h> #include <sys/wait.h> #include <signal.h> @@ -44,6 +44,9 @@ struct stem_test { + void shm_init(); + void shm_finit(); + void basic1(); void basic2(); void basic1new(); @@ -148,21 +151,21 @@ void stem_test::dl() { -#ifdef _STLP_DEBUG - void *lh = dlopen( "dl/obj/gcc/so_stlg/libloadable_stemstlg.so", RTLD_LAZY ); -#elif defined(DEBUG) - void *lh = dlopen( "dl/obj/gcc/so_g/libloadable_stemg.so", RTLD_LAZY ); -#else - void *lh = dlopen( "dl/obj/gcc/so/libloadable_stem.so", RTLD_LAZY ); -#endif + void *lh = dlopen( "libloadable_stem.so", RTLD_LAZY ); // Path was passed via -Wl,--rpath= + BOOST_REQUIRE( lh != NULL ); - void *(*f)(unsigned) = reinterpret_cast<void *(*)(unsigned)>( dlsym( lh, "create_NewNodeDL" ) ); + void *(*f)(unsigned); + void (*g)(void *); + void (*w)(void *); + int (*v)(void *); + + *(void **)(&f) = dlsym( lh, "create_NewNodeDL" ); BOOST_REQUIRE( f != NULL ); - void (*g)(void *) = reinterpret_cast<void (*)(void *)>( dlsym( lh, "destroy_NewNodeDL" ) ); + *(void **)(&g) = dlsym( lh, "destroy_NewNodeDL" ); BOOST_REQUIRE( g != NULL ); - void (*w)(void *) = reinterpret_cast<void (*)(void *)>( dlsym( lh, "wait_NewNodeDL" ) ); + *(void **)(&w) = dlsym( lh, "wait_NewNodeDL" ); BOOST_REQUIRE( w != NULL ); - int (*v)(void *) = reinterpret_cast<int (*)(void *)>( dlsym( lh, "v_NewNodeDL" ) ); + *(void **)(&v) = dlsym( lh, "v_NewNodeDL" ); BOOST_REQUIRE( v != NULL ); NewNodeDL *node = reinterpret_cast<NewNodeDL *>( f( 2002 ) ); @@ -289,25 +292,29 @@ } } -void stem_test::echo_net() +const char fname[] = "/tmp/stem_test.shm"; +xmt::shm_alloc<0> seg; +xmt::allocator_shm<xmt::__Condition<true>,0> shm_cnd; + +void stem_test::shm_init() { - shmid_ds ds; - int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); - BOOST_REQUIRE( id != -1 ); - // if ( id == -1 ) { - // cerr << "Error on shmget" << endl; - // } - BOOST_REQUIRE( shmctl( id, IPC_STAT, &ds ) != -1 ); - // if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { - // cerr << "Error on shmctl" << endl; - // } - void *buf = shmat( id, 0, 0 ); - BOOST_REQUIRE( buf != reinterpret_cast<void *>(-1) ); - // if ( buf == reinterpret_cast<void *>(-1) ) { - // cerr << "Error on shmat" << endl; - // } + try { + seg.allocate( fname, 4*4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0600 ); + } + catch ( const xmt::shm_bad_alloc& err ) { + BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); + } +} - xmt::__Condition<true>& fcnd = *new( buf ) xmt::__Condition<true>(); +void stem_test::shm_finit() +{ + seg.deallocate(); + unlink( fname ); +} + +void stem_test::echo_net() +{ + xmt::__Condition<true>& fcnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__Condition<true>(); fcnd.set( false ); try { @@ -361,10 +368,8 @@ } (&fcnd)->~__Condition<true>(); + shm_cnd.deallocate( &fcnd, 1 ); - shmdt( buf ); - shmctl( id, IPC_RMID, &ds ); - // cerr << "Fine\n"; } @@ -396,29 +401,13 @@ pid_t fpid; - shmid_ds ds; - int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); - BOOST_REQUIRE( id != -1 ); - // if ( id == -1 ) { - // cerr << "Error on shmget" << endl; - // } - BOOST_REQUIRE( shmctl( id, IPC_STAT, &ds ) != -1 ); - // if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { - // cerr << "Error on shmctl" << endl; - // } - void *buf = shmat( id, 0, 0 ); - BOOST_REQUIRE( buf != reinterpret_cast<void *>(-1) ); - // if ( buf == reinterpret_cast<void *>(-1) ) { - // cerr << "Error on shmat" << endl; - // } - - xmt::__Condition<true>& fcnd = *new( buf ) xmt::__Condition<true>(); + xmt::__Condition<true>& fcnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__Condition<true>(); fcnd.set( false ); - xmt::__Condition<true>& pcnd = *new( (char *)buf + sizeof(xmt::__Condition<true>) ) xmt::__Condition<true>(); + xmt::__Condition<true>& pcnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__Condition<true>(); pcnd.set( false ); - xmt::__Condition<true>& scnd = *new( (char *)buf + sizeof(xmt::__Condition<true>) * 2 ) xmt::__Condition<true>(); + xmt::__Condition<true>& scnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__Condition<true>(); scnd.set( false ); try { @@ -563,7 +552,7 @@ pcnd.set( true ); c2.wait(); - cerr << "Fine!" << endl; + // cerr << "Fine!" << endl; scnd.set( true ); mgr.close(); @@ -589,32 +578,16 @@ } (&fcnd)->~__Condition<true>(); + shm_cnd.deallocate( &fcnd, 1 ); (&pcnd)->~__Condition<true>(); + shm_cnd.deallocate( &pcnd, 1 ); (&scnd)->~__Condition<true>(); - - shmdt( buf ); - shmctl( id, IPC_RMID, &ds ); + shm_cnd.deallocate( &scnd, 1 ); } void stem_test::boring_manager() { - shmid_ds ds; - int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); - BOOST_REQUIRE( id != -1 ); - // if ( id == -1 ) { - // cerr << "Error on shmget" << endl; - // } - BOOST_REQUIRE( shmctl( id, IPC_STAT, &ds ) != -1 ); - // if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { - // cerr << "Error on shmctl" << endl; - // } - void *buf = shmat( id, 0, 0 ); - BOOST_REQUIRE( buf != reinterpret_cast<void *>(-1) ); - // if ( buf == reinterpret_cast<void *>(-1) ) { - // cerr << "Error on shmat" << endl; - // } - - xmt::__Condition<true>& fcnd = *new( buf ) xmt::__Condition<true>(); + xmt::__Condition<true>& fcnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__Condition<true>(); fcnd.set( false ); try { @@ -659,9 +632,7 @@ } (&fcnd)->~__Condition<true>(); - - shmdt( buf ); - shmctl( id, IPC_RMID, &ds ); + shm_cnd.deallocate( &fcnd, 1 ); } struct stem_test_suite : @@ -683,9 +654,12 @@ test_case *dl_tc = BOOST_CLASS_TEST_CASE( &stem_test::dl, instance ); test_case *ns_tc = BOOST_CLASS_TEST_CASE( &stem_test::ns, instance ); test_case *echo_tc = BOOST_CLASS_TEST_CASE( &stem_test::echo, instance ); + test_case *shm_init_tc = BOOST_CLASS_TEST_CASE( &stem_test::shm_init, instance ); test_case *echo_net_tc = BOOST_CLASS_TEST_CASE( &stem_test::echo_net, instance ); test_case *peer_tc = BOOST_CLASS_TEST_CASE( &stem_test::peer, instance ); test_case *boring_manager_tc = BOOST_CLASS_TEST_CASE( &stem_test::boring_manager, instance ); + test_case *shm_finit_tc = BOOST_CLASS_TEST_CASE( &stem_test::shm_finit, instance ); + basic2_tc->depends_on( basic1_tc ); basic1n_tc->depends_on( basic1_tc ); basic2n_tc->depends_on( basic2_tc ); @@ -694,9 +668,13 @@ ns_tc->depends_on( basic1_tc ); echo_tc->depends_on( basic2_tc ); + echo_net_tc->depends_on( shm_init_tc ); echo_net_tc->depends_on( echo_tc ); peer_tc->depends_on( echo_tc ); + peer_tc->depends_on( shm_init_tc ); boring_manager_tc->depends_on( peer_tc ); + boring_manager_tc->depends_on( shm_init_tc ); + shm_finit_tc->depends_on( shm_init_tc ); add( basic1_tc ); add( basic2_tc ); @@ -706,9 +684,11 @@ add( ns_tc ); add( echo_tc ); + add( shm_init_tc ); add( echo_net_tc ); add( peer_tc ); add( boring_manager_tc ); + add( shm_finit_tc ); } test_suite *init_unit_test_suite( int argc, char **argv ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-02-12 12:17:56
|
Revision: 1525 http://svn.sourceforge.net/complement/?rev=1525&view=rev Author: complement Date: 2007-02-12 04:17:50 -0800 (Mon, 12 Feb 2007) Log Message: ----------- use Init technique to initialize static idx [thread-specific data index]---avoid global mutex initialization [lead to problems after fork?]; reinitilize idx after fork; libsockios: Version 1.11.0 Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/lib/sockios/ChangeLog trunk/complement/explore/lib/sockios/Makefile.inc trunk/complement/explore/lib/sockios/_sockmgr.cc Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2007-02-12 11:22:03 UTC (rev 1524) +++ trunk/complement/explore/include/sockios/sockmgr.h 2007-02-12 12:17:50 UTC (rev 1525) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/01 16:10:07 ptr> +// -*- C++ -*- Time-stamp: <07/02/12 14:50:57 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -52,22 +52,23 @@ class basic_sockmgr : public sock_base { + private: + class Init + { + public: + Init(); + ~Init(); + private: + static void _guard( int ); + static void __at_fork_prepare(); + static void __at_fork_child(); + static void __at_fork_parent(); + }; + public: - basic_sockmgr() : - _errno( 0 ), - _mode( ios_base::in | ios_base::out ), - _state( ios_base::goodbit ), - _fd( -1 ) - { - xmt::Locker _l( _idx_lck ); - if ( _idx == -1 ) { - _idx = xmt::Thread::xalloc(); - } - } + basic_sockmgr(); + virtual ~basic_sockmgr(); - virtual ~basic_sockmgr() - { basic_sockmgr::close(); } - protected: __FIT_DECLSPEC void open( const in_addr& addr, int port, sock_base::stype type, sock_base::protocol prot ); __FIT_DECLSPEC void open( unsigned long addr, int port, sock_base::stype type, sock_base::protocol prot ); @@ -109,10 +110,8 @@ protected: static int _idx; + friend class Init; - private: - static xmt::Mutex _idx_lck; - protected: xmt::Mutex _fd_lck; xmt::Condition _loop_cnd; @@ -274,7 +273,7 @@ bool accept_udp(); private: - xmt::Thread loop_id; + xmt::Thread loop_id; protected: typedef sockmgr_stream_MP<Connect> _Self_type; Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2007-02-12 11:22:03 UTC (rev 1524) +++ trunk/complement/explore/lib/sockios/ChangeLog 2007-02-12 12:17:50 UTC (rev 1525) @@ -1,3 +1,12 @@ +2007-02-12 Petr Ovtchenkov <pt...@is...> + + * sockmgr.h, _sockmgr.cc: use Init technique to initialize + static idx [thread-specific data index]---avoid global + mutex initialization [lead to problems after fork?]; + reinitilize idx after fork; + + * libsockios: Version 1.11.0 + 2007-02-01 Petr Ovtchenkov <pt...@is...> * sockmgr.cc: clean container with sockstreams, Modified: trunk/complement/explore/lib/sockios/Makefile.inc =================================================================== --- trunk/complement/explore/lib/sockios/Makefile.inc 2007-02-12 11:22:03 UTC (rev 1524) +++ trunk/complement/explore/lib/sockios/Makefile.inc 2007-02-12 12:17:50 UTC (rev 1525) @@ -2,8 +2,8 @@ LIBNAME = sockios MAJOR = 1 -MINOR = 10 -PATCH = 4 +MINOR = 11 +PATCH = 0 SRC_CC = _sockstream.cc _sockmgr.cc SRC_C = freebsd/getaddrinfo.c \ freebsd/ns_parse.c \ Modified: trunk/complement/explore/lib/sockios/_sockmgr.cc =================================================================== --- trunk/complement/explore/lib/sockios/_sockmgr.cc 2007-02-12 11:22:03 UTC (rev 1524) +++ trunk/complement/explore/lib/sockios/_sockmgr.cc 2007-02-12 12:17:50 UTC (rev 1525) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/06/28 10:35:10 ptr> +// -*- C++ -*- Time-stamp: <07/02/12 14:49:26 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -35,8 +35,58 @@ #endif int basic_sockmgr::_idx = -1; -xmt::Mutex basic_sockmgr::_idx_lck; +void basic_sockmgr::Init::__at_fork_prepare() +{ +} + +void basic_sockmgr::Init::__at_fork_child() +{ + basic_sockmgr::_idx = xmt::Thread::xalloc(); +} + +void basic_sockmgr::Init::__at_fork_parent() +{ +} + +void basic_sockmgr::Init::_guard( int direction ) +{ + static xmt::Mutex _init_lock; + static int _count = 0; + + if ( direction ) { + if ( _count++ == 0 ) { +#ifdef _PTHREADS + pthread_atfork( __at_fork_prepare, __at_fork_parent, __at_fork_child ); +#endif + basic_sockmgr::_idx = xmt::Thread::xalloc(); + } + } +} + +basic_sockmgr::Init::Init() +{ _guard( 1 ); } + +basic_sockmgr::Init::~Init() +{ _guard( 0 ); } + +char Init_buf[128]; + +basic_sockmgr::basic_sockmgr() : + _errno( 0 ), + _mode( ios_base::in | ios_base::out ), + _state( ios_base::goodbit ), + _fd( -1 ) +{ + new( Init_buf ) Init(); +} + +basic_sockmgr::~basic_sockmgr() +{ + basic_sockmgr::close(); + ((Init *)Init_buf)->~Init(); +} + void basic_sockmgr::open( const in_addr& addr, int port, sock_base::stype type, sock_base::protocol prot ) { MT_REENTRANT( _fd_lck, _1 ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-02-19 09:52:40
|
Revision: 1529 http://svn.sourceforge.net/complement/?rev=1529&view=rev Author: complement Date: 2007-02-19 01:52:36 -0800 (Mon, 19 Feb 2007) Log Message: ----------- remove Netware and Metrowerk CodeWarrior compiler (for Netware) Modified Paths: -------------- trunk/complement/explore/Makefiles/gmake/sysid.mak trunk/complement/explore/configure Removed Paths: ------------- trunk/complement/explore/Makefiles/gmake/mwccnlm.mak trunk/complement/explore/Makefiles/gmake/netware/ Deleted: trunk/complement/explore/Makefiles/gmake/mwccnlm.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/mwccnlm.mak 2007-02-15 12:38:53 UTC (rev 1528) +++ trunk/complement/explore/Makefiles/gmake/mwccnlm.mak 2007-02-19 09:52:36 UTC (rev 1529) @@ -1,89 +0,0 @@ -# Time-stamp: <06/11/10 15:56:39 ptr> -# -# Copyright (c) 2005, 2006 -# Petr Ovtchenkov -# -# Licensed under the Academic Free License version 3.0 -# - -INCLUDES := - -ifndef _FORCE_CXX -CXX := mwccnlm -else -CXX := $_FORCE_CXX -endif - -ifndef _FORCE_CC -CC := mwccnlm -else -CC := $_FORCE_CC -endif - -LINK.cc = mwldnlm $(LDFLAGS) $(TARGET_ARCH) - -ifeq ($(OSNAME), cygming) -RC := windres -endif - -CXX_VERSION := $(shell ${CXX} -version | grep Version | awk '{ print $$2; }') -CXX_VERSION_MAJOR := $(shell echo ${CXX_VERSION} | awk 'BEGIN { FS = "."; } { print $$1; }') -CXX_VERSION_MINOR := $(shell echo ${CXX_VERSION} | awk 'BEGIN { FS = "."; } { print $$2; }') -CXX_VERSION_PATCH := $(shell echo ${CXX_VERSION} | awk 'BEGIN { FS = "."; } { print $$3; }') - -DEFS ?= -OPT ?= - -OUTPUT_OPTION = -o $@ -LINK_OUTPUT_OPTION = ${OUTPUT_OPTION} -CPPFLAGS = $(DEFS) -gccinc -I. $(INCLUDES) -ir "$(NWSDK_DIR)" -ir "$(MWCW_NOVELL)" -prefix Headers/nlm_prefix.h - -ifeq ($(OSNAME), cygming) -release-shared : RCFLAGS = --include-dir=${STLPORT_INCLUDE_DIR} -DCOMP=gcc -DBUILD=r -DBUILD_INFOS="-O2" --output-format coff -dbg-shared : RCFLAGS = --include-dir=${STLPORT_INCLUDE_DIR} -DCOMP=gcc -DBUILD=d -DBUILD_INFOS="-g" --output-format coff -stldbg-shared : RCFLAGS = --include-dir=${STLPORT_INCLUDE_DIR} -DCOMP=gcc -DBUILD=stld -DBUILD_INFOS="-g -D_STLP_DEBUG" --output-format coff -RC_OUTPUT_OPTION = -o $@ -COMPILE.rc = $(RC) $(RCFLAGS) -endif - -CFLAGS = -lang c -msgstyle gcc -ext o -nostdinc -flag longlong_prepeval $(OPT) -CXXFLAGS = -lang c++ -msgstyle gcc -ext o -iso_templates on -bool on -Cpp_exceptions on -wchar_t on -nostdinc -flag longlong_prepeval $(OPT) - -ifdef EXTRA_CXXFLAGS -CXXFLAGS += ${EXTRA_CXXFLAGS} -endif - -CDEPFLAGS = -M -CCDEPFLAGS = -M - -# STLport DEBUG mode specific defines -stldbg-static : DEFS += -D_STLP_DEBUG -stldbg-shared : DEFS += -D_STLP_DEBUG -stldbg-static-dep : DEFS += -D_STLP_DEBUG -stldbg-shared-dep : DEFS += -D_STLP_DEBUG - -# optimization and debug compiler flags -release-static : OPT += -O4 -release-shared : OPT += -O4 - -dbg-static : OPT += -g -dbg-shared : OPT += -g -#dbg-static-dep : OPT += -g -#dbg-shared-dep : OPT += -g - -stldbg-static : OPT += -g -stldbg-shared : OPT += -g -#stldbg-static-dep : OPT += -g -#stldbg-shared-dep : OPT += -g - -# dependency output parser (dependencies collector) - -DP_OUTPUT_DIR = | sed 's|\($*\)\.o[ :]*|$(OUTPUT_DIR)/\1.o $@ : |g' > $@; \ - [ -s $@ ] || rm -f $@ - -DP_OUTPUT_DIR_DBG = | sed 's|\($*\)\.o[ :]*|$(OUTPUT_DIR_DBG)/\1.o $@ : |g' > $@; \ - [ -s $@ ] || rm -f $@ - -DP_OUTPUT_DIR_STLDBG = | sed 's|\($*\)\.o[ :]*|$(OUTPUT_DIR_STLDBG)/\1.o $@ : |g' > $@; \ - [ -s $@ ] || rm -f $@ - Modified: trunk/complement/explore/Makefiles/gmake/sysid.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/sysid.mak 2007-02-15 12:38:53 UTC (rev 1528) +++ trunk/complement/explore/Makefiles/gmake/sysid.mak 2007-02-19 09:52:36 UTC (rev 1529) @@ -2,11 +2,6 @@ ifndef BUILD_DATE -ifeq (mwccnlm,$(COMPILER_NAME)) -# this is really cross -TARGET_OS := netware -endif - ifndef TARGET_OS OSNAME := $(shell uname -s | tr '[A-Z]' '[a-z]' | tr ', /\\()"' ',//////' | tr ',/' ',-') @@ -31,18 +26,10 @@ endif else -ifndef (mwccnlm,$(COMPILER_NAME)) OSNAME := $(shell echo ${TARGET_OS} | sed 's/^[a-z0-9_]\+-[a-z0-9]\+-\([a-z]\+\).*/\1/' | sed 's/^[a-z0-9_]\+-\([a-z]\+\).*/\1/' ) OSREL := $(shell echo ${TARGET_OS} | sed 's/^[[:alnum:]_]\+-[a-z0-9]\+-[a-z]\+\([a-zA-Z.0-9]*\).*/\1/' | sed 's/^[a-z0-9_]\+-[a-z]\+\([a-zA-Z.0-9]*\).*/\1/' ) M_ARCH := $(shell echo ${TARGET_OS} | sed 's/^\([a-z0-9_]\+\)-.*/\1/' ) P_ARCH := unknown -else -OSNAME := netware -OSREL := 5 -M_ARCH := i386 -P_ARCH := unknown -endif - # TARGET_OS endif Modified: trunk/complement/explore/configure =================================================================== --- trunk/complement/explore/configure 2007-02-15 12:38:53 UTC (rev 1528) +++ trunk/complement/explore/configure 2007-02-19 09:52:36 UTC (rev 1529) @@ -33,10 +33,6 @@ --with-system-boost use boost installed on this system --with-msvc=<dir> use MS VC from this catalog --with-mssdk=<dir> use MS SDK from this catalog - --with-mwcw=<dir> Metrowerks CodeWarrior compiler catalog (useful for mw* compilers) - i.e. something like "c:/Program Files/Metrowerks/CodeWarrior" - --with-nwsdk=<dir> use Novell NDK/SDK from this catalog (useful for *-*-netware target) - i.e. something like "c:/Novell/ndk/nwsdk" --with-extra-cxxflags=<options> pass extra options to C++ compiler --use-static-gcc use static gcc libs instead of shared libgcc_s (useful for gcc compiler, @@ -49,7 +45,6 @@ --use-compiler-family=<name> use compiler family; one of: gcc GNU compilers icc Intel compilers - mwccnlm Metrowerks CodeWarrior for Novell Netware aCC HP\'s aCC compilers CC SunPro\'s CC compilers @@ -140,12 +135,6 @@ write_option "$option" EXTRA_CXXFLAGS cxxflags_set=y ;; - --with-nwsdk=*) - write_option "$option" NWSDK_DIR - ;; - --with-mwcw=*) - write_option "$option" MWCW_BASE - ;; --use-static-gcc) write_option "1" USE_STATIC_LIBGCC ;; @@ -171,7 +160,7 @@ ;; --use-compiler-family=*) case `echo $option | sed -e 's/^[^=]*=//'` in - gcc|icc|aCC|CC|mwccnlm) + gcc|icc|aCC|CC) write_option "$option" COMPILER_NAME ;; *) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-02-28 08:23:44
|
Revision: 1536 http://svn.sourceforge.net/complement/?rev=1536&view=rev Author: complement Date: 2007-02-28 00:23:43 -0800 (Wed, 28 Feb 2007) Log Message: ----------- fstream-like interface to unique temporary file; file generated from template with mkstemp [POSIX 1003.1-2001] Modified Paths: -------------- trunk/complement/explore/lib/misc/ChangeLog Added Paths: ----------- trunk/complement/explore/include/misc/tfstream trunk/complement/explore/inquiry/shades/mkstemp/ trunk/complement/explore/inquiry/shades/mkstemp/Makefile trunk/complement/explore/inquiry/shades/mkstemp/Makefile.inc trunk/complement/explore/inquiry/shades/mkstemp/test.c Added: trunk/complement/explore/include/misc/tfstream =================================================================== --- trunk/complement/explore/include/misc/tfstream (rev 0) +++ trunk/complement/explore/include/misc/tfstream 2007-02-28 08:23:43 UTC (rev 1536) @@ -0,0 +1,89 @@ +// -*- C++ -*- Time-stamp: <07/02/28 00:53:40 ptr> + +/* + * + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License version 3.0 + * + */ + +#ifndef __misc_tfstream +#define __misc_tfstream + +#include <fstream> +#include <string> +#include <cstdlib> + +namespace misc { + +template <class _CharT, class _Traits> +class basic_tfstream : + public std::basic_iostream<_CharT, _Traits> +{ + public: + typedef _CharT char_type; + typedef typename _Traits::int_type int_type; + typedef typename _Traits::pos_type pos_type; + typedef typename _Traits::off_type off_type; + typedef _Traits traits_type; + + public: + basic_tfstream() : + std::basic_ios<_CharT, _Traits>(), + std::basic_iostream<_CharT, _Traits>(0), + _M_buf() + { this->init(&_M_buf); } + + explicit basic_tfstream( const char *__s ) : + std::basic_ios<_CharT, _Traits>(), + std::basic_iostream<_CharT, _Traits>(0), + _M_buf() + { + this->init(&_M_buf); + _name = __s; + _name += "XXXXXX"; + int fd = ::mkstemp( const_cast<char *>(_name.c_str()) ); + if ( fd < 0 || !_M_buf.open( fd ) ) { + this->setstate(std::ios_base::failbit); + } + } + + void open( const char *__s ) + { + _name = __s; + _name += "XXXXXX"; + int fd = ::mkstemp( const_cast<char *>(_name.c_str()) ); + if ( fd < 0 || !_M_buf.open( fd ) ) { + this->setstate(std::ios_base::failbit); + } + } + + const char *name() const + { return _name.c_str(); } + + std::basic_filebuf<_CharT, _Traits>* rdbuf() const + { return const_cast<std::basic_filebuf<_CharT, _Traits> *>(&_M_buf); } + + bool is_open() + { return this->rdbuf()->is_open(); } + + void close() + { + if (!this->rdbuf()->close()) { + this->setstate(std::ios_base::failbit); + } + } + + private: + std::string _name; + std::basic_filebuf<_CharT, _Traits> _M_buf; +}; + +typedef basic_tfstream<char, std::char_traits<char> > tfstream; +typedef basic_tfstream<wchar_t, std::char_traits<wchar_t> > wtfstream; + +} // namespace misc + +#endif // __misc_tfstream Property changes on: trunk/complement/explore/inquiry/shades/mkstemp ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/explore/inquiry/shades/mkstemp/Makefile =================================================================== --- trunk/complement/explore/inquiry/shades/mkstemp/Makefile (rev 0) +++ trunk/complement/explore/inquiry/shades/mkstemp/Makefile 2007-02-28 08:23:43 UTC (rev 1536) @@ -0,0 +1,10 @@ +# -*- Makefile -*- Time-stamp: <06/11/13 23:03:45 ptr> + +SRCROOT := ../../.. + +include Makefile.inc +include ${SRCROOT}/Makefiles/top.mak + +ifndef WITHOUT_STLPORT +LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR} +endif Added: trunk/complement/explore/inquiry/shades/mkstemp/Makefile.inc =================================================================== --- trunk/complement/explore/inquiry/shades/mkstemp/Makefile.inc (rev 0) +++ trunk/complement/explore/inquiry/shades/mkstemp/Makefile.inc 2007-02-28 08:23:43 UTC (rev 1536) @@ -0,0 +1,4 @@ +# -*- makefile -*- Time-stamp: <04/01/12 15:37:40 ptr> + +PRGNAME = test +SRC_C = test.c Added: trunk/complement/explore/inquiry/shades/mkstemp/test.c =================================================================== --- trunk/complement/explore/inquiry/shades/mkstemp/test.c (rev 0) +++ trunk/complement/explore/inquiry/shades/mkstemp/test.c 2007-02-28 08:23:43 UTC (rev 1536) @@ -0,0 +1,20 @@ +#include <stdlib.h> +#include <stdio.h> + + +int main() +{ + char buf[1024]; + int fd; + + strcpy( buf, "/tmp/qXXXXXX" ); + printf( "%s\n", buf ); + + fd = mkstemp( buf ); + + printf( "%s\n", buf ); + close( fd ); + /* unlink( buf ); */ + + return 0; +} Modified: trunk/complement/explore/lib/misc/ChangeLog =================================================================== --- trunk/complement/explore/lib/misc/ChangeLog 2007-02-27 14:55:33 UTC (rev 1535) +++ trunk/complement/explore/lib/misc/ChangeLog 2007-02-28 08:23:43 UTC (rev 1536) @@ -1,3 +1,10 @@ +2007-02-28 Petr Ovtchenkov <pt...@is...> + + * tfstream: fstream-like interface to unique temporary file; + file generated from template with mkstemp [POSIX 1003.1-2001]; + template only, library not required; current implementation work + only with STLport with extentions enabled. + 2006-05-24 Petr Ovtchenkov <pt...@is...> * args.cc: explicitly add stdexcept header. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-03-12 18:25:17
|
Revision: 1553 http://svn.sourceforge.net/complement/?rev=1553&view=rev Author: complement Date: 2007-03-12 11:25:09 -0700 (Mon, 12 Mar 2007) Log Message: ----------- remove code for Novell NetWare; libxmt 1.10.3 Modified Paths: -------------- trunk/complement/explore/include/config/feature.h trunk/complement/explore/include/mt/xmt.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/xmt.cc Removed Paths: ------------- trunk/complement/explore/include/config/_mwccnlm.h trunk/complement/explore/include/config/_netware.h Deleted: trunk/complement/explore/include/config/_mwccnlm.h =================================================================== --- trunk/complement/explore/include/config/_mwccnlm.h 2007-03-09 17:48:37 UTC (rev 1552) +++ trunk/complement/explore/include/config/_mwccnlm.h 2007-03-12 18:25:09 UTC (rev 1553) @@ -1,27 +0,0 @@ -// -*- C++ -*- Time-stamp: <05/06/29 19:01:14 ptr> - -/* - * - * Copyright (c) 2003 - * Petr Ovchenkov - * - * Licensed under the Academic Free License Version 1.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 __config__mwccnlm_h -#define __config__mwccnlm_h - -#ident "@(#)$Id$" - - -#endif // __config__mwccnlm_h Deleted: trunk/complement/explore/include/config/_netware.h =================================================================== --- trunk/complement/explore/include/config/_netware.h 2007-03-09 17:48:37 UTC (rev 1552) +++ trunk/complement/explore/include/config/_netware.h 2007-03-12 18:25:09 UTC (rev 1553) @@ -1,30 +0,0 @@ -// -*- C++ -*- Time-stamp: <05/06/29 19:29:34 ptr> - -/* - * - * Copyright (c) 2005 - * Petr Ovtchenkov - * - * Licensed under the Academic Free License Version 2.1 - * - * 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 __config__netware_h -#define __config__netware_h - -#ident "@(#)$Id$" - -#define __FIT_NETWARE // mark target: Novell Netware -#define __FIT_NOVELL_THREADS -#define _LITTLE_ENDIAN // Novell NetWare run only on Intel - -#endif // __config__netware_h Modified: trunk/complement/explore/include/config/feature.h =================================================================== --- trunk/complement/explore/include/config/feature.h 2007-03-09 17:48:37 UTC (rev 1552) +++ trunk/complement/explore/include/config/feature.h 2007-03-12 18:25:09 UTC (rev 1553) @@ -1,23 +1,14 @@ -/* Time-stamp: <05/12/12 10:47:17 ptr> */ +/* Time-stamp: <07/03/12 20:17:03 ptr> */ /* - * Copyright (c) 1999, 2002, 2003, 2004, 2005 + * Copyright (c) 1999, 2002-2007 * Petr Ovtchenkov * * Portion Copyright (c) 1999-2001 * Parallel Graphics Ltd. * - * Licensed under the Academic Free License Version 2.1 + * Licensed under the Academic Free License Version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. - * */ #ifndef __config_feature_h @@ -76,13 +67,6 @@ #include <config/_windows.h> #endif -#ifdef N_PLAT_NLM -# include <config/_netware.h> -# ifdef __MWERKS__ -# include <config/_mwccnlm.h> -# endif -#endif - #ifdef __FIT_USE_DECLSPEC /* using export/import technique */ # ifdef __FIT_DLL # define __FIT_DECLSPEC __declspec( dllexport ) Modified: trunk/complement/explore/include/mt/xmt.h =================================================================== --- trunk/complement/explore/include/mt/xmt.h 2007-03-09 17:48:37 UTC (rev 1552) +++ trunk/complement/explore/include/mt/xmt.h 2007-03-12 18:25:09 UTC (rev 1553) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/02 21:32:58 ptr> +// -*- C++ -*- Time-stamp: <07/03/12 20:09:11 ptr> /* * Copyright (c) 1997-1999, 2002-2007 @@ -50,16 +50,6 @@ // # define __DLLEXPORT #endif // __unix -#ifdef __FIT_NOVELL_THREADS // Novell NetWare -# if defined( _REENTRANT ) && !defined(_NOTHREADS) -# include <nwthread.h> -# include <nwsemaph.h> -# include <nwproc.h> -# elif !defined(_NOTHREADS) // !_REENTRANT -# define _NOTHREADS -# endif -#endif - #include <cerrno> #include <mt/time.h> @@ -234,9 +224,6 @@ #ifdef __FIT_WIN32THREADS InitializeCriticalSection( &_M_lock ); #endif -#ifdef __FIT_NOVELL_THREADS - _M_lock = OpenLocalSemaphore( 1 ); -#endif } ~__mutex_base() @@ -250,9 +237,6 @@ #ifdef WIN32 DeleteCriticalSection( &_M_lock ); #endif -#ifdef __FIT_NOVELL_THREADS - CloseLocalSemaphore( _M_lock ); -#endif } private: @@ -269,12 +253,6 @@ #ifdef __FIT_WIN32THREADS CRITICAL_SECTION _M_lock; #endif -#ifdef __FIT_NOVELL_THREADS - // This is for ...LocalSemaphore() calls - // Alternative is EnterCritSec ... ExitCritSec; but ...CritSec in Novell - // block all threads except current - LONG _M_lock; -#endif #ifndef __FIT_WIN32THREADS private: @@ -340,9 +318,6 @@ #ifdef __FIT_WIN32THREADS EnterCriticalSection( &this->_M_lock ); #endif -#ifdef __FIT_NOVELL_THREADS - WaitOnLocalSemaphore( this->_M_lock ); -#endif } #if !defined( WIN32 ) || (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400) @@ -357,9 +332,6 @@ #ifdef __FIT_WIN32THREADS return TryEnterCriticalSection( &this->_M_lock ) != 0 ? 0 : -1; #endif -#ifdef __FIT_NOVELL_THREADS - return ExamineLocalSemaphore( this->_M_lock ) > 0 ? WaitOnLocalSemaphore( this->_M_lock ) : -1; -#endif #ifdef _NOTHREADS return 0; #endif @@ -377,9 +349,6 @@ #ifdef __FIT_WIN32THREADS LeaveCriticalSection( &this->_M_lock ); #endif -#ifdef __FIT_NOVELL_THREADS - SignalLocalSemaphore( this->_M_lock ); -#endif } private: @@ -453,9 +422,6 @@ # ifdef __FIT_UITHREADS thread_t _c_id = thr_self(); # endif -# ifdef __FIT_NOVELL_THREADS - int _c_id = GetThreadID(); -# endif if ( _c_id == _id ) { ++_count; return; @@ -479,9 +445,6 @@ # ifdef __FIT_UITHREADS thread_t _c_id = thr_self(); # endif -# ifdef __FIT_NOVELL_THREADS - int _c_id = GetThreadID(); -# endif if ( _c_id == _id ) { ++_count; return 0; @@ -522,9 +485,6 @@ # ifdef __FIT_UITHREADS thread_t _id; # endif -# ifdef __FIT_NOVELL_THREADS - int _id; -# endif }; #endif // __FIT_PTHREAD_SPINLOCK @@ -536,7 +496,7 @@ // (or XSI---X/Open System Interfaces Extention) has recursive mutex option. // Another specialization? -#if (defined(__unix) && !defined(__FIT_XSI_THR)) || defined(__FIT_NOVELL_THREADS) +#if (defined(__unix) && !defined(__FIT_XSI_THR)) // This specialization need for old POSIX and DCE threads, // before XSI (X/Open System Interfaces Extention) or Unix 98. @@ -557,9 +517,6 @@ # ifdef _PTHREADS _id( __STATIC_CAST(pthread_t,-1) ) # endif -# ifdef __FIT_NOVELL_THREADS - _id( -1 ) -# endif { } ~__Mutex() @@ -574,9 +531,6 @@ # ifdef __FIT_UITHREADS thread_t _c_id = thr_self(); # endif -# ifdef __FIT_NOVELL_THREADS - int _c_id = GetThreadID(); -# endif if ( _c_id == _id ) { ++_count; return; @@ -587,9 +541,6 @@ # ifdef __FIT_UITHREADS mutex_lock( &_M_lock ); # endif -# ifdef __FIT_NOVELL_THREADS - WaitOnLocalSemaphore( this->_M_lock ); -# endif _id = _c_id; _count = 0; # endif // !_NOTHREADS @@ -613,9 +564,6 @@ # ifdef __FIT_UITHREADS thread_t _c_id = thr_self(); # endif -# ifdef __FIT_NOVELL_THREADS - int _c_id = GetThreadID(); -# endif if ( _c_id == _id ) { ++_count; return 0; @@ -626,9 +574,6 @@ # ifdef __FIT_UITHREADS int res = mutex_trylock( &_M_lock ); # endif -# ifdef __FIT_NOVELL_THREADS - int res = ExamineLocalSemaphore( this->_M_lock ) > 0 ? WaitOnLocalSemaphore( this->_M_lock ) : -1; -# endif if ( res != 0 ) { return res; } @@ -652,10 +597,6 @@ _id = __STATIC_CAST(pthread_t,-1); pthread_mutex_unlock( &_M_lock ); # endif -# ifdef __FIT_NOVELL_THREADS - _id = -1; - SignalLocalSemaphore( this->_M_lock ); -# endif # endif // !_NOTHREADS } } @@ -675,9 +616,6 @@ # ifdef __FIT_UITHREADS thread_t _id; # endif -# ifdef __FIT_NOVELL_THREADS - int _id; -# endif }; #endif // __unix && !__FIT_XSI_THR @@ -719,10 +657,6 @@ #error Fix me! InitializeCriticalSection( &_M_lock ); #endif -#ifdef __FIT_NOVELL_THREADS -#error Fix me! - _M_lock = OpenLocalSemaphore( 1 ); -#endif } ~__mutex_rw_base() @@ -738,10 +672,6 @@ #error Fix me! DeleteCriticalSection( &_M_lock ); #endif -#ifdef __FIT_NOVELL_THREADS -#error Fix me! - CloseLocalSemaphore( _M_lock ); -#endif } private: @@ -760,13 +690,6 @@ #error Fix me! CRITICAL_SECTION _M_lock; #endif -#ifdef __FIT_NOVELL_THREADS - // This is for ...LocalSemaphore() calls - // Alternative is EnterCritSec ... ExitCritSec; but ...CritSec in Novell - // block all threads except current -#error Fix me! - LONG _M_lock; -#endif }; template <bool SCOPE> @@ -793,10 +716,6 @@ #error Fix me! EnterCriticalSection( &this->_M_lock ); #endif -#ifdef __FIT_NOVELL_THREADS -#error Fix me! - WaitOnLocalSemaphore( this->_M_lock ); -#endif } void wrlock() @@ -812,10 +731,6 @@ #error Fix me! EnterCriticalSection( &this->_M_lock ); #endif -#ifdef __FIT_NOVELL_THREADS -#error Fix me! - WaitOnLocalSemaphore( this->_M_lock ); -#endif } #if !defined( WIN32 ) || (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400) @@ -832,10 +747,6 @@ #error Fix me! return TryEnterCriticalSection( &this->_M_lock ) != 0 ? 0 : -1; #endif -#ifdef __FIT_NOVELL_THREADS -#error Fix me! - return ExamineLocalSemaphore( this->_M_lock ) > 0 ? WaitOnLocalSemaphore( this->_M_lock ) : -1; -#endif #ifdef _NOTHREADS #error Fix me! return 0; @@ -855,10 +766,6 @@ #error Fix me! return TryEnterCriticalSection( &this->_M_lock ) != 0 ? 0 : -1; #endif -#ifdef __FIT_NOVELL_THREADS -#error Fix me! - return ExamineLocalSemaphore( this->_M_lock ) > 0 ? WaitOnLocalSemaphore( this->_M_lock ) : -1; -#endif #ifdef _NOTHREADS #error Fix me! return 0; @@ -880,10 +787,6 @@ #error Fix me! LeaveCriticalSection( &this->_M_lock ); #endif -#ifdef __FIT_NOVELL_THREADS -#error Fix me! - SignalLocalSemaphore( this->_M_lock ); -#endif } private: @@ -978,9 +881,6 @@ #ifdef __FIT_WIN32THREADS explicit LockerExt( const CRITICAL_SECTION& m ) : #endif -#ifdef __FIT_NOVELL_THREADS - explicit LockerExt( const LONG& m ) : -#endif _M_lock( m ) { #ifdef _PTHREADS @@ -992,9 +892,6 @@ #ifdef __FIT_WIN32THREADS EnterCriticalSection( const_cast<CRITICAL_SECTION *>(&_M_lock) ); #endif -#ifdef __FIT_NOVELL_THREADS - WaitOnLocalSemaphore( const_cast<LONG&>(_M_lock) ); -#endif } ~LockerExt() @@ -1008,9 +905,6 @@ #ifdef __FIT_WIN32THREADS LeaveCriticalSection( const_cast<CRITICAL_SECTION *>(&_M_lock) ); #endif -#ifdef __FIT_NOVELL_THREADS - SignalLocalSemaphore( const_cast<LONG&>(_M_lock) ); -#endif } private: @@ -1026,13 +920,6 @@ #ifdef __FIT_WIN32THREADS const CRITICAL_SECTION& _M_lock; #endif -#ifdef __FIT_NOVELL_THREADS - // This is for ...LocalSemaphore() calls - // Alternative is EnterCritSec ... ExitCritSec; but ...CritSec in Novell - // block all threads except current - const LONG& _M_lock; -#endif - }; template <bool SCOPE> @@ -1059,9 +946,6 @@ #ifdef __FIT_UITHREADS cond_init( &_cond, 0, 0 ); #endif -#ifdef __FIT_NOVELL_THREADS - _cond = OpenLocalSemaphore( 0 ); -#endif } ~__Condition() @@ -1075,9 +959,6 @@ #ifdef __FIT_UITHREADS cond_destroy( &_cond ); #endif -#ifdef __FIT_NOVELL_THREADS - CloseLocalSemaphore( _cond ); -#endif } bool set( bool __v, bool _broadcast = false ) @@ -1111,16 +992,6 @@ } } #endif -#ifdef __FIT_NOVELL_THREADS - if ( __v == true && tmp == false ) { - if ( _broadcast ) { - // Unimplemented - // pthread_cond_broadcast( &_cond ); - } else { - SignalLocalSemaphore( _cond ); - } - } -#endif return tmp; } @@ -1129,7 +1000,7 @@ int try_wait() { -#if defined(__FIT_WIN32THREADS) || defined(__FIT_NOVELL_THREADS) +#if defined(__FIT_WIN32THREADS) _lock.lock(); #endif #if defined(__FIT_UITHREADS) || defined(_PTHREADS) @@ -1143,10 +1014,6 @@ } return 0; #endif -#ifdef __FIT_NOVELL_THREADS - _lock.unlock(); - return WaitOnLocalSemaphore( _cond ); -#endif #if defined(__FIT_UITHREADS) || defined(_PTHREADS) int ret = 0; while ( !_val ) { @@ -1161,7 +1028,7 @@ return ret; #endif } -#if defined(__FIT_WIN32THREADS) || defined(__FIT_NOVELL_THREADS) +#if defined(__FIT_WIN32THREADS) _lock.unlock(); #endif return 0; @@ -1195,12 +1062,6 @@ return ret; #endif -#ifdef __FIT_NOVELL_THREADS - _lock.lock(); - _val = false; - _lock.unlock(); - return WaitOnLocalSemaphore( _cond ); -#endif #ifdef _NOTHREADS return 0; #endif @@ -1236,9 +1097,6 @@ #ifdef __FIT_UITHREADS return _broadcast ? cond_broadcast( &_cond ) : cond_signal( &_cond ); #endif -#ifdef __FIT_NOVELL_THREADS - return SignalLocalSemaphore( _cond ); -#endif #ifdef _NOTHREADS return 0; #endif @@ -1254,9 +1112,6 @@ #ifdef __FIT_UITHREADS cond_t _cond; #endif -#ifdef __FIT_NOVELL_THREADS - LONG _cond; -#endif __Mutex<false,SCOPE> _lock; bool _val; @@ -1283,9 +1138,6 @@ #ifdef _PTHREADS sem_init( &_sem, SCOPE ? 1 : 0, cnt ); #endif -#ifdef __FIT_NOVELL_THREADS - _sem = OpenLocalSemaphore( cnt ); -#endif } ~__Semaphore() @@ -1299,9 +1151,6 @@ #ifdef _PTHREADS sem_destroy( &_sem ); #endif -#ifdef __FIT_NOVELL_THREADS - CloseLocalSemaphore( _sem ); -#endif } int wait() @@ -1320,9 +1169,6 @@ #ifdef _PTHREADS return sem_wait( &_sem ); #endif -#ifdef __FIT_NOVELL_THREADS - return WaitOnLocalSemaphore( _sem ); -#endif } __FIT_DECLSPEC int wait_time( const ::timespec *t ); // wait for time t, or signal @@ -1343,9 +1189,6 @@ #ifdef _PTHREADS return sem_trywait( &_sem ); #endif -#ifdef __FIT_NOVELL_THREADS - return ExamineLocalSemaphore( _sem ) > 0 ? WaitOnLocalSemaphore( _sem ) : -1; -#endif } int post() @@ -1359,9 +1202,6 @@ #ifdef _PTHREADS return sem_post( &_sem ); #endif -#ifdef __FIT_NOVELL_THREADS - return SignalLocalSemaphore( _sem ); -#endif } int value() @@ -1378,9 +1218,6 @@ return e == 0 ? v : -1; #endif -#ifdef __FIT_NOVELL_THREADS - return ExamineLocalSemaphore( _sem ); -#endif } protected: @@ -1394,9 +1231,6 @@ #ifdef _PTHREADS sem_t _sem; #endif -#ifdef __FIT_NOVELL_THREADS - LONG _sem; -#endif private: __Semaphore( const __Semaphore& ) { } @@ -1428,13 +1262,6 @@ return -1; // not implemented # endif #endif -#ifdef __FIT_NOVELL_THREADS - time_t ct = time( 0 ); - time_t _conv = abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000; - - unsigned ms = _conv >= ct ? _conv - ct : 1; - return TimedWaitOnLocalSemaphore( _sem, ms ); -#endif } template <bool SCOPE> @@ -1461,10 +1288,6 @@ return -1; // not implemented # endif #endif -#ifdef __FIT_NOVELL_THREADS - unsigned ms = interval->tv_sec * 1000 + interval->tv_nsec / 1000000; - return TimedWaitOnLocalSemaphore( _sem, ms ); -#endif } template <bool SCOPE> @@ -1534,10 +1357,6 @@ typedef thread_key_t thread_key_type; typedef thread_t thread_id_type; #endif -#ifdef __FIT_NOVELL_THREADS - typedef void * thread_key_type; - typedef int thread_id_type; -#endif enum { // thread mode flags @@ -1562,13 +1381,6 @@ suspended = CREATE_SUSPENDED, daemon = detached, #endif -#ifdef __FIT_NOVELL_THREADS - bound = 0, - detached = 0x2, - new_lwp = 0, - suspended = 0, - daemon = detached, -#endif // state flags goodbit = 0x00, badbit = 0x01 @@ -1675,9 +1487,6 @@ #ifdef __FIT_WIN32THREADS unsigned long _thr_id; #endif -#ifdef __FIT_NOVELL_THREADS - __Condition<false> _thr_join; -#endif entrance_type _entrance; void *_param; size_t _param_sz; @@ -1692,15 +1501,12 @@ #ifdef __FIT_WIN32THREADS friend unsigned long __stdcall _xcall( void *p ); #endif -#ifdef __FIT_NOVELL_THREADS - friend void _xcall( void * ); -#endif }; template <bool SCOPE> int __Condition<SCOPE>::try_wait_time( const ::timespec *abstime ) { -#if defined(__FIT_WIN32THREADS) || defined(__FIT_NOVELL_THREADS) +#if defined(__FIT_WIN32THREADS) MT_LOCK( _lock ); #endif #if defined(__FIT_UITHREADS) || defined(_PTHREADS) @@ -1743,17 +1549,11 @@ return ret; #endif // _PTHREADS || __FIT_UITHREADS -#ifdef __FIT_NOVELL_THREADS - time_t ct = time( 0 ); - unsigned ms = abstime->tv_sec >= ct ? (abstime->tv_sec - ct) * 1000 + abstime->tv_nsec / 1000000 : 1; - MT_UNLOCK( _lock ); - return TimedWaitOnLocalSemaphore( _cond, ms ); -#endif #ifdef _NOTHREADS return 0; #endif } -#if defined(__FIT_WIN32THREADS) || defined(__FIT_NOVELL_THREADS) +#if defined(__FIT_WIN32THREADS) MT_UNLOCK( _lock ); #endif return 0; @@ -1762,7 +1562,7 @@ template <bool SCOPE> int __Condition<SCOPE>::try_wait_delay( const ::timespec *interval ) { -#if defined(__FIT_WIN32THREADS) || defined(__FIT_NOVELL_THREADS) +#if defined(__FIT_WIN32THREADS) MT_LOCK( _lock ); #endif #if defined(__FIT_UITHREADS) || defined(_PTHREADS) @@ -1809,17 +1609,13 @@ return ret; #endif // _PTHREADS || __FIT_UITHREADS -#ifdef __FIT_NOVELL_THREADS - MT_UNLOCK( _lock ); - return TimedWaitOnLocalSemaphore( _cond, interval->tv_sec * 1000 + interval->tv_nsec / 1000000 ); -#endif #ifdef _NOTHREADS return 0; #endif } -#if defined(__FIT_WIN32THREADS) || defined(__FIT_NOVELL_THREADS) +#if defined(__FIT_WIN32THREADS) MT_UNLOCK( _lock ); #endif return 0; @@ -1870,14 +1666,6 @@ return ret; #endif -#ifdef __FIT_NOVELL_THREADS - MT_LOCK( _lock ); - _val = false; - time_t ct = time( 0 ); - unsigned ms = abstime->tv_sec >= ct ? (abstime->tv_sec - ct) * 1000 + abstime->tv_nsec / 1000000 : 1; - MT_UNLOCK( _lock ); - return TimedWaitOnLocalSemaphore( _cond, ms ); -#endif #ifdef _NOTHREADS return 0; #endif @@ -1909,13 +1697,6 @@ return this->wait_time( &ct ); #endif -#ifdef __FIT_NOVELL_THREADS - MT_LOCK( _lock ); - _val = false; - unsigned ms = interval->tv_sec * 1000 + interval->tv_nsec / 1000000; - MT_UNLOCK( _lock ); - return TimedWaitOnLocalSemaphore( _cond, ms ); -#endif #ifdef _NOTHREADS return 0; #endif Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-03-09 17:48:37 UTC (rev 1552) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-03-12 18:25:09 UTC (rev 1553) @@ -1,3 +1,9 @@ +2007-03-12 Petr Ovtchenkov <pt...@is...> + + * xmt.h, xmt.cc: code for Novell NetWare removed. + + * libxmt: version 1.10.3 + 2007-02-08 Petr Ovtchenkov <pt...@is...> * shm.h: process-shared barrier may be allocated in shared Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2007-03-09 17:48:37 UTC (rev 1552) +++ trunk/complement/explore/lib/mt/Makefile.inc 2007-03-12 18:25:09 UTC (rev 1553) @@ -1,8 +1,8 @@ -# -*- Makefile -*- Time-stamp: <07/02/02 20:56:56 ptr> +# -*- Makefile -*- Time-stamp: <07/03/12 20:14:01 ptr> LIBNAME = xmt MAJOR = 1 MINOR = 10 -PATCH = 2 +PATCH = 3 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/xmt.cc =================================================================== --- trunk/complement/explore/lib/mt/xmt.cc 2007-03-09 17:48:37 UTC (rev 1552) +++ trunk/complement/explore/lib/mt/xmt.cc 2007-03-12 18:25:09 UTC (rev 1553) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/02 21:34:56 ptr> +// -*- C++ -*- Time-stamp: <07/03/12 20:14:35 ptr> /* * Copyright (c) 1997-1999, 2002-2007 @@ -32,10 +32,6 @@ #include <memory> #include <functional> #include <cerrno> -#ifdef __FIT_NETWARE -# include <nwerrno.h> -# include <nwadv.h> -#endif #include <string> #ifdef __linux @@ -86,16 +82,11 @@ static pid_t _pid = syscall( SYS_getpid ); static pid_t _ppid = syscall( SYS_getppid ); -#ifdef __FIT_NOVELL_THREADS -xmt::Thread::thread_key_type _mt_key = 0; -#else // !__FIT_NOVELL_THREADS xmt::Thread::thread_key_type _mt_key = __STATIC_CAST(xmt::Thread::thread_key_type,-1); # ifndef __FIT_WIN32THREADS void *_uw_save = 0; # endif -#endif // !__FIT_NOVELL_THREADS - #ifdef _PTHREADS xmt::Mutex _F_lock; # define _F_locklock xmt::detail::_F_lock.lock(); @@ -106,7 +97,7 @@ # error "Unimplemented" #endif -#if defined(__FIT_WIN32THREADS) || defined(__FIT_NOVELL_THREADS) +#if defined(__FIT_WIN32THREADS) # define _F_locklock # define _F_lockunlock #endif @@ -244,10 +235,6 @@ # endif // !(__FreeBSD__ || __OpenBSD__) #endif // __FIT_UITHREADS || _PTHREADS -#ifdef __FIT_NOVELL_THREADS -const Thread::thread_id_type Thread::bad_thread_id = EFAILURE; -#endif // __FIT_NOVELL_THREADS - Thread::thread_key_type& Thread::_mt_key( detail::_mt_key ); __FIT_DECLSPEC @@ -266,9 +253,6 @@ #ifdef __FIT_WIN32THREADS _uw_alloc_type *user_words = static_cast<_uw_alloc_type *>(TlsGetValue( _mt_key )); #endif -#ifdef __FIT_NOVELL_THREADS - _uw_alloc_type *user_words = *static_cast<_uw_alloc_type **>(GetThreadDataAreaPtr()); -#endif // __FIT_NOVELL_THREADS alloc.deallocate( user_words, uw_alloc_size ); user_words = 0; uw_alloc_size = 0; @@ -300,9 +284,6 @@ #ifdef __FIT_WIN32THREADS TlsSetValue( _mt_key, user_words ); #endif -#ifdef __FIT_NOVELL_THREADS - SaveThreadDataAreaPtr( user_words ); -#endif } else { #ifdef __FIT_UITHREADS thr_getspecific( _mt_key, &(static_cast<void *>(user_words)) ); @@ -313,9 +294,6 @@ #ifdef __FIT_WIN32THREADS user_words = static_cast<_uw_alloc_type *>(TlsGetValue( _mt_key )); #endif -#ifdef __FIT_NOVELL_THREADS - user_words = *static_cast<_uw_alloc_type **>(GetThreadDataAreaPtr()); -#endif if ( (__idx + 1) * sizeof( _uw_alloc_type ) > uw_alloc_size ) { size_t tmp = sizeof( _uw_alloc_type ) * (__idx + 1); #if !defined(_STLP_VERSION) && defined(_MSC_VER) @@ -337,9 +315,6 @@ #ifdef __FIT_WIN32THREADS TlsSetValue( _mt_key, user_words ); #endif -#ifdef __FIT_NOVELL_THREADS - *static_cast<_uw_alloc_type **>(GetThreadDataAreaPtr()) = user_words; -#endif } } @@ -403,8 +378,6 @@ return (_id != bad_thread_id) && (_id == pthread_self()); #elif defined(__FIT_UITHREADS) return (_id != bad_thread_id) && (_id == thr_self()); -#elif defined(__FIT_NOVELL_THREADS) - return (_id != bad_thread_id) && (_id == GetThreadID()); #elif defined(__FIT_WIN32THREADS) return (_id != bad_thread_id) && (_id == GetCurrentThread()); #else @@ -452,15 +425,6 @@ } #endif // __FIT_UITHREADS || PTHREADS -#ifdef __FIT_NOVELL_THREADS - rt.iword = 0; - if ( !_not_run() ) { - _thr_join.wait(); - // Locker lk( _llock ); - _rip_id = bad_thread_id; - } -#endif // __FIT_NOVELL_THREADS - return rt; } @@ -487,9 +451,6 @@ #ifdef __FIT_UITHREADS return thr_suspend( _id ); #endif -#ifdef __FIT_NOVELL_THREADS - return SuspendThread( _id ); -#endif } return -1; @@ -518,9 +479,6 @@ #ifdef __FIT_UITHREADS return thr_continue( _id ); #endif -#ifdef __FIT_NOVELL_THREADS - return ResumeThread( _id ); -#endif } return -1; @@ -563,9 +521,6 @@ #ifdef __FIT_WIN32THREADS ExitThread( code ); #endif -#ifdef __FIT_NOVELL_THREADS - ExitThread( EXIT_THREAD, code ); -#endif } #ifdef __FIT_UITHREADS @@ -786,17 +741,6 @@ _rip_id = _id = CreateThread( 0, 0, _xcall, this, (_flags & suspended), &_thr_id ); err = GetLastError(); #endif -#ifdef __FIT_NOVELL_THREADS - _id = BeginThread( _xcall, 0, 65536, this ); - if ( _id == bad_thread_id ) { - err = errno; // not ::errno, due to #define errno *__get_errno_ptr() - if ( (_flags & detached) == 0 ) { - _thr_join.signal(); - } - } else { - _rip_id = _id; - } -#endif if ( err != 0 ) { if ( psz > sizeof(void *) ) { // clear allocated here @@ -957,11 +901,7 @@ #if defined( __SUNPRO_CC ) && defined( __i386 ) Thread::_exit( ret.iword ); #endif -#ifdef __FIT_NOVELL_THREADS - if ( (me->_flags & detached) == 0 ) { - me->_thr_join.signal(); - } -#endif // __FIT_NOVELL_THREADS || __FIT_WIN32THREADS + return ret.pword; } #ifdef _WIN32 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-03-12 18:29:17
|
Revision: 1555 http://svn.sourceforge.net/complement/?rev=1555&view=rev Author: complement Date: 2007-03-12 11:29:11 -0700 (Mon, 12 Mar 2007) Log Message: ----------- EvManager.h, EvManager.cc: trace-related locks, flags and functions moved from static to member; fix bogus bug---missed return in << operator for gaddr_type; NetTransport.cc: directly use _trflags, due to function use lock now; _EventHandler.cc: ::getpid call may give lame result after fork; use xmt::getpid; libstem: library version 4.5.0 Modified Paths: -------------- trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Makefile.inc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/lib/stem/_EventHandler.cc trunk/complement/explore/test/stem/unit_test.cc Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2007-03-12 18:26:06 UTC (rev 1554) +++ trunk/complement/explore/include/stem/EvManager.h 2007-03-12 18:29:11 UTC (rev 1555) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/08 16:38:05 ptr> +// -*- C++ -*- Time-stamp: <07/03/12 17:18:41 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -163,12 +163,12 @@ __FIT_DECLSPEC void Remove( void * ); __FIT_DECLSPEC std::ostream& dump( std::ostream& ) const; - static void settrf( unsigned f ); - static void unsettrf( unsigned f ); - static void resettrf( unsigned f ); - static void cleantrf(); - static unsigned trflags(); - static void settrs( std::ostream * ); + void settrf( unsigned f ); + void unsettrf( unsigned f ); + void resettrf( unsigned f ); + void cleantrf(); + unsigned trflags() const; + void settrs( std::ostream * ); protected: bool unsafe_is_avail( addr_type id ) const @@ -256,9 +256,9 @@ xmt::Condition _cnd_queue; static std::string inv_key_str; - static xmt::Mutex _lock_tr; - static unsigned _trflags; - static std::ostream *_trs; + xmt::Mutex _lock_tr; + unsigned _trflags; + std::ostream *_trs; friend class Names; friend class NetTransportMgr; Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2007-03-12 18:26:06 UTC (rev 1554) +++ trunk/complement/explore/lib/stem/ChangeLog 2007-03-12 18:29:11 UTC (rev 1555) @@ -1,3 +1,17 @@ +2007-03-12 Petr Ovtchenkov <pt...@is...> + + * EvManager.h, EvManager.cc: trace-related locks, flags and + functions moved from static to member; fix bogus bug---missed + return in << operator for gaddr_type; + + * NetTransport.cc: directly use _trflags, due to function use + lock now; + + * _EventHandler.cc: ::getpid call may give lame result after + fork; use xmt::getpid; + + * libstem: library version 4.5.0 + 2007-02-08 Petr Ovtchenkov <pt...@is...> * EvManager.h, EvManager.cc: use deque instead of queue; Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2007-03-12 18:26:06 UTC (rev 1554) +++ trunk/complement/explore/lib/stem/EvManager.cc 2007-03-12 18:29:11 UTC (rev 1555) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/08 16:38:41 ptr> +// -*- C++ -*- Time-stamp: <07/03/12 18:53:45 ptr> /* * @@ -41,9 +41,6 @@ const addr_type endextaddr = 0xbfffffff; std::string EvManager::inv_key_str( "invalid key" ); -xmt::Mutex EvManager::_lock_tr; -unsigned EvManager::_trflags = 0; -std::ostream *EvManager::_trs = 0; std::ostream& operator <<( std::ostream& s, const gaddr_type& ga ); @@ -54,7 +51,9 @@ _x_low( begextaddr ), _x_high( endextaddr ), _x_id( _x_low ), - _dispatch_stop( false ) + _dispatch_stop( false ), + _trflags( 0 ), + _trs( 0 ) { // #ifndef __hpux _cnd_queue.set( false ); @@ -82,22 +81,25 @@ EvManager& me = *reinterpret_cast<EvManager *>(p); xmt::Thread::ret_code rt; rt.iword = 0; + xmt::Mutex& lq = me._lock_queue; + queue_type& in_ev_queue = me.in_ev_queue; + queue_type& out_ev_queue = me.out_ev_queue; while ( me.not_finished() ) { - MT_LOCK( me._lock_queue ); - me.in_ev_queue.swap( me.out_ev_queue ); - MT_UNLOCK( me._lock_queue ); - while ( !me.out_ev_queue.empty() ) { - me.Send( me.out_ev_queue.front() ); - me.out_ev_queue.pop_front(); + lq.lock(); + in_ev_queue.swap( out_ev_queue ); + lq.unlock(); + while ( !out_ev_queue.empty() ) { + me.Send( out_ev_queue.front() ); + out_ev_queue.pop_front(); } - MT_LOCK( me._lock_queue ); - if ( me.in_ev_queue.empty() && me.not_finished() ) { + lq.lock(); + if ( in_ev_queue.empty() && me.not_finished() ) { me._cnd_queue.set( false ); - MT_UNLOCK( me._lock_queue ); + lq.unlock(); me._cnd_queue.try_wait(); } else { - MT_UNLOCK( me._lock_queue ); + lq.unlock(); } } @@ -344,22 +346,41 @@ } void EvManager::settrf( unsigned f ) -{ _trflags |= f; } +{ + Locker _x1( _lock_tr ); + _trflags |= f; +} void EvManager::unsettrf( unsigned f ) -{ _trflags &= (0xffffffff & ~f); } +{ + Locker _x1( _lock_tr ); + _trflags &= (0xffffffff & ~f); +} void EvManager::resettrf( unsigned f ) -{ _trflags = f; } +{ + Locker _x1( _lock_tr ); + _trflags = f; +} void EvManager::cleantrf() -{ _trflags = 0; } +{ + Locker _x1( _lock_tr ); + _trflags = 0; +} -unsigned EvManager::trflags() -{ return _trflags; } +unsigned EvManager::trflags() const +{ + Locker _x1( _lock_tr ); + return _trflags; +} + void EvManager::settrs( std::ostream *s ) -{ _trs = s; } +{ + Locker _x1( _lock_tr ); + _trs = s; +} // Remove references to remote objects, that was announced via 'channel' // (related, may be, with socket connection) @@ -658,6 +679,8 @@ << "-" << setw(8) << hex << setfill( '0' ) << ga.addr; s.flags( f ); + + return s; } __FIT_DECLSPEC std::ostream& EvManager::dump( std::ostream& s ) const @@ -666,29 +689,40 @@ s << "Local map:\n"; s << hex << showbase; - for ( local_heap_type::const_iterator i = heap.begin(); i != heap.end(); ++i ) { - s << i->first << "\t=> " << i->second << "\n"; + { + Locker lk( _lock_heap ); + + for ( local_heap_type::const_iterator i = heap.begin(); i != heap.end(); ++i ) { + s << i->first << "\t=> " << i->second << "\n"; + } } s << "\nInfo map:\n"; + { + Locker lk( _lock_iheap ); - for ( info_heap_type::const_iterator i = iheap.begin(); i != iheap.end(); ++i ) { - s << i->first << "\t=> '" << i->second << "'\n"; + for ( info_heap_type::const_iterator i = iheap.begin(); i != iheap.end(); ++i ) { + s << i->first << "\t=> '" << i->second << "'\n"; + } } - s << "\nExternal address map:\n"; - for ( ext_uuid_heap_type::const_iterator i = _ex_heap.begin(); i != _ex_heap.end(); ++i ) { - s << hex << showbase << i->first << "\t=> " << i->second << "\n"; - } + { + Locker lk( _lock_xheap ); - s << "\nUnique Id to transport map:\n"; - for ( uuid_tr_heap_type::const_iterator i = _tr_heap.begin(); i != _tr_heap.end(); ++i ) { - s << i->first << "\t=> " << hex << i->second.first << " " << i->second.second.link << " " << dec << i->second.second.metric << "\n"; - } + s << "\nExternal address map:\n"; + for ( ext_uuid_heap_type::const_iterator i = _ex_heap.begin(); i != _ex_heap.end(); ++i ) { + s << hex << showbase << i->first << "\t=> " << i->second << "\n"; + } - s << "\nTransport to Unique Id map:\n"; - for ( tr_uuid_heap_type::const_iterator i = _ch_heap.begin(); i != _ch_heap.end(); ++i ) { - s << i->first << "\t=> " << i->second << "\n"; + s << "\nUnique Id to transport map:\n"; + for ( uuid_tr_heap_type::const_iterator i = _tr_heap.begin(); i != _tr_heap.end(); ++i ) { + s << i->first << "\t=> " << hex << i->second.first << " " << i->second.second.link << " " << dec << i->second.second.metric << "\n"; + } + + s << "\nTransport to Unique Id map:\n"; + for ( tr_uuid_heap_type::const_iterator i = _ch_heap.begin(); i != _ch_heap.end(); ++i ) { + s << i->first << "\t=> " << i->second << "\n"; + } } s << endl; Modified: trunk/complement/explore/lib/stem/Makefile.inc =================================================================== --- trunk/complement/explore/lib/stem/Makefile.inc 2007-03-12 18:26:06 UTC (rev 1554) +++ trunk/complement/explore/lib/stem/Makefile.inc 2007-03-12 18:29:11 UTC (rev 1555) @@ -1,8 +1,8 @@ -# -*- Makefile -*- Time-stamp: <06/11/30 16:51:10 ptr> +# -*- Makefile -*- Time-stamp: <07/03/12 20:19:19 ptr> LIBNAME = stem MAJOR = 4 -MINOR = 4 +MINOR = 5 PATCH = 0 SRC_CC = _EventHandler.cc NetTransport.cc EvManager.cc EvPack.cc crc.cc \ Names.cc Cron.cc Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2007-03-12 18:26:06 UTC (rev 1554) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2007-03-12 18:29:11 UTC (rev 1555) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/13 13:38:28 ptr> +// -*- C++ -*- Time-stamp: <07/03/12 17:25:23 ptr> /* * @@ -363,7 +363,7 @@ #ifdef __FIT_STEM_TRACE try { xmt::Locker lk(manager()->_lock_tr); - if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->trflags() & EvManager::tracenet) ) { + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracenet) ) { *manager()->_trs << "Pid/ppid: " << xmt::getpid() << "/" << xmt::getppid() << "\n"; manager()->dump( *manager()->_trs ) << endl; } @@ -376,7 +376,7 @@ #ifdef __FIT_STEM_TRACE try { xmt::Locker lk(manager()->_lock_tr); - if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->trflags() & (EvManager::tracefault)) ) { + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & (EvManager::tracefault)) ) { *manager()->_trs << __FILE__ << ":" << __LINE__ << " (" << xmt::getpid() << "/" << xmt::getppid() << ") " @@ -399,7 +399,7 @@ #ifdef __FIT_STEM_TRACE try { xmt::Locker lk(manager()->_lock_tr); - if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->trflags() & (EvManager::tracenet)) ) { + if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & (EvManager::tracenet)) ) { *manager()->_trs << __FILE__ << ":" << __LINE__ << endl; } } Modified: trunk/complement/explore/lib/stem/_EventHandler.cc =================================================================== --- trunk/complement/explore/lib/stem/_EventHandler.cc 2007-03-12 18:26:06 UTC (rev 1554) +++ trunk/complement/explore/lib/stem/_EventHandler.cc 2007-03-12 18:29:11 UTC (rev 1555) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/08 17:27:44 ptr> +// -*- C++ -*- Time-stamp: <07/03/12 19:36:45 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -261,7 +261,7 @@ __FIT_DECLSPEC gaddr_type EventHandler::self_glid() const { - return gaddr_type(xmt::hostid(), getpid(), _id ); + return gaddr_type(xmt::hostid(), xmt::getpid(), _id ); } } // namespace stem Modified: trunk/complement/explore/test/stem/unit_test.cc =================================================================== --- trunk/complement/explore/test/stem/unit_test.cc 2007-03-12 18:26:06 UTC (rev 1554) +++ trunk/complement/explore/test/stem/unit_test.cc 2007-03-12 18:29:11 UTC (rev 1555) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/03/09 20:43:27 ptr> +// -*- C++ -*- Time-stamp: <07/03/12 21:20:54 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -56,10 +56,9 @@ void echo(); void echo_net(); + void net_echo(); void peer(); void boring_manager(); - void net_echo(); - void net_echo2(); static xmt::Thread::ret_code thr1( void * ); static xmt::Thread::ret_code thr1new( void * ); @@ -361,7 +360,7 @@ fcnd.set( true ); int stat; - waitpid( child.pid(), &stat, 0 ); + BOOST_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); srv.close(); srv.wait(); @@ -376,6 +375,80 @@ // cerr << "Fine\n"; } +// same as echo_net(), but server in child process + +void stem_test::net_echo() +{ + try { + xmt::__Barrier<true>& b = *new ( shm_b.allocate( 1 ) ) xmt::__Barrier<true>(); + xmt::__Condition<true>& c = *new ( shm_cnd.allocate( 1 ) ) xmt::__Condition<true>(); + + c.set( false ); + + try { + xmt::fork(); + + // server part + { + std::sockmgr_stream_MP<stem::NetTransport> srv( 6995 ); + StEMecho echo( 0, "echo service"); + + // echo.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch ); + // echo.manager()->settrs( &std::cerr ); + + BOOST_REQUIRE( srv.good() ); + c.set( true ); // ok, server listen + + b.wait(); // server may go away + + srv.close(); + srv.wait(); + } + + exit( 0 ); + } + catch ( xmt::fork_in_parent& child ) { + // client part + + stem::NetTransportMgr mgr; + // mgr.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch | stem::EvManager::tracefault ); + // mgr.manager()->settrs( &std::cerr ); + + c.try_wait(); // wait server start + + stem::addr_type zero = mgr.open( "localhost", 6995 ); + + BOOST_REQUIRE( mgr.good() ); + BOOST_REQUIRE( zero != stem::badaddr ); + + EchoClient node; + stem::Event ev( NODE_EV_ECHO ); + ev.dest( zero ); + + ev.value() = node.mess; + node.Send( ev ); + + node.wait(); + + mgr.close(); + mgr.join(); + + b.wait(); // server may go away + + int stat; + BOOST_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + } + + (&c)->~__Condition<true>(); + shm_cnd.deallocate( &c, 1 ); + (&b)->~__Barrier<true>(); + shm_b.deallocate( &b, 1 ); + } + catch ( xmt::shm_bad_alloc& err ) { + BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); + } +} + extern "C" { static void dummy_signal_handler( int ) @@ -640,238 +713,6 @@ // ----------------- -#define EV_STU_MESS 0x801 -#define EV_STU_ECHO 0x802 - -class TestObj : - public stem::EventHandler -{ - public: - TestObj() - { } - - void reset() - { cnd.set( false ); } - - void wait() - { cnd.try_wait(); } - - const std::string& msg() const - { return m; } - - void mess( const stem::Event& ); - void echo( const stem::Event& ); - - private: - xmt::Condition cnd; - std::string m; - - DECLARE_RESPONSE_TABLE( TestObj, stem::EventHandler ); -}; - -void TestObj::mess( const stem::Event& ev ) -{ - // cerr << "hi!\n"; - m = ev.value(); - cnd.set( true ); -} - -void TestObj::echo( const stem::Event& ev ) -{ - m = ev.value(); - cnd.set( true ); -} - -DEFINE_RESPONSE_TABLE( TestObj ) - EV_EDS( ST_NULL, EV_STU_MESS, mess ) - EV_EDS( ST_NULL, EV_STU_ECHO, echo ) -END_RESPONSE_TABLE - -class EchoSrv : - public stem::EventHandler -{ - public: - EchoSrv(); - EchoSrv( stem::addr_type id ); - EchoSrv( stem::addr_type id, const char * ); - - void echo( const stem::Event& ); - - private: - DECLARE_RESPONSE_TABLE( EchoSrv, stem::EventHandler ); -}; - -EchoSrv::EchoSrv() -{ -} - -EchoSrv::EchoSrv( stem::addr_type id ) : - stem::EventHandler( id ) -{ -} - -EchoSrv::EchoSrv( stem::addr_type id, const char *info ) : - stem::EventHandler( id, info ) -{ -} - -// Unconditionally echo message - -void EchoSrv::echo( const stem::Event& ev ) -{ - cerr << __FILE__ << ":" << __LINE__ << endl; - ev.dest( ev.src() ); - Forward( ev ); -} - -DEFINE_RESPONSE_TABLE( EchoSrv ) - EV_EDS( ST_NULL, EV_STU_ECHO, echo ) -END_RESPONSE_TABLE - -void stem_test::net_echo() -{ - try { - xmt::__Barrier<true>& b = *new ( shm_b.allocate( 1 ) ) xmt::__Barrier<true>(); - xmt::__Condition<true>& c = *new ( shm_cnd.allocate( 1 ) ) xmt::__Condition<true>(); - - c.set( false ); - - try { - xmt::fork(); - - // server part - { - std::sockmgr_stream_MP<stem::NetTransport> srv( 6890 ); - EchoSrv echosrv( 0, "Echo service"); - - BOOST_REQUIRE( srv.good() ); - c.set( true ); // ok, server listen - - b.wait(); // server may go away - - srv.close(); - srv.wait(); - } - - exit( 0 ); - } - catch ( xmt::fork_in_parent& child ) { - // client part - - stem::NetTransportMgr client; - - c.try_wait(); // wait server start - - stem::addr_type a = client.open( "localhost", 6890 ); - - BOOST_REQUIRE( client.good() ); - BOOST_REQUIRE( a != stem::badaddr ); - - TestObj t1; - - t1.reset(); - - stem::Event ev( EV_STU_ECHO ); - ev.dest( a ); - - ev.value() = "echo"; - t1.Send( ev ); - - t1.wait(); - - BOOST_CHECK( t1.msg() == "echo" ); - - client.close(); - client.join(); - - b.wait(); // server may go away - - int stat; - BOOST_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); - } - - (&c)->~__Condition<true>(); - shm_cnd.deallocate( &c, 1 ); - (&b)->~__Barrier<true>(); - shm_b.deallocate( &b, 1 ); - } - catch ( xmt::shm_bad_alloc& err ) { - BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); - } -} - -void stem_test::net_echo2() -{ - try { - xmt::__Barrier<true>& b = *new ( shm_b.allocate( 1 ) ) xmt::__Barrier<true>(); - xmt::__Condition<true>& c = *new ( shm_cnd.allocate( 1 ) ) xmt::__Condition<true>(); - - c.set( false ); - - try { - xmt::fork(); - - // server part - { - std::sockmgr_stream_MP<stem::NetTransport> srv( 6890 ); - EchoSrv echosrv( 0, "Echo service"); - - BOOST_REQUIRE( srv.good() ); - c.set( true ); // ok, server listen - - b.wait(); // server may go away - - srv.close(); - srv.wait(); - } - - exit( 0 ); - } - catch ( xmt::fork_in_parent& child ) { - // client part - - stem::NetTransportMgr client; - - c.try_wait(); // wait server start - - stem::addr_type a = client.open( "localhost", 6890 ); - - BOOST_REQUIRE( client.good() ); - BOOST_REQUIRE( a != stem::badaddr ); - - TestObj t1; - - t1.reset(); - - stem::Event ev( EV_STU_ECHO ); - ev.dest( a ); - - ev.value() = "echo"; - t1.Send( ev ); - - t1.wait(); - - BOOST_CHECK( t1.msg() == "echo" ); - - client.close(); - client.join(); - - b.wait(); // server may go away - - int stat; - BOOST_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); - } - - (&c)->~__Condition<true>(); - shm_cnd.deallocate( &c, 1 ); - (&b)->~__Barrier<true>(); - shm_b.deallocate( &b, 1 ); - } - catch ( xmt::shm_bad_alloc& err ) { - BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); - } -} - // ----------------- struct stem_test_suite : @@ -895,10 +736,9 @@ test_case *echo_tc = BOOST_CLASS_TEST_CASE( &stem_test::echo, instance ); test_case *shm_init_tc = BOOST_CLASS_TEST_CASE( &stem_test::shm_init, instance ); test_case *echo_net_tc = BOOST_CLASS_TEST_CASE( &stem_test::echo_net, instance ); + test_case *net_echo_tc = BOOST_CLASS_TEST_CASE( &stem_test::net_echo, instance ); test_case *peer_tc = BOOST_CLASS_TEST_CASE( &stem_test::peer, instance ); test_case *boring_manager_tc = BOOST_CLASS_TEST_CASE( &stem_test::boring_manager, instance ); - test_case *net_echo_tc = BOOST_CLASS_TEST_CASE( &stem_test::net_echo, instance ); - // test_case *net_echo2_tc = BOOST_CLASS_TEST_CASE( &stem_test::net_echo2, instance ); test_case *shm_finit_tc = BOOST_CLASS_TEST_CASE( &stem_test::shm_finit, instance ); basic2_tc->depends_on( basic1_tc ); @@ -911,14 +751,12 @@ echo_tc->depends_on( basic2_tc ); echo_net_tc->depends_on( shm_init_tc ); echo_net_tc->depends_on( echo_tc ); + net_echo_tc->depends_on( shm_init_tc ); + net_echo_tc->depends_on( echo_net_tc ); peer_tc->depends_on( echo_tc ); peer_tc->depends_on( shm_init_tc ); boring_manager_tc->depends_on( peer_tc ); boring_manager_tc->depends_on( shm_init_tc ); - net_echo_tc->depends_on( shm_init_tc ); - net_echo_tc->depends_on( echo_net_tc ); - // net_echo2_tc->depends_on( shm_init_tc ); - // net_echo2_tc->depends_on( net_echo_tc ); shm_finit_tc->depends_on( shm_init_tc ); add( basic1_tc ); @@ -931,10 +769,9 @@ add( echo_tc ); add( shm_init_tc ); add( echo_net_tc ); + add( net_echo_tc ); add( peer_tc ); add( boring_manager_tc ); - add( net_echo_tc ); - // add( net_echo2_tc ); add( shm_finit_tc ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-06-08 19:40:28
|
Revision: 1585 http://svn.sourceforge.net/complement/?rev=1585&view=rev Author: complement Date: 2007-06-08 12:40:15 -0700 (Fri, 08 Jun 2007) Log Message: ----------- move gmake-specific files into gmake catalog Modified Paths: -------------- trunk/complement/explore/Makefiles/ChangeLog trunk/complement/explore/Makefiles/gmake/app/top.mak trunk/complement/explore/Makefiles/gmake/lib/top.mak trunk/complement/explore/Makefiles/top.mak trunk/complement/explore/configure Added Paths: ----------- trunk/complement/explore/Makefiles/gmake/clean.mak trunk/complement/explore/Makefiles/gmake/extern.mak Removed Paths: ------------- trunk/complement/explore/Makefiles/clean.mak trunk/complement/explore/Makefiles/extern.mak Property Changed: ---------------- trunk/complement/explore/Makefiles/ trunk/complement/explore/Makefiles/gmake/ Property changes on: trunk/complement/explore/Makefiles ___________________________________________________________________ Name: svn:ignore - config.mak + Modified: trunk/complement/explore/Makefiles/ChangeLog =================================================================== --- trunk/complement/explore/Makefiles/ChangeLog 2007-06-06 18:03:04 UTC (rev 1584) +++ trunk/complement/explore/Makefiles/ChangeLog 2007-06-08 19:40:15 UTC (rev 1585) @@ -1,3 +1,12 @@ +2007-06-08 Petr Ovtchenkov <pt...@is...> + + * clean.mak, extern.mak, config.mak: move to gmake catalog + + * top.mak: move some files in gmake catalog; replace USE_MAKE + by gmake; + + * gmake/app/top.mak, gmake/lib/top.mak: replace USE_MAKE by gmake. + 2007-05-31 Petr Ovtchenkov <pt...@is...> * gmake/app/gcc.mak, gmake/targets.mak, gmake/windows/rules-so.mak: Deleted: trunk/complement/explore/Makefiles/clean.mak =================================================================== --- trunk/complement/explore/Makefiles/clean.mak 2007-06-06 18:03:04 UTC (rev 1584) +++ trunk/complement/explore/Makefiles/clean.mak 2007-06-08 19:40:15 UTC (rev 1585) @@ -1,48 +0,0 @@ -# -*- Makefile -*- Time-stamp: <06/11/17 00:25:42 ptr> -# -# Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 -# Petr Ovtchenkov -# -# Portion Copyright (c) 1999-2001 -# Parallel Graphics Ltd. -# -# Licensed under the Academic Free License version 3.0 -# - -PHONY += clean distclean mostlyclean maintainer-clean uninstall - -define obj_clean -clean:: - @-rm -f $$($(1)_OBJ) $$($(1)_DEP) - @-rm -f $$($(1)_OBJ_DBG) $$($(1)_DEP_DBG) - @-rm -f $$($(1)_OBJ_STLDBG) $$($(1)_DEP_STLDBG) -endef - -clean:: - @-rm -f core core.* -ifdef PRGNAME - @-rm -f $(OBJ) $(DEP) - @-rm -f $(OBJ_DBG) $(DEP_DBG) - @-rm -f $(OBJ_STLDBG) $(DEP_STLDBG) -endif -ifdef LIBNAME - @-rm -f $(OBJ) $(DEP) - @-rm -f $(OBJ_DBG) $(DEP_DBG) - @-rm -f $(OBJ_STLDBG) $(DEP_STLDBG) -endif - -$(foreach prg,$(PRGNAMES),$(eval $(call obj_clean,$(prg)))) - -$(foreach prg,$(LIBNAMES),$(eval $(call obj_clean,$(prg)))) - -distclean:: clean -# $(DEPENDS_COLLECTION) removed before directory, -# see app/clean.mak and lib/clean.mak - -mostlyclean:: clean - @-rm -f $(DEPENDS_COLLECTION) - @-rm -f TAGS tags - -maintainer-clean:: distclean - @rm -f ${RULESBASE}/config.mak - @-rm -f TAGS tags Deleted: trunk/complement/explore/Makefiles/extern.mak =================================================================== --- trunk/complement/explore/Makefiles/extern.mak 2007-06-06 18:03:04 UTC (rev 1584) +++ trunk/complement/explore/Makefiles/extern.mak 2007-06-08 19:40:15 UTC (rev 1585) @@ -1,40 +0,0 @@ -# Time-stamp: <07/03/08 22:41:26 ptr> -# -# Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 -# Petr Ovtchenkov -# -# Portion Copyright (c) 1999-2001 -# Parallel Graphics Ltd. -# -# Licensed under the Academic Free License version 3.0 -# - -# Complement project: - -CoMT_DIR ?= ${SRCROOT} - -CoMT_LIB_DIR ?= ${INSTALL_LIB_DIR} -CoMT_LIB_DIR_DBG ?= ${INSTALL_LIB_DIR_DBG} -CoMT_LIB_DIR_STLDBG ?= ${INSTALL_LIB_DIR_STLDBG} -CoMT_BIN_DIR ?= ${INSTALL_BIN_DIR} -CoMT_BIN_DIR_DBG ?= ${INSTALL_BIN_DIR_DBG} -CoMT_BIN_DIR_STLDBG ?= ${INSTALL_BIN_DIR_STLDBG} - -CoMT_INCLUDE_DIR ?= ${CoMT_DIR}/include - -# boost (http://www.boost.org, http://boost.sourceforge.net) - -ifdef BOOST_DIR -BOOST_INCLUDE_DIR ?= ${BOOST_DIR} -endif - -# STLport library - -ifndef WITHOUT_STLPORT -STLPORT_DIR ?= ${HOME}/STLport.lab/STLport -endif - -ifdef STLPORT_DIR -STLPORT_LIB_DIR ?= $(STLPORT_DIR)/${TARGET_NAME}lib -STLPORT_INCLUDE_DIR ?= $(STLPORT_DIR)/stlport -endif Property changes on: trunk/complement/explore/Makefiles/gmake ___________________________________________________________________ Name: svn:ignore + config.mak Modified: trunk/complement/explore/Makefiles/gmake/app/top.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/app/top.mak 2007-06-06 18:03:04 UTC (rev 1584) +++ trunk/complement/explore/Makefiles/gmake/app/top.mak 2007-06-08 19:40:15 UTC (rev 1585) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <07/03/08 21:59:26 ptr> +# -*- makefile -*- Time-stamp: <07/06/08 23:35:09 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -33,9 +33,9 @@ LDFLAGS += ${LDSEARCH} -include ${RULESBASE}/${USE_MAKE}/app/${COMPILER_NAME}.mak -include ${RULESBASE}/${USE_MAKE}/app/rules.mak -include ${RULESBASE}/${USE_MAKE}/app/rules-install.mak +include ${RULESBASE}/gmake/app/${COMPILER_NAME}.mak +include ${RULESBASE}/gmake/app/rules.mak +include ${RULESBASE}/gmake/app/rules-install.mak define prog_clean clean:: Copied: trunk/complement/explore/Makefiles/gmake/clean.mak (from rev 1582, trunk/complement/explore/Makefiles/clean.mak) =================================================================== --- trunk/complement/explore/Makefiles/gmake/clean.mak (rev 0) +++ trunk/complement/explore/Makefiles/gmake/clean.mak 2007-06-08 19:40:15 UTC (rev 1585) @@ -0,0 +1,48 @@ +# -*- Makefile -*- Time-stamp: <06/11/17 00:25:42 ptr> +# +# Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 +# Petr Ovtchenkov +# +# Portion Copyright (c) 1999-2001 +# Parallel Graphics Ltd. +# +# Licensed under the Academic Free License version 3.0 +# + +PHONY += clean distclean mostlyclean maintainer-clean uninstall + +define obj_clean +clean:: + @-rm -f $$($(1)_OBJ) $$($(1)_DEP) + @-rm -f $$($(1)_OBJ_DBG) $$($(1)_DEP_DBG) + @-rm -f $$($(1)_OBJ_STLDBG) $$($(1)_DEP_STLDBG) +endef + +clean:: + @-rm -f core core.* +ifdef PRGNAME + @-rm -f $(OBJ) $(DEP) + @-rm -f $(OBJ_DBG) $(DEP_DBG) + @-rm -f $(OBJ_STLDBG) $(DEP_STLDBG) +endif +ifdef LIBNAME + @-rm -f $(OBJ) $(DEP) + @-rm -f $(OBJ_DBG) $(DEP_DBG) + @-rm -f $(OBJ_STLDBG) $(DEP_STLDBG) +endif + +$(foreach prg,$(PRGNAMES),$(eval $(call obj_clean,$(prg)))) + +$(foreach prg,$(LIBNAMES),$(eval $(call obj_clean,$(prg)))) + +distclean:: clean +# $(DEPENDS_COLLECTION) removed before directory, +# see app/clean.mak and lib/clean.mak + +mostlyclean:: clean + @-rm -f $(DEPENDS_COLLECTION) + @-rm -f TAGS tags + +maintainer-clean:: distclean + @rm -f ${RULESBASE}/config.mak + @-rm -f TAGS tags Copied: trunk/complement/explore/Makefiles/gmake/extern.mak (from rev 1582, trunk/complement/explore/Makefiles/extern.mak) =================================================================== --- trunk/complement/explore/Makefiles/gmake/extern.mak (rev 0) +++ trunk/complement/explore/Makefiles/gmake/extern.mak 2007-06-08 19:40:15 UTC (rev 1585) @@ -0,0 +1,40 @@ +# Time-stamp: <07/03/08 22:41:26 ptr> +# +# Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 +# Petr Ovtchenkov +# +# Portion Copyright (c) 1999-2001 +# Parallel Graphics Ltd. +# +# Licensed under the Academic Free License version 3.0 +# + +# Complement project: + +CoMT_DIR ?= ${SRCROOT} + +CoMT_LIB_DIR ?= ${INSTALL_LIB_DIR} +CoMT_LIB_DIR_DBG ?= ${INSTALL_LIB_DIR_DBG} +CoMT_LIB_DIR_STLDBG ?= ${INSTALL_LIB_DIR_STLDBG} +CoMT_BIN_DIR ?= ${INSTALL_BIN_DIR} +CoMT_BIN_DIR_DBG ?= ${INSTALL_BIN_DIR_DBG} +CoMT_BIN_DIR_STLDBG ?= ${INSTALL_BIN_DIR_STLDBG} + +CoMT_INCLUDE_DIR ?= ${CoMT_DIR}/include + +# boost (http://www.boost.org, http://boost.sourceforge.net) + +ifdef BOOST_DIR +BOOST_INCLUDE_DIR ?= ${BOOST_DIR} +endif + +# STLport library + +ifndef WITHOUT_STLPORT +STLPORT_DIR ?= ${HOME}/STLport.lab/STLport +endif + +ifdef STLPORT_DIR +STLPORT_LIB_DIR ?= $(STLPORT_DIR)/${TARGET_NAME}lib +STLPORT_INCLUDE_DIR ?= $(STLPORT_DIR)/stlport +endif Modified: trunk/complement/explore/Makefiles/gmake/lib/top.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/lib/top.mak 2007-06-06 18:03:04 UTC (rev 1584) +++ trunk/complement/explore/Makefiles/gmake/lib/top.mak 2007-06-08 19:40:15 UTC (rev 1585) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <03/10/10 16:15:53 ptr> +# -*- makefile -*- Time-stamp: <07/06/08 23:34:51 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -12,26 +12,26 @@ LDFLAGS ?= ifneq ("$(findstring $(OSNAME),darwin windows)","") -include ${RULESBASE}/${USE_MAKE}/${OSNAME}/lib.mak +include ${RULESBASE}/gmake/${OSNAME}/lib.mak else -include ${RULESBASE}/${USE_MAKE}/unix/lib.mak +include ${RULESBASE}/gmake/unix/lib.mak endif -include ${RULESBASE}/${USE_MAKE}/lib/${COMPILER_NAME}.mak +include ${RULESBASE}/gmake/lib/${COMPILER_NAME}.mak ifneq ("$(findstring $(OSNAME),windows)","") -include ${RULESBASE}/${USE_MAKE}/${OSNAME}/rules-so.mak +include ${RULESBASE}/gmake/${OSNAME}/rules-so.mak else -include ${RULESBASE}/${USE_MAKE}/unix/rules-so.mak +include ${RULESBASE}/gmake/unix/rules-so.mak endif -include ${RULESBASE}/${USE_MAKE}/lib/rules-a.mak +include ${RULESBASE}/gmake/lib/rules-a.mak ifneq ("$(findstring $(OSNAME),windows)","") -include ${RULESBASE}/${USE_MAKE}/${OSNAME}/rules-install-so.mak +include ${RULESBASE}/gmake/${OSNAME}/rules-install-so.mak else -include ${RULESBASE}/${USE_MAKE}/unix/rules-install-so.mak +include ${RULESBASE}/gmake/unix/rules-install-so.mak endif -include ${RULESBASE}/${USE_MAKE}/lib/rules-install-a.mak -include ${RULESBASE}/${USE_MAKE}/lib/clean.mak +include ${RULESBASE}/gmake/lib/rules-install-a.mak +include ${RULESBASE}/gmake/lib/clean.mak Modified: trunk/complement/explore/Makefiles/top.mak =================================================================== --- trunk/complement/explore/Makefiles/top.mak 2007-06-06 18:03:04 UTC (rev 1584) +++ trunk/complement/explore/Makefiles/top.mak 2007-06-08 19:40:15 UTC (rev 1585) @@ -1,4 +1,4 @@ -# Time-stamp: <07/03/08 22:57:35 ptr> +# Time-stamp: <07/06/08 23:23:03 ptr> # # Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 # Petr Ovtchenkov @@ -18,7 +18,7 @@ RULESBASE ?= $(SRCROOT)/Makefiles # include file, generated by configure, if available --include ${RULESBASE}/config.mak +-include ${RULESBASE}/gmake/config.mak ifndef COMPILER_NAME # gcc is default compiler, others specify explicitly; @@ -73,47 +73,44 @@ NOT_USE_NOSTDLIB := 1 endif -# define what make clone we use -USE_MAKE := gmake - ifndef OSNAME # identify OS and build date -include ${RULESBASE}/$(USE_MAKE)/sysid.mak +include ${RULESBASE}/gmake/sysid.mak endif # OS-specific definitions, like ln, install, etc. (guest host) -include ${RULESBASE}/$(USE_MAKE)/$(BUILD_OSNAME)/sys.mak +include ${RULESBASE}/gmake/$(BUILD_OSNAME)/sys.mak # target OS-specific definitions, like ar, etc. -include ${RULESBASE}/$(USE_MAKE)/$(OSNAME)/targetsys.mak +include ${RULESBASE}/gmake/$(OSNAME)/targetsys.mak # compiler, compiler options -include ${RULESBASE}/$(USE_MAKE)/$(COMPILER_NAME).mak +include ${RULESBASE}/gmake/$(COMPILER_NAME).mak # rules to make dirs for targets -include ${RULESBASE}/$(USE_MAKE)/targetdirs.mak +include ${RULESBASE}/gmake/targetdirs.mak # Extern projects for everyday usage and settings for ones -include ${RULESBASE}/extern.mak +include ${RULESBASE}/gmake/extern.mak # os-specific local rules (or other project-specific definitions) -include specific.mak # derive common targets (*.o, *.d), # build rules (including output catalogs) -include ${RULESBASE}/$(USE_MAKE)/targets.mak +include ${RULESBASE}/gmake/targets.mak # dependency -include ${RULESBASE}/$(USE_MAKE)/depend.mak +include ${RULESBASE}/gmake/depend.mak # general clean -include ${RULESBASE}/clean.mak +include ${RULESBASE}/gmake/clean.mak # if target is library, rules for library ifdef LIBNAME -include ${RULESBASE}/$(USE_MAKE)/lib/top.mak +include ${RULESBASE}/gmake/lib/top.mak endif # if target is program, rules for executable ifdef PRGNAME -include ${RULESBASE}/$(USE_MAKE)/app/top.mak +include ${RULESBASE}/gmake/app/top.mak else ifdef PRGNAMES -include ${RULESBASE}/$(USE_MAKE)/app/top.mak +include ${RULESBASE}/gmake/app/top.mak endif endif Modified: trunk/complement/explore/configure =================================================================== --- trunk/complement/explore/configure 2007-06-06 18:03:04 UTC (rev 1584) +++ trunk/complement/explore/configure 2007-06-08 19:40:15 UTC (rev 1585) @@ -1,8 +1,8 @@ #!/bin/sh -# Time-stamp: <06/11/10 15:47:21 ptr> +# Time-stamp: <07/06/08 23:24:03 ptr> -configmak=Makefiles/config.mak +configmak=Makefiles/gmake/config.mak # rm -f ${configmak} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-07-11 21:01:15
|
Revision: 1606 http://svn.sourceforge.net/complement/?rev=1606&view=rev Author: complement Date: 2007-07-11 14:01:08 -0700 (Wed, 11 Jul 2007) Log Message: ----------- step to interface like boost or http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2007/n2178.html; Locker* changed to basic_lock or basic_read_lock, internal lock flag added, lock/unlock methods added to basic_*_lock and exception lock_error added too. Spinlock was renamed to spinlock, LockerExt to native_scoped_lock. LockerRd renamed to rd_scoped_lock, LockerWr to wr_scoped_lock, __mutex_rw_base to __rw_mutex_base, mutexRW to rw_mutex; mutexRS renamed to recursive_mutex; LockerRS renamed to recursive_scoped_lock; obsolete LockerSDS removed; all Mutex replaced by mutex; replace Locker by scoped_lock. Barrier replaced by barrier, Semaphore by semaphore. Condition replaced by condition; libxmt: version 1.11.0 libsockios: Version 1.12.0 libstem: library version 4.6.0 This is result of merge with -r1584:1605 from branches/complement-xmt Modified Paths: -------------- trunk/complement/explore/include/mt/shm.h trunk/complement/explore/include/mt/thr_mgr.h trunk/complement/explore/include/mt/xmt.h trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/include/sockios/sockstream trunk/complement/explore/include/stem/Cron.h trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/include/stem/EventHandler.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/thr_mgr.cc trunk/complement/explore/lib/mt/time.cc trunk/complement/explore/lib/mt/uid.cc trunk/complement/explore/lib/mt/xmt.cc trunk/complement/explore/lib/sockios/ChangeLog trunk/complement/explore/lib/sockios/Makefile.inc trunk/complement/explore/lib/sockios/_sockmgr.cc trunk/complement/explore/lib/sockios/_sockstream.cc trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Makefile.inc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/lib/stem/_EventHandler.cc trunk/complement/explore/test/mt/flck.cc trunk/complement/explore/test/mt/lfs.cc trunk/complement/explore/test/mt/mt_test.cc trunk/complement/explore/test/mt/signal-1.cc trunk/complement/explore/test/mt/signal-3.cc trunk/complement/explore/test/sockios/bytes_in_socket.cc trunk/complement/explore/test/sockios/bytes_in_socket2.cc trunk/complement/explore/test/sockios/client-wc.cc trunk/complement/explore/test/sockios/close_socket.cc trunk/complement/explore/test/sockios/message.cc trunk/complement/explore/test/sockios/message.h trunk/complement/explore/test/sockios/sockios_test.cc trunk/complement/explore/test/stem/Echo.h trunk/complement/explore/test/stem/NameService.h trunk/complement/explore/test/stem/Node.h trunk/complement/explore/test/stem/NodeDL.h trunk/complement/explore/test/stem/unit_test.cc Modified: trunk/complement/explore/include/mt/shm.h =================================================================== --- trunk/complement/explore/include/mt/shm.h 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/include/mt/shm.h 2007-07-11 21:01:08 UTC (rev 1606) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/07 10:11:34 ptr> +// -*- C++ -*- Time-stamp: <07/07/11 22:38:41 ptr> /* * Copyright (c) 2006, 2007 @@ -70,31 +70,31 @@ }; template <> -struct ipc_sharable<xmt::__Condition<true> > +struct ipc_sharable<xmt::__condition<true> > { typedef std::__true_type is_ipc_sharable; }; template <> -struct ipc_sharable<xmt::__Semaphore<true> > +struct ipc_sharable<xmt::__semaphore<true> > { typedef std::__true_type is_ipc_sharable; }; template <> -struct ipc_sharable<xmt::__Barrier<true> > +struct ipc_sharable<xmt::__barrier<true> > { typedef std::__true_type is_ipc_sharable; }; template <> -struct ipc_sharable<xmt::__Mutex<false,true> > +struct ipc_sharable<xmt::__mutex<false,true> > { typedef std::__true_type is_ipc_sharable; }; template <> -struct ipc_sharable<xmt::__Mutex<true,true> > +struct ipc_sharable<xmt::__mutex<true,true> > { typedef std::__true_type is_ipc_sharable; }; @@ -303,7 +303,7 @@ template <class T> void named( const T& obj, int name ) { - xmt::__Locker<__Mutex<false,true> > lk( _lock ); + xmt::basic_lock<__mutex<false,true> > lk( _lock ); if ( _last == 255 ) { throw std::range_error( "too many named objects" ); } @@ -328,7 +328,7 @@ template <class T> T& named( int name ) { - xmt::__Locker<__Mutex<false,true> > lk( _lock ); + xmt::basic_lock<__mutex<false,true> > lk( _lock ); for ( int i = 0; _nm_table[i].name != -1; ++i ) { if ( _nm_table[i].name == name ) { ++_nm_table[i].count; @@ -341,7 +341,7 @@ template <class T> const T& named( int name ) const { - xmt::__Locker<__Mutex<false,true> > lk( _lock ); + xmt::basic_lock<__mutex<false,true> > lk( _lock ); for ( int i = 0; _nm_table[i].name != -1; ++i ) { if ( _nm_table[i].name == name ) { ++_nm_table[i].count; @@ -354,7 +354,7 @@ template <class T> void release( int name ) { - xmt::__Locker<__Mutex<false,true> > lk( _lock ); + xmt::basic_lock<__mutex<false,true> > lk( _lock ); for ( int i = 0; _nm_table[i].name != -1; ++i ) { if ( _nm_table[i].name == name ) { if ( --_nm_table[i].count == 0 ) { @@ -371,7 +371,7 @@ int count( int name ) const throw() { - xmt::__Locker<__Mutex<false,true> > lk( _lock ); + xmt::basic_lock<__mutex<false,true> > lk( _lock ); for ( int i = 0; _nm_table[i].name != -1; ++i ) { if ( _nm_table[i].name == name ) { return _nm_table[i].count; @@ -391,7 +391,7 @@ shm_name_mgr& operator =( const shm_name_mgr& ) { return *this; } - xmt::__Mutex<false,true> _lock; + xmt::__mutex<false,true> _lock; struct _name_rec { int name; @@ -420,7 +420,7 @@ { uint64_t _magic; size_type _first; - xmt::__Mutex<false,true> _lock; + xmt::__mutex<false,true> _lock; size_type _nm; }; @@ -463,7 +463,7 @@ if ( p != reinterpret_cast<pointer>(-1) && (force || _seg.count() <= 1) ) { _master *m = reinterpret_cast<_master *>( _seg.address() ); - (&m->_lock)->~__Mutex<false,true>(); + (&m->_lock)->~__mutex<false,true>(); if ( m->_nm != 0 ) { reinterpret_cast<shm_name_mgr<_Inst> *>(reinterpret_cast<char *>(p) + m->_nm)->~shm_name_mgr<_Inst>(); } @@ -480,7 +480,7 @@ if ( p != reinterpret_cast<pointer>(-1) ) { _master *m = reinterpret_cast<_master *>( p ); if ( m->_nm == 0 ) { - xmt::__Locker<xmt::__Mutex<false,true> > lk( m->_lock ); + xmt::basic_lock<xmt::__mutex<false,true> > lk( m->_lock ); void *nm = _traverse( &m->_first, sizeof(shm_name_mgr<_Inst>) ); m->_nm = reinterpret_cast<char *>(nm) - reinterpret_cast<char *>(p); return *new ( nm ) shm_name_mgr<_Inst>(); @@ -496,7 +496,7 @@ { _master *m = reinterpret_cast<_master *>( _seg.address() ); if ( m != reinterpret_cast<_master *>(-1) ) { - xmt::__Locker<xmt::__Mutex<false,true> > lk( m->_lock ); + xmt::basic_lock<xmt::__mutex<false,true> > lk( m->_lock ); return _traverse( &m->_first, n ); } @@ -512,8 +512,8 @@ static void init( _master& m ) { m._magic = MAGIC; - new ( &m._lock ) xmt::__Mutex<false,true>(); - xmt::__Locker<xmt::__Mutex<false,true> > lk( m._lock ); + new ( &m._lock ) xmt::__mutex<false,true>(); + xmt::basic_lock<xmt::__mutex<false,true> > lk( m._lock ); m._first = sizeof( _master ); m._nm = 0; _fheader& h = *new ( reinterpret_cast<char *>(&m) + sizeof(_master) ) _fheader(); @@ -535,7 +535,7 @@ n = max( n + (__align - n % __align) % __align, sizeof(_fheader) ); _master *m = reinterpret_cast<_master *>( _seg.address() ); if ( m != reinterpret_cast<_master *>(-1) && (reinterpret_cast<char *>(p) - reinterpret_cast<char *>(_seg.address())) < (_seg.max_size() + sizeof(_master) + sizeof(_aheader) ) ) { - xmt::__Locker<xmt::__Mutex<false,true> > lk( m->_lock ); + xmt::basic_lock<xmt::__mutex<false,true> > lk( m->_lock ); _aheader *a = reinterpret_cast<_aheader *>( reinterpret_cast<char *>(p) - sizeof(_aheader) ); size_type off = reinterpret_cast<char *>(p) - reinterpret_cast<char *>(_seg.address()); if ( m->_first == 0 ) { Modified: trunk/complement/explore/include/mt/thr_mgr.h =================================================================== --- trunk/complement/explore/include/mt/thr_mgr.h 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/include/mt/thr_mgr.h 2007-07-11 21:01:08 UTC (rev 1606) @@ -46,7 +46,7 @@ protected: _Sequence _M_c; - Mutex _lock; + mutex _lock; }; } // namespace xmt Modified: trunk/complement/explore/include/mt/xmt.h =================================================================== --- trunk/complement/explore/include/mt/xmt.h 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/include/mt/xmt.h 2007-07-11 21:01:08 UTC (rev 1606) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/03/12 20:09:11 ptr> +// -*- C++ -*- Time-stamp: <07/07/11 22:37:57 ptr> /* * Copyright (c) 1997-1999, 2002-2007 @@ -56,34 +56,16 @@ #ifdef _REENTRANT -# define MT_REENTRANT(point,nm) xmt::Locker nm(point) -# define MT_REENTRANT_RS(point,nm) xmt::LockerRS nm(point) -# define MT_REENTRANT_SDS(point,nm) xmt::LockerSDS nm(point) // obsolete, use MT_REENTRANT_RS +# define MT_REENTRANT(point,nm) xmt::scoped_lock nm(point) # define MT_LOCK(point) point.lock() # define MT_UNLOCK(point) point.unlock() -# ifdef __FIT_RWLOCK -# define MT_REENTRANT_RD(point,nm) xmt::LockerRd nm(point) -# define MT_REENTRANT_WR(point,nm) xmt::LockerWr nm(point) -# define MT_LOCK_RD(point) point.rdlock() -# define MT_LOCK_WR(point) point.wrlock() -# else // !__FIT_RWLOCK -# define MT_REENTRANT_RD(point,nm) ((void)0) -# define MT_REENTRANT_WR(point,nm) ((void)0) -# define MT_LOCK_RD(point) ((void)0) -# define MT_LOCK_WR(point) ((void)0) -# endif // __FIT_RWLOCK #else // !_REENTRANT # define MT_REENTRANT(point,nm) ((void)0) # define MT_REENTRANT_RS(point,nm) ((void)0) -# define MT_REENTRANT_SDS(point,nm) ((void)0) // obsolete, use MT_REENTRANT_RS # define MT_LOCK(point) ((void)0) # define MT_UNLOCK(point) ((void)0) -# define MT_REENTRANT_RD(point,nm) ((void)0) -# define MT_REENTRANT_WR(point,nm) ((void)0) -# define MT_LOCK_RD(point) ((void)0) -# define MT_LOCK_WR(point) ((void)0) #endif // _REENTRANT @@ -121,6 +103,32 @@ namespace xmt { + +// Exceptions + +// class thread_exit; +// class thread_cancel: public thread_exit; +// class thread_error: public exception; + +class lock_error : + public std::exception +{ + private: + int r_; + + public: + + explicit lock_error( int r ) : + r_( r ) + { } + + virtual char const *what() throw() + { return "std::lock_error"; } + + int error() const + { return r_; } +}; + namespace detail { #ifdef __FIT_PSHARED_MUTEX @@ -174,7 +182,7 @@ #endif // !_WIN32 -template <bool SCOPE> class __Condition; +template <bool SCOPE> class __condition; // if parameter SCOPE (process scope) true, PTHREAD_PROCESS_SHARED will // be used; otherwise PTHREAD_PROCESS_PRIVATE. @@ -256,7 +264,7 @@ #ifndef __FIT_WIN32THREADS private: - friend class __Condition<SCOPE>; + friend class __condition<SCOPE>; #endif }; @@ -288,23 +296,23 @@ #endif // __FIT_PTHREAD_SPINLOCK -// Portable Mutex implementation. If the parameter RECURSIVE_SAFE -// is true, Mutex will be recursive safe (detect deadlock). +// Portable mutex implementation. If the parameter RECURSIVE_SAFE +// is true, mutex will be recursive safe (detect deadlock). // If RECURSIVE_SAFE is false, implementation may not to be // recursive-safe. -// The SCOPE parameter designate Mutex scope---shared between +// The SCOPE parameter designate mutex scope---shared between // processes (true), or only inside threads of one process (false). // Note, that not all OS support interprocess mutex scope // (for example, Windows and Linux). template <bool RECURSIVE_SAFE, bool SCOPE> -class __Mutex : +class __mutex : public __mutex_base<RECURSIVE_SAFE,SCOPE> { public: - __Mutex() + __mutex() { } - ~__Mutex() + ~__mutex() { } void lock() @@ -321,7 +329,7 @@ } #if !defined( WIN32 ) || (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400) - int trylock() + int try_lock() { #ifdef _PTHREADS return pthread_mutex_trylock( &this->_M_lock ); @@ -352,29 +360,29 @@ } private: - __Mutex( const __Mutex& ) + __mutex( const __mutex& ) { } #ifndef __FIT_WIN32THREADS private: - friend class __Condition<SCOPE>; + friend class __condition<SCOPE>; #endif }; #ifdef __FIT_PTHREAD_SPINLOCK // Spinlock-based locks (IEEE Std. 1003.1j-2000) -template <bool RS, bool SCOPE> class __Spinlock; +template <bool RS, bool SCOPE> class __spinlock; template <bool SCOPE> -class __Spinlock<false,SCOPE> : +class __spinlock<false,SCOPE> : public __spinlock_base<SCOPE> { public: - __Spinlock() + __spinlock() { } - ~__Spinlock() + ~__spinlock() { } void lock() @@ -384,7 +392,7 @@ # endif } - int trylock() + int try_lock() { # ifdef _PTHREADS return pthread_spin_trylock( &this->_M_lock ); @@ -400,17 +408,22 @@ pthread_spin_unlock( &this->_M_lock ); # endif } + + private: + __spinlock( const __spinlock& ) + { } + }; template <bool SCOPE> -class __Spinlock<true,SCOPE> : // Recursive safe +class __spinlock<true,SCOPE> : // Recursive safe public __spinlock_base<SCOPE> { public: - __Spinlock() + __spinlock() { } - ~__Spinlock() + ~__spinlock() { } void lock() @@ -434,7 +447,7 @@ # endif // !_NOTHREADS } - int trylock() + int try_lock() { # ifdef _NOTHREADS return 0; @@ -485,6 +498,10 @@ # ifdef __FIT_UITHREADS thread_t _id; # endif + + private: + __spinlock( const __spinlock& ) + { } }; #endif // __FIT_PTHREAD_SPINLOCK @@ -505,11 +522,11 @@ // __mutex_base above). template <bool SCOPE> -class __Mutex<true,SCOPE> : // Recursive Safe +class __mutex<true,SCOPE> : // Recursive Safe public __mutex_base<true,SCOPE> { public: - __Mutex() : + __mutex() : _count( 0 ), # ifdef __FIT_UITHREADS _id( __STATIC_CAST(thread_t,-1) ) @@ -519,7 +536,7 @@ # endif { } - ~__Mutex() + ~__mutex() { } void lock() @@ -549,11 +566,11 @@ // Equivalent to lock(), except that if the mutex object referenced // by mutex is currently locked the call return immediately. // If mutex is currently owned by the calling thread, the mutex lock count - // incremented by one and the trylock() function immediately return success + // incremented by one and the try_lock() function immediately return success // (value 0). Otherwise, if mutex is currently owned by another thread, // return error (non-zero). - int trylock() + int try_lock() { # ifdef _NOTHREADS return 0; @@ -602,7 +619,7 @@ } private: - __Mutex( const __Mutex& ) + __mutex( const __mutex& ) { } protected: @@ -623,10 +640,10 @@ // Read-write mutex: IEEE Std 1003.1, 2001, 2004 Editions template <bool SCOPE> -class __mutex_rw_base +class __rw_mutex_base { public: - __mutex_rw_base() + __rw_mutex_base() { #ifdef _PTHREADS if ( SCOPE ) { @@ -659,7 +676,7 @@ #endif } - ~__mutex_rw_base() + ~__rw_mutex_base() { #ifdef _PTHREADS pthread_rwlock_destroy( &_M_lock ); @@ -675,7 +692,7 @@ } private: - __mutex_rw_base( const __mutex_rw_base& ) + __rw_mutex_base( const __rw_mutex_base& ) { } protected: @@ -693,14 +710,14 @@ }; template <bool SCOPE> -class __MutexRW : - public __mutex_rw_base<SCOPE> +class __rw_mutex : + public __rw_mutex_base<SCOPE> { public: - __MutexRW() + __rw_mutex() { } - ~__MutexRW() + ~__rw_mutex() { } void rdlock() @@ -718,7 +735,7 @@ #endif } - void wrlock() + void lock() { #ifdef _PTHREADS pthread_rwlock_wrlock( &this->_M_lock ); @@ -734,7 +751,7 @@ } #if !defined( WIN32 ) || (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400) - int tryrdlock() + int try_rdlock() { #ifdef _PTHREADS return pthread_rwlock_tryrdlock( &this->_M_lock ); @@ -753,7 +770,7 @@ #endif } - int trywrlock() + int try_lock() { #ifdef _PTHREADS return pthread_rwlock_trywrlock( &this->_M_lock ); @@ -790,96 +807,124 @@ } private: - __MutexRW( const __MutexRW& ) + __rw_mutex( const __rw_mutex& ) { } }; #endif // __FIT_RWLOCK template <class M> -class __Locker +class basic_lock { public: - __Locker( const M& point ) : - m( point ) - { const_cast<M&>(m).lock(); } - ~__Locker() - { const_cast<M&>(m).unlock(); } + basic_lock( const M& point, bool initially_locked = true ) : + m( point ), + lk( false ) + { if ( initially_locked ) lock(); } + ~basic_lock() + { if ( lk ) const_cast<M&>(m).unlock(); } + void lock() + { + if ( lk ) { + throw lock_error( 0 ); + } + const_cast<M&>(m).lock(); + lk = true; + } + + void unlock() + { + if ( !lk ) { + throw lock_error( 0 ); + } + lk = false; + const_cast<M&>(m).unlock(); + } + private: - __Locker( const __Locker& ) + basic_lock( const basic_lock& ) { } + basic_lock& operator =( const basic_lock& ) + { return *this; } + const M& m; + bool lk; }; #ifdef __FIT_RWLOCK -template <bool SCOPE> -class __LockerRd +template <class M> +class basic_read_lock { public: - __LockerRd( const __MutexRW<SCOPE>& point ) : - m( point ) - { const_cast<__MutexRW<SCOPE>&>(m).rdlock(); } - ~__LockerRd() - { const_cast<__MutexRW<SCOPE>&>(m).unlock(); } + basic_read_lock( const M& point, bool initially_locked = true ) : + m( point ), + lk( false ) + { if ( initially_locked ) lock(); } + ~basic_read_lock() + { if ( lk ) const_cast<M&>(m).unlock(); } - private: - __LockerRd( const __LockerRd& ) - { } - const __MutexRW<SCOPE>& m; -}; + void lock() + { + if ( lk ) { + throw lock_error( 0 ); + } + const_cast<M&>(m).rdlock(); + lk = true; + } -template <bool SCOPE> -class __LockerWr -{ - public: - __LockerWr( const __MutexRW<SCOPE>& point ) : - m( point ) - { const_cast<__MutexRW<SCOPE>&>(m).wrlock(); } - ~__LockerWr() - { const_cast<__MutexRW<SCOPE>&>(m).unlock(); } + void unlock() + { + if ( !lk ) { + throw lock_error( 0 ); + } + lk = false; + const_cast<M&>(m).unlock(); + } private: - __LockerWr( const __LockerWr& ) + basic_read_lock( const basic_read_lock& ) { } - const __MutexRW<SCOPE>& m; + basic_read_lock& operator =( const basic_read_lock& ) + { return *this; } + + const M& m; + bool lk; }; #endif // __FIT_RWLOCK -typedef __Mutex<false,false> Mutex; -typedef __Mutex<true,false> MutexRS; -typedef __Mutex<true,false> MutexSDS; // obsolete, use instead MutexRS +typedef __mutex<false,false> mutex; +typedef __mutex<true,false> recursive_mutex; #ifdef __FIT_RWLOCK -typedef __MutexRW<false> MutexRW; +typedef __rw_mutex<false> rw_mutex; #endif // __FIT_RWLOCK #ifdef __FIT_PTHREAD_SPINLOCK -typedef __Spinlock<false,false> Spinlock; -typedef __Spinlock<true,false> SpinlockRS; +typedef __spinlock<false,false> spinlock; +typedef __spinlock<true,false> recursive_spinlock; #endif // __FIT_RWLOCK -typedef __Locker<Mutex> Locker; -typedef __Locker<MutexRS> LockerRS; -typedef __Locker<MutexRS> LockerSDS; // obsolete, use instead LockerRS +typedef basic_lock<mutex> scoped_lock; +typedef basic_lock<recursive_mutex> recursive_scoped_lock; #ifdef __FIT_RWLOCK -typedef __LockerRd<false> LockerRd; -typedef __LockerWr<false> LockerWr; +typedef basic_read_lock<__rw_mutex<false> > rd_scoped_lock; +typedef basic_lock<__rw_mutex<false> > wr_scoped_lock; #endif // __FIT_RWLOCK #ifdef __FIT_PTHREAD_SPINLOCK -typedef __Locker<Spinlock> LockerSpin; -typedef __Locker<SpinlockRS> LockerSpinRS; +typedef basic_lock<spinlock> spin_scoped_lock; +typedef basic_lock<recursive_spinlock> recursive_spin_scoped_lock; #endif // __FIT_RWLOCK -class LockerExt +class native_scoped_lock { public: #ifdef _PTHREADS - explicit LockerExt( const pthread_mutex_t& m ) : + explicit native_scoped_lock( const pthread_mutex_t& m ) : #endif #ifdef __FIT_UITHREADS - explicit LockerExt( const mutex_t& m ) : + explicit native_scoped_lock( const mutex_t& m ) : #endif #ifdef __FIT_WIN32THREADS - explicit LockerExt( const CRITICAL_SECTION& m ) : + explicit native_scoped_lock( const CRITICAL_SECTION& m ) : #endif _M_lock( m ) { @@ -894,7 +939,7 @@ #endif } - ~LockerExt() + ~native_scoped_lock() { #ifdef _PTHREADS pthread_mutex_unlock( const_cast<pthread_mutex_t *>(&_M_lock) ); @@ -908,7 +953,7 @@ } private: - LockerExt( const LockerExt& m ) : + native_scoped_lock( const native_scoped_lock& m ) : _M_lock( m._M_lock ) { } #ifdef _PTHREADS @@ -923,10 +968,10 @@ }; template <bool SCOPE> -class __Condition +class __condition { public: - __Condition() : + __condition() : _val( true ) { #ifdef __FIT_WIN32THREADS @@ -948,7 +993,7 @@ #endif } - ~__Condition() + ~__condition() { #ifdef __FIT_WIN32THREADS CloseHandle( _cond ); @@ -963,7 +1008,7 @@ bool set( bool __v, bool _broadcast = false ) { - __Locker<__Mutex<false,SCOPE> > _x1( _lock ); + basic_lock<__mutex<false,SCOPE> > _x1( _lock ); bool tmp = _val; _val = __v; @@ -1000,15 +1045,11 @@ int try_wait() { -#if defined(__FIT_WIN32THREADS) - _lock.lock(); -#endif -#if defined(__FIT_UITHREADS) || defined(_PTHREADS) - __Locker<__Mutex<false,SCOPE> > _x1( _lock ); -#endif + basic_lock<__mutex<false,SCOPE> > _x1( _lock ); + if ( _val == false ) { #ifdef __FIT_WIN32THREADS - _lock.unlock(); + _x1.unlock(); if ( WaitForSingleObject( _cond, -1 ) == WAIT_FAILED ) { return -1; } @@ -1028,27 +1069,24 @@ return ret; #endif } -#if defined(__FIT_WIN32THREADS) - _lock.unlock(); -#endif + return 0; } int wait() { + basic_lock<__mutex<false,SCOPE> > lk( _lock ); + _val = false; + #ifdef __FIT_WIN32THREADS - MT_LOCK( _lock ); - _val = false; ResetEvent( _cond ); - MT_UNLOCK( _lock ); + lk.unlock(); if ( WaitForSingleObject( _cond, -1 ) == WAIT_FAILED ) { return -1; } return 0; #endif #if defined(_PTHREADS) || defined(__FIT_UITHREADS) - __Locker<__Mutex<false,SCOPE> > lk( _lock ); - _val = false; int ret; while ( !_val ) { ret = @@ -1085,7 +1123,7 @@ int signal( bool _broadcast = false ) { - __Locker<__Mutex<false,SCOPE> > _x1( _lock ); + basic_lock<__mutex<false,SCOPE> > _x1( _lock ); _val = true; #ifdef __FIT_WIN32THREADS @@ -1112,21 +1150,21 @@ #ifdef __FIT_UITHREADS cond_t _cond; #endif - __Mutex<false,SCOPE> _lock; + __mutex<false,SCOPE> _lock; bool _val; private: - __Condition( const __Condition& ) + __condition( const __condition& ) { } }; -typedef __Condition<false> Condition; +typedef __condition<false> condition; template <bool SCOPE> -class __Semaphore +class __semaphore { public: - __Semaphore( int cnt = 1 ) + __semaphore( int cnt = 1 ) { #ifdef __FIT_WIN32THREADS _sem = CreateSemaphore( NULL, cnt, INT_MAX, 0 ); // check! @@ -1140,7 +1178,7 @@ #endif } - ~__Semaphore() + ~__semaphore() { #ifdef __FIT_WIN32THREADS CloseHandle( _sem ); @@ -1232,14 +1270,14 @@ sem_t _sem; #endif private: - __Semaphore( const __Semaphore& ) + __semaphore( const __semaphore& ) { } }; -typedef __Semaphore<false> Semaphore; +typedef __semaphore<false> semaphore; template <bool SCOPE> -int __Semaphore<SCOPE>::wait_time( const ::timespec *abstime ) // wait for time t, or signal +int __semaphore<SCOPE>::wait_time( const ::timespec *abstime ) // wait for time t, or signal { #ifdef __FIT_WIN32THREADS time_t ct = time( 0 ); @@ -1265,7 +1303,7 @@ } template <bool SCOPE> -int __Semaphore<SCOPE>::wait_delay( const ::timespec *interval ) // wait, timeout is delay t, or signal +int __semaphore<SCOPE>::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; @@ -1291,10 +1329,10 @@ } template <bool SCOPE> -class __Barrier +class __barrier { public: - __Barrier( unsigned cnt = 2 ) + __barrier( unsigned cnt = 2 ) { #ifdef _PTHREADS pthread_barrierattr_t attr; @@ -1305,7 +1343,7 @@ #endif } - ~__Barrier() + ~__barrier() { #ifdef _PTHREADS pthread_barrier_destroy( &_barr ); @@ -1325,7 +1363,7 @@ #endif }; -typedef __Barrier<false> Barrier; +typedef __barrier<false> barrier; __FIT_DECLSPEC void fork() throw( fork_in_parent, std::runtime_error ); __FIT_DECLSPEC void become_daemon() throw( fork_in_parent, std::runtime_error ); @@ -1471,7 +1509,7 @@ static alloc_type alloc; static int _idx; // user words index static int _self_idx; // user words index, that word point to self - static Mutex _idx_lock; + static mutex _idx_lock; static thread_key_type& _mt_key; size_t uw_alloc_size; @@ -1481,7 +1519,7 @@ # ifndef __hpux // sorry, POSIX threads don't have suspend/resume calls, so it should // be simulated via cond_wait - __Condition<false> _suspend; + __condition<false> _suspend; # endif #endif #ifdef __FIT_WIN32THREADS @@ -1492,7 +1530,7 @@ size_t _param_sz; unsigned _flags; size_t _stack_sz; // stack size, if not 0 - // Mutex _llock; + // mutex _llock; friend class Init; // extern "C", wrap for thread_create #ifdef __unix @@ -1504,13 +1542,13 @@ }; 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) MT_LOCK( _lock ); #endif #if defined(__FIT_UITHREADS) || defined(_PTHREADS) - MT_REENTRANT( _lock, _x1 ); + scoped_lock _x1( _lock ); #endif if ( _val == false ) { #ifdef __FIT_WIN32THREADS @@ -1560,13 +1598,13 @@ } 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) MT_LOCK( _lock ); #endif #if defined(__FIT_UITHREADS) || defined(_PTHREADS) - MT_REENTRANT( _lock, _x1 ); + scoped_lock _x1( _lock ); #endif if ( _val == false ) { #ifdef WIN32 @@ -1622,7 +1660,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 ); @@ -1642,7 +1680,7 @@ return 0; #endif #ifdef _PTHREADS - MT_REENTRANT( _lock, _x1 ); // ?? + scoped_lock _x1( _lock ); // ?? _val = false; int ret = pthread_cond_timedwait( &_cond, &_lock._M_lock, abstime ); if ( ret == ETIMEDOUT ) { @@ -1651,7 +1689,7 @@ return ret; #endif // _PTHREADS #ifdef __FIT_UITHREADS - MT_REENTRANT( _lock, _x1 ); + scoped_lock _x1( _lock ); _val = false; int ret; while ( !_val ) { @@ -1672,7 +1710,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 ); Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2007-07-11 21:01:08 UTC (rev 1606) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/01 19:50:14 ptr> +// -*- C++ -*- Time-stamp: <07/07/11 21:14:42 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -29,7 +29,7 @@ template <class Connect> void sockmgr_stream_MP<Connect>::_open( sock_base::stype t ) { - MT_REENTRANT( _fd_lck, _1 ); + xmt::scoped_lock lk(_fd_lck); if ( is_open_unsafe() ) { if ( t == sock_base::sock_stream ) { _accept = &_Self_type::accept_tcp; @@ -100,7 +100,7 @@ // cerr << __FILE__ << ":" << __LINE__ << endl; // } if ( j->revents != 0 ) { - xmt::Locker _l( _c_lock ); + xmt::scoped_lock _l( _c_lock ); // We should distinguish closed socket from income message typename container_type::iterator i = find_if( _M_c.begin(), _M_c.end(), bind2nd( _M_comp, j->fd ) ); @@ -204,7 +204,7 @@ } if ( _pfd[0].revents != 0 ) { - MT_REENTRANT( _fd_lck, _1 ); + xmt::scoped_lock lk(_fd_lck); if ( !is_open_unsafe() ) { // may be already closed return false; } @@ -217,14 +217,14 @@ } try { - xmt::Locker _l( _c_lock ); + xmt::scoped_lock _l( _c_lock ); _M_c.push_back( _Connect() ); _M_c.back().open( _sd, addr.any ); _Connect *cl_new = &_M_c.back(); if ( cl_new->s.rdbuf()->in_avail() > 0 ) { // this is the case when user read from sockstream // in ctor above; push processing of this stream - MT_REENTRANT( _dlock, _1 ); + xmt::scoped_lock lk(_dlock); _conn_pool.push_back( --_M_c.end() ); _pool_cnd.set( true ); _observer_cnd.set( true ); @@ -404,7 +404,7 @@ if ( stream.is_open() && stream.good() ) { if ( stream.rdbuf()->in_avail() > 0 ) { // socket has buffered data, push it back to queue - MT_REENTRANT( me->_dlock, _1 ); + xmt::scoped_lock lk(me->_dlock); me->_conn_pool.push_back( c ); me->_observer_cnd.set( true ); me->_pool_cnd.set( true ); @@ -418,7 +418,7 @@ me->_conn_pool.erase( std::remove( me->_conn_pool.begin(), me->_conn_pool.end(), c ), me->_conn_pool.end() ); me->_dlock.unlock(); - xmt::Locker _l( me->_c_lock ); + xmt::scoped_lock _l( me->_c_lock ); me->_M_c.erase( c ); } } @@ -428,7 +428,7 @@ for ( idle_count = 0; idle_count < 2; ++idle_count ) { { - MT_REENTRANT( me->_dlock, _1 ); + xmt::scoped_lock lk(me->_dlock); if ( !me->_follow ) { break; } @@ -481,7 +481,7 @@ // std::swap( pool_size[0], pool_size[1] ); std::rotate( pool_size, pool_size, pool_size + 3 ); { - MT_REENTRANT( me->_dlock, _1 ); + xmt::scoped_lock lk(me->_dlock); pool_size[2] = static_cast<int>(me->_conn_pool.size()); tpop = me->_tpop; } @@ -535,7 +535,7 @@ template <class Connect> void sockmgr_stream_MP_SELECT<Connect>::_open( sock_base::stype t ) { - MT_REENTRANT( _fd_lck, _1 ); + xmt::scoped_lock lk(_fd_lck); if ( is_open_unsafe() ) { if ( t == sock_base::sock_stream ) { _accept = &_Self_type::accept_tcp; @@ -655,11 +655,11 @@ FD_ZERO( &_pfde ); // *** Set all listen sockets here... - MT_LOCK( _fd_lck ); + _fd_lck.lock(); FD_SET( fd_unsafe(), &_pfdr ); FD_SET( fd_unsafe(), &_pfde ); _fdmax = fd_unsafe(); - MT_UNLOCK( _fd_lck ); + _fd_lck.unlock(); for ( typename container_type::iterator i = _M_c.begin(); i != _M_c.end(); ++i ) { if ( (*i)->s->is_open() ) { FD_SET( (*i)->s->rdbuf()->fd(), &_pfdr ); @@ -677,7 +677,7 @@ return 0; // poll wait infinite, so it can't return 0 (timeout), so it return -1. } - MT_REENTRANT( _fd_lck, _1 ); + xmt::scoped_lock lk(_fd_lck); if ( !is_open_unsafe() || FD_ISSET( fd_unsafe(), &_pfde ) ) { // may be already closed return 0; } Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/include/sockios/sockmgr.h 2007-07-11 21:01:08 UTC (rev 1606) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/12 14:50:57 ptr> +// -*- C++ -*- Time-stamp: <07/07/11 20:57:31 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -85,19 +85,19 @@ public: bool is_open() const - { MT_REENTRANT( _fd_lck, _1 ); return is_open_unsafe(); } + { xmt::scoped_lock lk(_fd_lck); return is_open_unsafe(); } bool good() const { return _state == ios_base::goodbit; } sock_base::socket_type fd() const - { MT_REENTRANT( _fd_lck, _1 ); return fd_unsafe(); } + { xmt::scoped_lock lk(_fd_lck); return fd_unsafe(); } __FIT_DECLSPEC void shutdown( sock_base::shutdownflg dir ); void setoptions( sock_base::so_t optname, bool on_off = true, int __v = 0 ) { - MT_REENTRANT( _fd_lck, _1 ); + xmt::scoped_lock lk(_fd_lck); setoptions_unsafe( optname, on_off, __v ); } @@ -113,8 +113,8 @@ friend class Init; protected: - xmt::Mutex _fd_lck; - xmt::Condition _loop_cnd; + xmt::mutex _fd_lck; + xmt::condition _loop_cnd; }; class ConnectionProcessorTemplate_MP // As reference @@ -288,19 +288,19 @@ _Sequence _M_c; _Compare _M_comp; pfd_equal _pfdcomp; - xmt::Mutex _c_lock; + xmt::mutex _c_lock; _fd_sequence _pfd; int _cfd; // sock_base::socket_type _connect_pool_sequence _conn_pool; - xmt::Condition _pool_cnd; - xmt::Mutex _dlock; + xmt::condition _pool_cnd; + xmt::mutex _dlock; timespec _tpop; - xmt::Mutex _flock; + xmt::mutex _flock; bool _follow; - xmt::Condition _observer_cnd; + xmt::condition _observer_cnd; timespec _busylimit; // start new thread to process incoming // requests, if processing thread busy // more then _busylimit @@ -419,7 +419,7 @@ _Sequence _M_c; _Compare _M_comp; in_buf_avail _M_av; - xmt::Mutex _c_lock; + xmt::mutex _c_lock; fd_set _pfdr; fd_set _pfde; Modified: trunk/complement/explore/include/sockios/sockstream =================================================================== --- trunk/complement/explore/include/sockios/sockstream 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/include/sockios/sockstream 2007-07-11 21:01:08 UTC (rev 1606) @@ -546,8 +546,8 @@ virtual streamsize xsputn(const char_type *s, streamsize n); public: - xmt::Mutex _M_lock_w; // lock for writing - // _STL_mutex_base _M_lock; used for read lock + xmt::mutex _M_lock_w; // lock for writing + private: // Helper functions charT* _bbuf; charT* _ebuf; Modified: trunk/complement/explore/include/stem/Cron.h =================================================================== --- trunk/complement/explore/include/stem/Cron.h 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/include/stem/Cron.h 2007-07-11 21:01:08 UTC (rev 1606) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <06/12/15 03:20:55 ptr> +// -*- C++ -*- Time-stamp: <07/07/11 21:20:12 ptr> /* - * Copyright (c) 1998, 2002, 2003, 2005 + * Copyright (c) 1998, 2002, 2003, 2005, 2007 * Petr Ovtchenkov * * Copyright (c) 1999-2001 @@ -18,9 +18,7 @@ #include <config/feature.h> #endif -#ifndef __IOSFWD__ #include <iosfwd> -#endif #ifndef __stem_EventHandler_h #include <stem/EventHandler.h> @@ -157,7 +155,7 @@ static xmt::Thread::ret_code _loop( void * ); xmt::Thread _thr; - xmt::Condition cond; + xmt::condition cond; typedef __CronEntry value_type; typedef std::priority_queue<value_type, @@ -165,7 +163,7 @@ std::greater<value_type> > container_type; container_type _M_c; - xmt::Mutex _M_l; + xmt::mutex _M_l; private: DECLARE_RESPONSE_TABLE( Cron, EventHandler ); Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/include/stem/EvManager.h 2007-07-11 21:01:08 UTC (rev 1606) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/03/12 17:18:41 ptr> +// -*- C++ -*- Time-stamp: <07/07/11 21:17:27 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -123,31 +123,31 @@ bool is_avail( addr_type id ) const { - MT_REENTRANT( _lock_heap, _x1 ); + xmt::scoped_lock lk( _lock_heap ); return unsafe_is_avail(id); } const std::string who_is( addr_type id ) const { - MT_REENTRANT( _lock_iheap, _x1 ); + xmt::scoped_lock lk( _lock_iheap ); return unsafe_who_is( id ); } const std::string annotate( addr_type id ) const { - MT_REENTRANT( _lock_iheap, _x1 ); + xmt::scoped_lock lk( _lock_iheap ); return unsafe_annotate( id ); } void change_announce( addr_type id, const std::string& info ) { - MT_REENTRANT( _lock_iheap, _x1 ); + xmt::scoped_lock lk( _lock_iheap ); unsafe_change_announce( id, info ); } void change_announce( addr_type id, const char *info ) { - MT_REENTRANT( _lock_iheap, _x1 ); + xmt::scoped_lock lk( _lock_iheap ); unsafe_change_announce( id, info ); } @@ -155,7 +155,7 @@ void push( const Event& e ) { - MT_REENTRANT( _lock_queue, _x1 ); + xmt::scoped_lock lk( _lock_queue ); in_ev_queue.push_back( e ); _cnd_queue.set( true ); } @@ -246,17 +246,17 @@ bool _dispatch_stop; xmt::Thread _ev_queue_thr; - xmt::Spinlock _ev_queue_dispatch_guard; + xmt::spinlock _ev_queue_dispatch_guard; - xmt::Mutex _lock_heap; - xmt::Mutex _lock_iheap; - xmt::Mutex _lock_xheap; + xmt::mutex _lock_heap; + xmt::mutex _lock_iheap; + xmt::mutex _lock_xheap; - xmt::Mutex _lock_queue; - xmt::Condition _cnd_queue; + xmt::mutex _lock_queue; + xmt::condition _cnd_queue; static std::string inv_key_str; - xmt::Mutex _lock_tr; + xmt::mutex _lock_tr; unsigned _trflags; std::ostream *_trs; Modified: trunk/complement/explore/include/stem/EventHandler.h =================================================================== --- trunk/complement/explore/include/stem/EventHandler.h 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/include/stem/EventHandler.h 2007-07-11 21:01:08 UTC (rev 1606) @@ -542,7 +542,7 @@ // See comment near EventHandler::EventHandler() implementation // HistoryContainer& theHistory; HistoryContainer theHistory; - xmt::MutexRS _theHistory_lock; + xmt::recursive_mutex _theHistory_lock; public: @@ -705,7 +705,7 @@ { theEventsTable.Out( out ); } \ virtual bool DispatchTrace( const stem::Event& __e, std::ostream& __s )\ { \ - MT_REENTRANT_SDS( this->_theHistory_lock, _x1 ); \ + xmt::recursive_scoped_lock lk( this->_theHistory_lock ); \ return theEventsTable.DispatchTrace( theHistory.begin(), \ theHistory.end(), __e, __s ); } \ virtual const std::type_info& classtype() const \ @@ -718,12 +718,12 @@ protected: \ virtual bool Dispatch( const stem::Event& __e ) \ { \ - MT_REENTRANT_SDS( this->_theHistory_lock, _x1 ); \ + xmt::recursive_scoped_lock lk( this->_theHistory_lock ); \ return theEventsTable.Dispatch( this, theHistory.begin(), \ theHistory.end(), __e ); } \ virtual bool DispatchStub( const stem::Event& __e ) \ { \ - MT_REENTRANT_SDS( this->_theHistory_lock, _x1 ); \ + xmt::recursive_scoped_lock lk( this->_theHistory_lock ); \ return theEventsTable.DispatchStub( this, theHistory.begin(), \ theHistory.end(), __e ); } \ static __FIT_DECLSPEC evtable_type theEventsTable; \ Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-07-11 21:01:08 UTC (rev 1606) @@ -1,3 +1,35 @@ +2007-07-12 Petr Ovtchenkov <pt...@is...> + + * libxmt: version 1.11.0 + +2007-07-11 Petr Ovtchenkov <pt...@is...> + + * xmt.h, shm.h: Condition replaced by condition; + + * xmt.h, shm.h: Barrier replaced by barrier, Semaphore by semaphore. + +2007-06-29 Petr Ovtchenkov <pt...@is...> + + * xmt.h, xmt.cc, uid.cc, thr_mgr.cc: replace Locker by scoped_lock. + + * shm.h, xmt.h, xmt.cc, thr_mgr.h, uid.cc, time.cc: all Mutex replaced by mutex; + + * xmt.h: mutexRS renamed to recursive_mutex; LockerRS renamed to + recursive_scoped_lock; obsolete LockerSDS removed; + + * xmt.h: LockerRd renamed to rd_scoped_lock, LockerWr to wr_scoped_lock, + __mutex_rw_base to __rw_mutex_base, mutexRW to rw_mutex; + + * xmt.h: Spinlock was renamed to spinlock, LockerExt to native_scoped_lock. + +2007-06-14 Petr Ovtchenkov <pt...@is...> + + * xmt.h, xmt.cc, shm.h: step to interface like boost or + http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2007/n2178.html; + Locker* changed to basic_lock or basic_read_lock, internal lock flag + added, lock/unlock methods added to basic_*_lock and exception + lock_error added too. + 2007-03-12 Petr Ovtchenkov <pt...@is...> * xmt.h, xmt.cc: code for Novell NetWare removed. Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/lib/mt/Makefile.inc 2007-07-11 21:01:08 UTC (rev 1606) @@ -1,8 +1,8 @@ -# -*- Makefile -*- Time-stamp: <07/03/12 20:14:01 ptr> +# -*- Makefile -*- Time-stamp: <07/07/12 00:51:47 ptr> LIBNAME = xmt MAJOR = 1 -MINOR = 10 -PATCH = 3 +MINOR = 11 +PATCH = 0 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/thr_mgr.cc =================================================================== --- trunk/complement/explore/lib/mt/thr_mgr.cc 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/lib/mt/thr_mgr.cc 2007-07-11 21:01:08 UTC (rev 1606) @@ -121,7 +121,7 @@ __FIT_DECLSPEC void ThreadMgr::launch( Thread::entrance_type entrance, const void *p, size_t psz, unsigned flags, size_t stack_sz ) { - Locker lk( _lock ); + scoped_lock lk( _lock ); _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); // Thread *t = new Thread( entrance, p, psz, flags, stack_sz ); // cerr << (void *)t << " created\n"; @@ -132,13 +132,13 @@ __FIT_DECLSPEC void ThreadMgr::garbage_collector() { - Locker lk( _lock ); + scoped_lock lk( _lock ); _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); } ThreadMgr::container_type::size_type ThreadMgr::size() const { - Locker lk( _lock ); + scoped_lock lk( _lock ); // ThreadMgr::container_type::size_type sz = count_if( _M_c.begin(), _M_c.end(), good_thread() ); // cerr << "Sz: " << sz << endl; @@ -148,7 +148,7 @@ __FIT_DECLSPEC void ThreadMgr::signal( int sig ) { // cerr << "Signal!" << endl; - Locker lk( _lock ); + scoped_lock lk( _lock ); for_each( _M_c.begin(), _M_c.end(), bind2nd( thread_signal(), sig ) ); } Modified: trunk/complement/explore/lib/mt/time.cc =================================================================== --- trunk/complement/explore/lib/mt/time.cc 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/lib/mt/time.cc 2007-07-11 21:01:08 UTC (rev 1606) @@ -14,7 +14,7 @@ #include <sys/time.h> #ifdef _WIN32 -xmt::Mutex _l; +xmt::mutex _l; #endif std::string calendar_time( time_t t ) Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/lib/mt/uid.cc 2007-07-11 21:01:08 UTC (rev 1606) @@ -36,9 +36,9 @@ __uid_init::__uid_init() { - static Mutex _lk; + static mutex _lk; - Locker lock( _lk ); + scoped_lock lock( _lk ); ifstream f( "/proc/sys/kernel/random/boot_id" ); string tmp; Modified: trunk/complement/explore/lib/mt/xmt.cc =================================================================== --- trunk/complement/explore/lib/mt/xmt.cc 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/lib/mt/xmt.cc 2007-07-11 21:01:08 UTC (rev 1606) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/03/12 20:14:35 ptr> +// -*- C++ -*- Time-stamp: <07/06/14 10:10:54 ptr> /* * Copyright (c) 1997-1999, 2002-2007 @@ -88,7 +88,7 @@ # endif #ifdef _PTHREADS -xmt::Mutex _F_lock; +xmt::mutex _F_lock; # define _F_locklock xmt::detail::_F_lock.lock(); # define _F_lockunlock xmt::detail::_F_lock.unlock(); #endif @@ -220,7 +220,7 @@ Thread::alloc_type Thread::alloc; int Thread::_idx = 0; int Thread::_self_idx = 0; -Mutex Thread::_idx_lock; +mutex Thread::_idx_lock; #ifdef __FIT_WIN32THREADS const Thread::thread_id_type Thread::bad_thread_id = INVALID_HANDLE_VALUE; @@ -926,7 +926,7 @@ int Thread::xalloc() { - Locker _l( _idx_lock ); + scoped_lock _l( _idx_lock ); return _idx++; } Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/lib/sockios/ChangeLog 2007-07-11 21:01:08 UTC (rev 1606) @@ -1,3 +1,18 @@ +2007-07-12 Petr Ovtchenkov <pt...@is...> + + * libsockios: Version 1.12.0 + +2007-07-11 Petr Ovtchenkov <pt...@is...> + + * sockmgr.h, sockmgr.cc: Condition replaced by condition. + +2007-06-29 Petr Ovtchenkov <pt...@is...> + + * sockmgr.cc, sockios_test.cc: replace Locker by scoped_lock. + + * sockmgr.h, sockstream, _sockmgr.cc, _sockstream.cc: all + Mutex replaced by mutex + 2007-02-12 Petr Ovtchenkov <pt...@is...> * sockmgr.h, _sockmgr.cc: use Init technique to initialize Modified: trunk/complement/explore/lib/sockios/Makefile.inc =================================================================== --- trunk/complement/explore/lib/sockios/Makefile.inc 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/lib/sockios/Makefile.inc 2007-07-11 21:01:08 UTC (rev 1606) @@ -1,8 +1,8 @@ -# -*- Makefile -*- Time-stamp: <07/02/01 19:53:51 ptr> +# -*- Makefile -*- Time-stamp: <07/07/12 00:53:38 ptr> LIBNAME = sockios MAJOR = 1 -MINOR = 11 +MINOR = 12 PATCH = 0 SRC_CC = _sockstream.cc _sockmgr.cc SRC_C = freebsd/getaddrinfo.c \ Modified: trunk/complement/explore/lib/sockios/_sockmgr.cc =================================================================== --- trunk/complement/explore/lib/sockios/_sockmgr.cc 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/lib/sockios/_sockmgr.cc 2007-07-11 21:01:08 UTC (rev 1606) @@ -51,7 +51,7 @@ void basic_sockmgr::Init::_guard( int direction ) { - static xmt::Mutex _init_lock; + static xmt::mutex _init_lock; static int _count = 0; if ( direction ) { Modified: trunk/complement/explore/lib/sockios/_sockstream.cc =================================================================== --- trunk/complement/explore/lib/sockios/_sockstream.cc 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/lib/sockios/_sockstream.cc 2007-07-11 21:01:08 UTC (rev 1606) @@ -66,7 +66,7 @@ static int __glob_init_cnt = 0; static int __glob_init_wsock2 = 0; -static xmt::Mutex _SI_lock; +static xmt::mutex _SI_lock; enum { WINDOWS_NT_4, Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/lib/stem/ChangeLog 2007-07-11 21:01:08 UTC (rev 1606) @@ -1,5 +1,22 @@ +2007-07-12 Petr Ovtchenkov <pt...@is...> + + * libstem: library version 4.6.0 + +2007-07-11 Petr Ovtchenkov <pt...@is...> + + * EvManager.h, Cron.h: Condition replaced by condition. + 2007-06-29 Petr Ovtchenkov <pt...@is...> + * NetTransport.cc, EvManager.cc: replace Locker by scoped_lock. + + * EvManager.cc, _EventHandler.cc, EventHandler.h, EvManager.h, Cron.h: + all Mutex replaced by mutex + + * EventHandler.h, _EventHandler.cc: mutexRS renamed to recursive_mutex; + LockerRS renamed to recursive_scoped_lock; obsolete LockerSDS + replaced by recursive_scoped_lock; + * _EventHandler.cc: call destructor, don't free memory here; acquire lock (missed lock). Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2007-07-11 19:56:54 UTC (rev 1605) +++ trunk/complement/explore/lib/stem/EvManager.cc 2007-07-11 21:01:08 UTC (rev 1606) @@ -72,7 +72,7 @@ bool EvManager::not_finished() { - xmt::LockerSpin _lk( _ev_queue_dispatch_guard ); + xmt::spin_scoped_lock _lk( _ev_queue_dispatch_guard ); return !_dispatch_stop; } @@ -81,7 +81,7 @@ EvManager& me = *reinterpret_cast<EvManager *>(p); xmt::Thread::ret_code rt; rt.iword = 0; - xmt::Mutex& lq = me._lock_queue; + xmt::mutex& lq = me._lock_queue; queue_type& in_ev_queue = me.in_ev_queue; queue_type& out_ev_queue = me.out_ev_queue; @@ -111,19 +111,19 @@ { addr_type id; { - Locker lk( _lock_heap ); + scoped_lock lk( _lock_heap ); id = create_unique(); heap[id] = object; } { - Locker lk( _lock_xheap ); + scoped_lock lk( _lock_xheap ); gaddr_type& gaddr = _ex_heap[id]; gaddr.hid = xmt::hostid(); gaddr.pid = xmt::getpid(); gaddr.addr = id; } - Locker lk( _lock_iheap ); + scoped_lock lk( _lock_iheap ); iheap[id] = info; return id; @@ -142,21 +142,21 @@ if ( (id & extbit) ) { return badaddr; } else { - Locker _x1( _lock_heap ); + scoped_lock _x1( _lock_heap ); if ( unsafe_is_avail( id ) ) { return badaddr; } heap[id] = object; } { - Locker lk( _lock_xheap ); + scoped_lock lk( _lock_xheap ); gaddr_type& gaddr = _ex_heap[id]; gaddr.hid = xmt::hostid(); gaddr.pid = xmt::getpid(); gaddr.addr = id; } - Locker _x1( _lock_iheap ); + scoped_lock _x1( _lock_iheap ); iheap[id] = info; return id; @@ -176,14 +176,14 @@ { addr_type id; { - Locker _x1( _lock_xheap ); + scoped_lock _x1( _lock_xheap ); id = create_unique_x(); _ex_heap[id] = addr; _tr_heap.insert( make_pair( addr, make_pair( id, tr ) ) ); _ch_heap.insert( make_pair( tr.link, addr ) ); } { - Locker _x1( _lock_iheap ); + scoped_lock _x1( _lock_iheap ); iheap[id] = info; } @@ -205,13 +205,13 @@ addr_type id; if ( addr.hid == xmt::hostid() && addr.pid == xmt::getpid() ) { // local if ( addr.addr & extbit ) { // may be transit object - Locker lk( _lock_xheap ); + scoped_lock lk( _lock_xheap ); pair<uuid_tr_heap_type::const_iterator,uuid_tr_heap_type::const_iterator> range = _tr_heap.equal_range( addr ); if ( range.first != range.second ) { // transport present return min_element( range.first, range.second, tr_compare )->second.first; } } else { // may be local object - Locker lk( _lock_heap ); + scoped_lock lk( _lock_heap ); local_heap_type::const_iterator i = heap.find( addr.addr ); if ( i != heap.end() ) { return i->first; @@ -219,7 +219,7 @@ } return badaddr; // don't know what I can made } else { // foreign object - Locker lk( _lock_xheap ); + scoped_lock lk( _lock_xheap ); pair<uuid_tr_heap_type::const_iterator,uuid_tr_heap_type::const_iterator> tr_range = _tr_heap.equal_range( addr ); if ( tr_range.first != tr_range.second ) { // transport present return min_element( tr_range.first, tr_range.second, tr_compare )->second.first; @@ -239,7 +239,7 @@ _ex_heap[id] = addr; } { - Locker lk( _lock_iheap ); + scoped_lock lk( _lock_iheap ); iheap[id] = info; } return id; @@ -256,7 +256,7 @@ bool EvManager::Unsubscribe( addr_type id ) { if ( (id & extbit) ) { - Locker _x1( _lock_xheap ); + scoped_lock _x1( _lock_xheap ); gaddr_type& addr = _ex_heap[id]; pair<uuid_tr_heap_type::iterator,uuid_tr_heap_type::iterator> range = _tr_heap.equal_range( addr ); @@ -277,12 +277,12 @@ } _ex_heap.erase( id ); } else { - Locker _x1( _lock_heap ); + scoped_lock _x1( _lock_heap ); heap.erase( id ); // Notify remotes? } - Locker _x1( _lock_iheap ); + scoped_lock _x1( _lock_iheap ); iheap.erase( id ); return true; @@ -294,7 +294,7 @@ if ( addr.hid == xmt::hostid() && addr.pid == xmt::getpid() ) { // this host, this process if ( (addr.addr & extbit) == 0 ) { // looks like local object - Locker _x1( _lock_heap ); + scoped_lock _x1( _lock_heap ); local_heap_type::const_iterator l = heap.find( addr.addr ); if ( l != heap.end() ) { return addr.addr; // l->first @@ -307,7 +307,7 @@ // peer don't know host ids, used as access to 'standard' services and initial // communication if ( (addr.addr & extbit) == 0 && addr.addr <= _low ) { - Locker _x1( _lock_heap ); + scoped_lock _x1( _lock_heap ); local_heap_type::const_iterator l = heap.find( addr.addr ); if ( l != heap.end() ) { return addr.addr; // l->first @@ -318,7 +318,7 @@ } #endif - Locker _x1( _lock_xheap ); + scoped_lock _x1( _lock_xheap ); pair<uuid_tr_heap_type::const_iterator,uuid_tr_heap_type::const_iterator> range = _tr_heap.equal_range( addr ); if ( range.first != range.second ) { // transport present return min_element( range.first, range.second, tr_compare )->second.first; @@ -329,7 +329,7 @@ __FIT_DECLSPEC gaddr_type EvManager::reflect( addr_type addr ) const { - Locker lk( _lock_xheap ); + scoped_lock lk( _lock_xheap ); ext_uuid_heap_type::const_iterator i = _ex_heap.find( addr ); if ( i != _ex_heap.end() ) { return i->second; @@ -340,45 +340,45 @@ __FIT_DECLSPEC void EvManager::Remove( void *channel ) { - Locker _x1( _lock_xheap ); - Locker _x2( _lock_iheap ); + scoped_lock _x1( _lock_xheap ); + scoped_lock _x2( _lock_iheap ); unsafe_Remove( channel ); } void EvManager::settrf( unsigned f ) { - Locker _x1( _lock_tr ); + scoped_lock _x1( _lock_tr ); _trflags |= f; } void EvManager::unsettrf( unsigned f ) { - Locker _x1( _lock_tr ); + scoped_lock _x1( _lock_tr ); _trflags &= (0xffffffff & ~f); } void EvManager::resettrf( unsigned f ) { - Locker _x1( _lock_tr ); + scoped_lock _x1( _lock_tr ); _trflags = f; } void EvManager::cleantrf() { - Locker _x1( _lock_tr ); + scoped_lock _x1( _lock_tr ); _trflags = 0; } unsigned EvManager::trflags() const { - Locker _x1( _lock_tr ); + scoped_lock _x1( _lock_tr ); return _trflags; } void EvManager::settrs( std::ostream *s ) { - Locker _x1( _lock_tr ); + scoped_lock _x1( _lock_tr ); _trs = s; } @@ -407,7 +407,7 @@ __FIT_DECLSPEC const detail::transport& EvManager::transport( addr_type id ) const { - Locker _x1( _lock_xheap ); + scoped_lock _x1( _lock_xheap ); if ( (id & extbit) != 0 ) { ext_uuid_heap_type::const_iterator i = _ex_heap.find( id ); if ( i == _ex_heap.end() ) { @@ -470,7 +470,7 @@ if ( !reinterpret_cast<NetTransport_base *>(link)->push( e, gaddr_dst, gaddr_src) ) { #ifdef __FIT_STEM_TRACE try { - Locker lk(_lock_tr); + scoped_lock lk(_lock_tr); if ( _trs != 0 && _trs->good() && (_trflags & tracenet) ) { *_trs << "Remove net channel " << link << endl; } @@ -493,7 +493,7 @@ catch ( std::logic_error& err ) { // #ifdef __FIT_STEM_TRACE try { - Locker lk(_lock_tr); + scoped_lock lk(_lock_tr); if ( _trs != 0 && _trs->good() && (_trflags & tracefault) ) { *_trs << err.what() << " " << __FILE__ << ":" << __LINE__ << endl; @@ -507,7 +507,7 @@ catch ( std::runtime_error& err ) { // #ifdef __FIT_STEM_TRACE try { - Locker lk(_lock_tr); + scoped_lock lk(_lock_tr); if ( _trs != 0 && _trs->good() && (_trflags & tracefault) ) { *_trs << err.what() << " " << __FILE__ << ":" << __LINE__ << endl; @@ -521,7 +521,7 @@ catch ( ... ) { // #ifdef __FIT_STEM_TRACE try { - Locker lk(_lock_tr); + scoped_lock lk(_lock_tr); if ( _trs != 0 && _trs->good() && (_trflags & tracefault) ) { *_trs << "Unknown, uncatched exception: " << __FILE__ << ":" << __LINE__ << endl; @@ -545,7 +545,7 @@ try { #ifdef __FIT_STEM_TRACE try { - Locker lk(_lock_tr); + scoped_lock lk(_lock_tr); if ( _trs != 0 && _trs->good() && (_trflags & tracedispatch) ) { *_trs << object->classtype().name() << " (" << object << ")\n"; @@ -560,7 +560,7 @@ } catch ( std::logic_error& err ) { try { - Locker lk(_lock_tr); + scoped_lock lk(_lock_tr); if ( _trs != 0 && _trs->good() && (_trflags & tracefault) ) { *_trs << err.what() << "\n" << object->classtype().name() << " (" << object << ")\n"; @@ -573,7 +573,7 @@ } catch ( ... ) { try { - Locker lk(_lock_tr); + scoped_lock lk(_lock_tr); if ( _trs != 0 && _trs->good() && (_trflags & tracefault) ) { *_trs << "Unknown, uncatched exception during process:\n" << object->classtype().name() << " (" << object << ")\n"; @@ -588,7 +588,7 @@ catch ( std::logic_error& err ) { //... [truncated message content] |
From: <com...@us...> - 2007-07-16 14:34:45
|
Revision: 1614 http://svn.sourceforge.net/complement/?rev=1614&view=rev Author: complement Date: 2007-07-16 07:34:39 -0700 (Mon, 16 Jul 2007) Log Message: ----------- prepare exam for usage as lib and self-unit-test Added Paths: ----------- trunk/complement/explore/include/exam/ trunk/complement/explore/include/exam/logger.h trunk/complement/explore/include/exam/suite.h trunk/complement/explore/lib/exam/ trunk/complement/explore/lib/exam/logger.cc trunk/complement/explore/lib/exam/suite.cc trunk/complement/explore/lib/exam/ut/ trunk/complement/explore/lib/exam/ut/Makefile trunk/complement/explore/lib/exam/ut/Makefile.inc trunk/complement/explore/lib/exam/ut/dummy_test.cc trunk/complement/explore/lib/exam/ut/exam_self_test.cc trunk/complement/explore/lib/exam/ut/exam_test_suite.cc trunk/complement/explore/lib/exam/ut/exam_test_suite.h Removed Paths: ------------- trunk/complement/explore/app/exam/dummy_test.cc trunk/complement/explore/app/exam/exam_self_test.cc trunk/complement/explore/app/exam/exam_test_suite.cc trunk/complement/explore/app/exam/exam_test_suite.h trunk/complement/explore/app/exam/logger.cc trunk/complement/explore/app/exam/logger.h trunk/complement/explore/app/exam/suite.cc trunk/complement/explore/app/exam/suite.h Deleted: trunk/complement/explore/app/exam/dummy_test.cc =================================================================== --- trunk/complement/explore/app/exam/dummy_test.cc 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/dummy_test.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,36 +0,0 @@ -#include "suite.h" - -int EXAM_IMPL(func) -{ - EXAM_CHECK(false); - - return EXAM_RESULT; -} - -class test_x -{ - public: - - int EXAM_IMPL(f) - { - EXAM_CHECK(false); - EXAM_CHECK(true); - - return EXAM_RESULT; - } - - int EXAM_IMPL(f_good) - { - EXAM_CHECK(true); - EXAM_CHECK(true); - - return EXAM_RESULT; - } -}; - -int EXAM_IMPL(func_good) -{ - EXAM_CHECK(true); - - return EXAM_RESULT; -} Deleted: trunk/complement/explore/app/exam/exam_self_test.cc =================================================================== --- trunk/complement/explore/app/exam/exam_self_test.cc 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/exam_self_test.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,14 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> - -#include "exam_test_suite.h" - -int main( int, char ** ) -{ - // exam::test_suite t( "exam self test" ); - // t.add( exam_self_test, "exam self test suite" ); - // - // return t.girdle(); - - return exam_self_test(0); -} - Deleted: trunk/complement/explore/app/exam/exam_test_suite.cc =================================================================== --- trunk/complement/explore/app/exam/exam_test_suite.cc 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/exam_test_suite.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,239 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> - -#include "exam_test_suite.h" - -#include "dummy_test.cc" - -int EXAM_IMPL(exam_basic_test::function_good) -{ - buff.str( "" ); - buff.clear(); - - exam::test_suite t( "exam self test, good function" ); - t.set_logger( &logger ); - - test_x tx; - t.add( func_good, "function" ); - t.add( &test_x::f_good, tx, "member function" ); - - t.girdle(); - - EXAM_REQUIRE( buff.str() == r0 ); - - // std::cerr << "%%%\n"; - // std::cerr << buff.str() << std::endl; - // std::cerr << "%%%\n"; - - return EXAM_RESULT; -} - -int EXAM_IMPL(exam_basic_test::function) -{ - buff.str( "" ); - buff.clear(); - - exam::test_suite t( "exam self test, fail function" ); - t.set_logger( &logger ); - - test_x tx; - t.add( func, "function" ); - t.add( &test_x::f, tx, "member function" ); - - t.girdle(); - - EXAM_REQUIRE( buff.str() == r1 ); - - // std::cerr << "%%%\n"; - // std::cerr << buff.str() << std::endl; - // std::cerr << "%%%\n"; - - return EXAM_RESULT; -} - -int EXAM_IMPL(exam_basic_test::dep) -{ - buff.str( "" ); - buff.clear(); - - exam::test_suite t( "exam self test, fail function" ); - t.set_logger( &logger ); - - test_x tx; - t.add( func_good, "function good", // "child" - t.add( &test_x::f_good, tx, "member function good" ) ); // "parent" - t.add( func, "function fail", // <- skiped, because depends upon failed (next line) - t.add( &test_x::f, tx, "member function fail" ) ); // <- fail - - t.girdle(); - - EXAM_REQUIRE( buff.str() == r2 ); - - // std::cerr << "%%%\n"; - // std::cerr << buff.str() << std::endl; - // std::cerr << "%%%\n"; - - return EXAM_RESULT; -} - -int EXAM_IMPL(exam_basic_test::trace) -{ - buff.str( "" ); - buff.clear(); - - exam::test_suite t( "exam self test, fail function" ); - t.set_logger( &logger ); - - logger.flags( exam::base_logger::trace_suite ); - - test_x tx; - t.add( func_good, "function good", // "child" - t.add( &test_x::f_good, tx, "member function good" ) ); // "parent" - t.add( func, "function fail", // <- skiped, because depends upon failed (next line) - t.add( &test_x::f, tx, "member function fail" ) ); // <- fail - - t.girdle(); - - EXAM_REQUIRE( buff.str() == r3 ); - - buff.str( "" ); - buff.clear(); - - logger.flags( exam::base_logger::silent ); - - t.girdle(); - - EXAM_REQUIRE( buff.str() == r4 ); - - buff.str( "" ); - buff.clear(); - - logger.flags( exam::base_logger::trace ); - - t.girdle(); - - EXAM_REQUIRE( buff.str() == r5 ); - - buff.str( "" ); - buff.clear(); - - logger.flags( exam::base_logger::verbose ); - - t.girdle(); - - logger.flags( 0 ); - - EXAM_REQUIRE( buff.str() == r6 ); - - // std::cerr << "%%%\n"; - // std::cerr << buff.str() << std::endl; - // std::cerr << "%%%\n"; - - return EXAM_RESULT; -} - -int EXAM_IMPL(exam_basic_test::dep_test_suite) -{ - buff.str( "" ); - buff.clear(); - - exam::test_suite t0( "exam self test, test suite master" ); - t0.set_logger( &logger ); - - test_x tx0; - t0.add( func_good, "function" ); - t0.add( &test_x::f_good, tx0, "member function" ); - - exam::test_suite t1( "exam self test, test suite slave" ); - t1.set_logger( &logger ); - - test_x tx1; - t1.add( func_good, "function good", // "child" - t1.add( &test_x::f_good, tx1, "member function good" ) ); // "parent" - t1.add( func, "function fail", // <- skiped, because depends upon failed (next line) - t1.add( &test_x::f, tx1, "member function fail" ) ); // <- fail - - exam::test_suite t( "exam self test, test suites dependency" ); - t.set_logger( &logger ); - - t.add( &exam::test_suite::run, t1, "slave test suite", - t.add( &exam::test_suite::run, t0, "master test suite" ) ); - - t.girdle(); - - EXAM_REQUIRE( buff.str() == r7 ); - - // std::cerr << "%%%\n"; - // std::cerr << buff.str() << std::endl; - // std::cerr << "%%%\n"; - - return EXAM_RESULT; -} - -const std::string exam_basic_test::r0 = "\ -*** PASS exam self test, good function (+2-0~0/2) ***\n"; - -const std::string exam_basic_test::r1 = "\ -dummy_test.cc:5: fail: false\n\ - FAIL function\n\ -dummy_test.cc:16: fail: false\n\ - FAIL member function\n\ -*** FAIL exam self test, fail function (+0-2~0/2) ***\n"; - -const std::string exam_basic_test::r2 = "\ -dummy_test.cc:16: fail: false\n\ - FAIL member function fail\n\ - SKIP function fail\n\ -*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; - -const std::string exam_basic_test::r3 = "\ -== Begin test suite\n\ -dummy_test.cc:16: fail: false\n\ - FAIL member function fail\n\ - SKIP function fail\n\ -== End test suite\n\ -*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; - -const std::string exam_basic_test::r4 = "\ -*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; - -const std::string exam_basic_test::r5 = "\ -dummy_test.cc:24: pass: true\n\ -dummy_test.cc:25: pass: true\n\ -dummy_test.cc:16: fail: false\n\ -dummy_test.cc:17: pass: true\n\ - FAIL member function fail\n\ - SKIP function fail\n\ -dummy_test.cc:33: pass: true\n\ -*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; - -const std::string exam_basic_test::r6 = "\ - PASS member function good\n\ -dummy_test.cc:16: fail: false\n\ - FAIL member function fail\n\ - SKIP function fail\n\ - PASS function good\n\ -*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; - -const std::string exam_basic_test::r7 = "\ -*** PASS exam self test, test suite master (+2-0~0/2) ***\n\ -dummy_test.cc:16: fail: false\n\ - FAIL member function fail\n\ - SKIP function fail\n\ -*** FAIL exam self test, test suite slave (+2-1~1/4) ***\n\ - FAIL slave test suite\n\ -*** FAIL exam self test, test suites dependency (+1-1~0/2) ***\n"; - -int EXAM_IMPL(exam_self_test) -{ - exam::test_suite t( "exam self test" ); - exam_basic_test exam_basic; - - t.add( &exam_basic_test::function_good, exam_basic, "call test, good calls" ); - t.add( &exam_basic_test::function, exam_basic, "call test, fail calls" ); - exam::test_suite::test_case_type d = t.add( &exam_basic_test::dep, exam_basic, "call test, tests dependency" ); - t.add( &exam_basic_test::trace, exam_basic, "trace flags test", d ); - t.add( &exam_basic_test::dep_test_suite, exam_basic, "test suites grouping", d ); - - return t.girdle(); -} - Deleted: trunk/complement/explore/app/exam/exam_test_suite.h =================================================================== --- trunk/complement/explore/app/exam/exam_test_suite.h 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/exam_test_suite.h 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,42 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> - -#ifndef __exam_test_suite_h -#define __exam_test_suite_h - -#define FIT_EXAM - -#include "suite.h" -#include <string> -#include <sstream> - -class exam_basic_test -{ - public: - exam_basic_test() : - buff(), - logger( buff ) - { } - - int EXAM_DECL(function_good); - int EXAM_DECL(function); - int EXAM_DECL(dep); - int EXAM_DECL(trace); - int EXAM_DECL(dep_test_suite); - - private: - std::stringstream buff; - exam::trivial_logger logger; - - static const std::string r0; - static const std::string r1; - static const std::string r2; - static const std::string r3; - static const std::string r4; - static const std::string r5; - static const std::string r6; - static const std::string r7; -}; - -int EXAM_DECL(exam_self_test); - -#endif // __exam_test_suite_h Deleted: trunk/complement/explore/app/exam/logger.cc =================================================================== --- trunk/complement/explore/app/exam/logger.cc 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/logger.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,111 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/07/13 10:53:32 ptr> - -#include "logger.h" -#include <iostream> - -namespace exam { - -using namespace std; - -int base_logger::flags() const -{ - return _flags; -} - -bool base_logger::is_trace() const -{ - return (_flags & trace) != 0; -} - -int base_logger::flags( int f ) -{ - int tmp = _flags; - _flags = f; - if ( (f & silent) != 0 ) { - _flags &= ~trace_suite; - } - return tmp; -} - -void trivial_logger::report( const char *file, int line, bool cnd, const char *expr ) -{ - if ( (cnd && ((_flags & trace) == 0)) || ((_flags & silent) != 0) ) { - return; - } - - if ( s != 0 ) { - *s << file << ":" << line << ": " << (cnd ? "pass" : "fail" ) << ": " << expr - << std::endl; - } else { - fprintf( f, "%s:%d: %s: %s\n", file, line, (cnd ? "pass" : "fail" ), expr ); - } -} - -void trivial_logger::begin_ts() -{ - if ( (_flags & trace_suite) == 0 ) { - return; - } - - if ( s != 0 ) { - *s << "== Begin test suite\n"; - } else { - fprintf( f, "== Begin test suite\n" ); - } -} - -void trivial_logger::end_ts() -{ - if ( (_flags & trace_suite) == 0 ) { - return; - } - - if ( *s ) { - *s << "== End test suite\n"; - } else { - fprintf( f, "== End test suite\n" ); - } -} - -void trivial_logger::result( const base_logger::stat& _stat, const string& suite_name ) -{ - if ( s != 0 ) { - *s << "*** " << (_stat.failed != 0 ? "FAIL " : "PASS " ) << suite_name - << " (+" << _stat.passed - << "-" << _stat.failed - << "~" << _stat.skipped << "/" << _stat.total << ") ***" << endl; - } else { - fprintf( f, "*** %s (+%d-%d~%d/%d) ***\n", (_stat.failed != 0 ? "FAIL" : "PASS" ), _stat.passed, _stat.failed, _stat.skipped, _stat.total ); - } -} - -void trivial_logger::tc( base_logger::tc_result r, const std::string& name ) -{ - if ( ((_flags & silent) != 0) || ((r == pass) && ((_flags & verbose) == 0) )) { - return; - } - - static const char *m[] = { " PASS ", " FAIL ", " SKIP " }; - const char *rs = ""; - - switch ( r ) - { - case pass: - rs = m[0]; - break; - case fail: - rs = m[1]; - break; - case skip: - rs = m[2]; - break; - } - - if ( s != 0 ) { - *s << rs << name << endl; - } else { - fprintf( f, "%s%s\n", rs, name.c_str() ); - } -} - -} //namespace exam Deleted: trunk/complement/explore/app/exam/logger.h =================================================================== --- trunk/complement/explore/app/exam/logger.h 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/logger.h 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,94 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/07/13 11:01:52 ptr> - -#ifndef __logger_h -#define __logger_h - -#include <string> -#include <cstdio> -#include <ostream> - -namespace exam { - -class base_logger -{ - public: - - enum trace_flags { - trace = 1, - trace_suite = 2, - silent = 4, - verbose = 8 - }; - - enum tc_result { - pass = 0, - fail, - skip - }; - - struct stat - { - stat() : - total(0), - passed(0), - failed(0), - skipped(0) - { } - - int total; - int passed; - int failed; - int skipped; - }; - - base_logger() : - _flags( 0 ) - { } - virtual ~base_logger() - { } - - int flags() const; - bool is_trace() const; - - int flags( int ); - - virtual void report( const char *, int, bool, const char * ) = 0; - - virtual void begin_ts() = 0; - virtual void end_ts() = 0; - virtual void result( const base_logger::stat&, const std::string& suite_name ) = 0; - virtual void tc( tc_result, const std::string& ) = 0; - - protected: - int _flags; -}; - -class trivial_logger : - public base_logger -{ - public: - explicit trivial_logger( std::ostream& str ) : - s( &str ), - f( 0 ) - { } - - explicit trivial_logger( FILE *fs ) : - s( 0 ), - f( fs ) - { } - - virtual void report( const char *, int, bool, const char * ); - - virtual void begin_ts(); - virtual void end_ts(); - virtual void result( const base_logger::stat&, const std::string& ); - virtual void tc( base_logger::tc_result, const std::string& ); - - private: - std::ostream *s; - FILE *f; -}; - -} // namespace exam - -#endif // __logger_h Deleted: trunk/complement/explore/app/exam/suite.cc =================================================================== --- trunk/complement/explore/app/exam/suite.cc 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/suite.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,265 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/07/15 16:33:03 ptr> - -#include "suite.h" -#include <boost/graph/breadth_first_search.hpp> -#include <stack> - -#include <cstdio> -#include <iostream> - -namespace exam { - -using namespace std; -using namespace boost; -using namespace detail; - -namespace detail { - -template <class Tag> -struct vertex_recorder : - public base_visitor<vertex_recorder<Tag> > -{ - typedef Tag event_filter; - - vertex_recorder(test_suite& ts) : - _suite(ts) - { } - - template <class Vertex, class Graph> - void operator()(Vertex v, const Graph& g) - { _suite.run_test_case( v ); } - - test_suite& _suite; -}; - -template <class Tag> -vertex_recorder<Tag> record_vertexes(test_suite& ts, Tag) -{ return vertex_recorder<Tag>(ts); } - -template <class Tag> -struct skip_recorder : - public base_visitor<skip_recorder<Tag> > -{ - typedef Tag event_filter; - - skip_recorder(test_suite& ts) : - _suite(ts) - { } - - template <class Edge, class Graph> - void operator()(Edge e, const Graph& g) - { - // typename graph_traits<Graph>::vertex_descriptor u = boost::source( e, g ); - // typename graph_traits<Graph>::vertex_descriptor v = boost::target( e, g ); - _suite.check_test_case( boost::source( e, g ), boost::target( e, g ) ); - } - - test_suite& _suite; -}; - -template <class Tag> -skip_recorder<Tag> record_skip(test_suite& ts, Tag) -{ return skip_recorder<Tag>(ts); } - -template <class Tag> -struct white_recorder : - public base_visitor<white_recorder<Tag> > -{ - typedef Tag event_filter; - - white_recorder(test_suite& ts) : - _suite(ts) - { } - - template <class Vertex, class Graph> - void operator()(Vertex v, const Graph& g) - { - // std::cerr << "On vertex " << v << std::endl; - // boost::put( boost::vertex_color, g, v, white_color ); - _suite.clean_test_case_state( v ); - } - - test_suite& _suite; -}; - -template <class Tag> -white_recorder<Tag> record_white(test_suite& ts, Tag) -{ return white_recorder<Tag>(ts); } - - -} // namespace detail - -int EXAM_IMPL(test_suite::_root_func) -{ - throw init_exception(); - - return -1; -} - -test_suite::test_suite( const string& name ) : - root( add_vertex( white_color, g ) ), - _suite_name( name ), - local_logger( logger ) -{ - testcase = get( vertex_testcase, g ); - _test[root].tc = detail::make_test_case( detail::call( _root_func ) ); - _test[root].state = 0; -} - -test_suite::test_suite( const char *name ) : - root( add_vertex( white_color, g ) ), - _suite_name( name ), - local_logger( logger ) -{ - testcase = get( vertex_testcase, g ); - _test[root].tc = detail::make_test_case( detail::call( _root_func ) ); - _test[root].state = 0; -} - -test_suite::~test_suite() -{ - for ( test_case_map_type::iterator i = _test.begin(); i != _test.end(); ++i ) { - delete i->second.tc; - } -} - -int test_suite::girdle( test_suite::test_case_type start ) -{ - stack<vertex_t> buffer; - vertex_color_map_t color = get( vertex_color, g ); - - // detail::white_recorder<on_initialize_vertex> vis( *this ); - // - // vertex_iterator_t i, i_end; - - // for ( tie(i, i_end) = vertices(g); i != i_end; ++i ) { - // // vis.initialize_vertex( *i, g ); - // put( color, *i, white_color ); - // } - - _stat = base_logger::stat(); - local_logger->begin_ts(); - breadth_first_search( g, start, buffer, - make_bfs_visitor( - make_pair( record_white(*this,on_initialize_vertex()), - make_pair( record_vertexes(*this,on_discover_vertex()), - record_skip(*this,on_examine_edge()) ) ) ), - color ); - local_logger->end_ts(); - local_logger->result( _stat, _suite_name ); - - return _stat.failed; -} - -test_suite::test_case_type test_suite::add( test_suite::func_type f, const string& name ) -{ - vertex_t v = add_vertex( white_color, g); - add_edge( root, v, g ); - _test[v].tc = detail::make_test_case( detail::call( f ) ); - _test[v].state = 0; - _test[v].name = name; - // ++_stat.total; - - return v; -} - -test_suite::test_case_type test_suite::add( test_suite::func_type f, const string& name, test_suite::test_case_type depends ) -{ - vertex_t v = add_vertex( white_color, g); - add_edge( depends, v, g ); - _test[v].tc = detail::make_test_case( detail::call( f ) ); - _test[v].state = 0; - _test[v].name = name; - // ++_stat.total; - - return v; -} - -int test_suite::flags() -{ - return local_logger->flags(); -} - -bool test_suite::is_trace() -{ - return local_logger->is_trace(); -} - -int test_suite::flags( int f ) -{ - return local_logger->flags( f ); -} - -trivial_logger __trivial_logger_inst( cerr ); - -base_logger *test_suite::logger = &__trivial_logger_inst; - -base_logger *test_suite::set_global_logger( base_logger *new_logger ) -{ - base_logger *tmp = logger; - logger = new_logger; - if ( tmp == local_logger ) { // if local_logger was identical to logger, switch it too - local_logger = logger; - } - return tmp; -} - -base_logger *test_suite::set_logger( base_logger *new_logger ) -{ - base_logger *tmp = local_logger; - local_logger = new_logger; - return tmp; -} - -void test_suite::report( const char *file, int line, bool cnd, const char *expr ) -{ - local_logger->report( file, line, cnd, expr ); -} - -void test_suite::run_test_case( test_suite::vertex_t v ) -{ - try { - ++_stat.total; - if ( _test[v].state == 0 ) { - if ( (*_test[v].tc)( this, 0 ) == 0 ) { - ++_stat.passed; - local_logger->tc( base_logger::pass, _test[v].name ); - } else { - _test[v].state = fail; - ++_stat.failed; - local_logger->tc( base_logger::fail, _test[v].name ); - } - } else { - ++_stat.skipped; - local_logger->tc( base_logger::skip, _test[v].name ); - } - } - catch ( init_exception& ) { - --_stat.total; - } - catch ( ... ) { - ++_stat.failed; - _test[v].state = fail; - local_logger->tc( base_logger::fail, _test[v].name ); - } -} - -void test_suite::check_test_case( test_suite::vertex_t u, test_suite::vertex_t v ) -{ - if ( _test[u].state != 0 ) { - _test[v].state = skip; - } -} - -void test_suite::clean_test_case_state( vertex_t v ) -{ - _test[v].state = 0; -} - -int test_suite::run( test_suite *, int ) -{ - return girdle( root ); -} - - -} // namespace exam Deleted: trunk/complement/explore/app/exam/suite.h =================================================================== --- trunk/complement/explore/app/exam/suite.h 2007-07-16 14:04:06 UTC (rev 1613) +++ trunk/complement/explore/app/exam/suite.h 2007-07-16 14:34:39 UTC (rev 1614) @@ -1,284 +0,0 @@ -// -*- C++ -*- Time-stamp: <07/07/15 16:33:17 ptr> - -#ifndef __suite_h -#define __suite_h - -#include <iostream> -#include <sstream> -#include <map> -#include <boost/graph/adjacency_list.hpp> -#include <string> -#include <exception> - -#include "logger.h" - -enum vertex_testcase_t { vertex_testcase }; - -namespace boost { - BOOST_INSTALL_PROPERTY( vertex, testcase ); -} // namespace boost - -namespace exam { - -class test_suite; - -namespace detail { - -struct call_impl -{ - virtual ~call_impl() - { } - // virtual int invoke() = 0; - virtual int invoke( test_suite *, int = 0 ) = 0; -}; - -template <typename F> -class call_impl_t : - public call_impl -{ - public: - explicit call_impl_t( F f ) : - _f( f ) - { } - - // virtual int invoke() - // { return _f(); } - - virtual int invoke( test_suite *s, int count = 0 ) - { return _f( s, count ); } - - - private: - F _f; -}; - -class dummy -{ - public: - // virtual int f() - // { return 0; } - - virtual int f( test_suite *, int count = 0 ) - { return count; } - - private: - virtual ~dummy() - { } -}; - -template <class TC> -class method_invoker -{ - public: - // typedef int (TC::*mf_type_a)(); - typedef int (TC::*mf_type)( test_suite *, int ); - - explicit method_invoker( TC& instance, mf_type f ) : - _inst(instance), - _func(f) - { } - - method_invoker( const method_invoker<TC>& m ) : - _inst( m._inst ), - _func( m._func ) - { } - - // int operator()() - // { return (_inst.*_func)(); } - - int operator()( test_suite *ts, int count = 0 ) - { return (_inst.*_func)( ts, count ); } - - private: - method_invoker& operator =( const method_invoker<TC>& ) - { return *this; } - - TC& _inst; - mf_type _func; -}; - -class call -{ - public: - call() - { } - - template <class F> - call( F f ) - { new (&_buf[0]) call_impl_t<F>(f); } - - // int operator()() - // { return reinterpret_cast<call_impl *>(&_buf[0])->invoke(); } - - int operator()( test_suite *ts, int count = 0 ) - { return reinterpret_cast<call_impl *>(&_buf[0])->invoke( ts, count ); } - - private: - // call_impl *_f; - char _buf[((sizeof(call_impl_t<method_invoker<dummy> >)+64) / 64) << 6]; -}; - - -class test_case -{ - public: - test_case( const call& f ) : - _tc( f ) - { } - - // int operator ()() - // { return _tc(); } - - int operator ()( test_suite *ts, int count = 0 ) - { return _tc( ts, count ); } - - private: - call _tc; -}; - -inline test_case *make_test_case( const call& f ) -{ - return new test_case( f ); -} - -template <class TC> -inline test_case *make_test_case( int (TC::*f)( test_suite *, int ), TC& instance ) -{ - return new test_case( method_invoker<TC>(instance, f) ); -} - -} // namespace detail - -class init_exception : - public std::exception -{ -}; - -class test_suite -{ - private: - typedef boost::property<vertex_testcase_t,int> TestCaseProperty; - typedef boost::property<boost::vertex_color_t, boost::default_color_type, TestCaseProperty> VColorProperty; - - typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VColorProperty > graph_t; - typedef boost::graph_traits<graph_t>::vertex_iterator vertex_iterator_t; - - typedef boost::graph_traits<graph_t>::vertex_descriptor vertex_t; - typedef boost::property_map<graph_t,boost::vertex_color_t>::type vertex_color_map_t; - typedef boost::property_map<graph_t,vertex_testcase_t>::type vertex_testcase_map_t; - - public: - typedef int (*func_type)( test_suite *, int ); - typedef vertex_t test_case_type; - - test_suite( const std::string& name ); - test_suite( const char *name ); - ~test_suite(); - - test_case_type add( func_type, const std::string& name ); - test_case_type add( func_type, const std::string& name, test_case_type ); - - template <class TC> - test_case_type add( int (TC::*)( test_suite *, int ), TC&, const std::string& name ); - - template <class TC> - test_case_type add( int (TC::*)( test_suite *, int ), TC&, const std::string& name, test_case_type ); - - int girdle( test_case_type start ); - int girdle() - { return girdle( root ); } - int run( test_suite *, int count = 0 ); - - void run_test_case( vertex_t v ); - void check_test_case( vertex_t u, vertex_t v ); - void clean_test_case_state( vertex_t v ); - - int flags(); - int flags( int ); - bool is_trace(); - void report( const char *, int, bool, const char * ); - base_logger *set_global_logger( base_logger * ); - base_logger *set_logger( base_logger * ); - - private: - enum { - pass = 0, - fail = 1, - skip = 2 - }; - - graph_t g; - vertex_t root; - vertex_testcase_map_t testcase; - base_logger *local_logger; - - struct test_case_collect - { - detail::test_case *tc; - int state; - std::string name; - }; - - typedef std::map<vertex_t,test_case_collect> test_case_map_type; - test_case_map_type _test; - base_logger::stat _stat; - std::string _suite_name; - - static int _root_func( test_suite *, int = 0 ); - - static base_logger *logger; -}; - -template <class TC> -test_suite::test_case_type test_suite::add( int (TC::*f)( test_suite *, int ), TC& instance, const std::string& name ) -{ - vertex_t v = boost::add_vertex( boost::white_color, g); - boost::add_edge( root, v, g ); - _test[v].tc = detail::make_test_case( f, instance ); - _test[v].state = 0; - _test[v].name = name; - // ++_stat.total; - - return v; -} - -template <class TC> -test_suite::test_case_type test_suite::add( int (TC::*f)( test_suite *, int ), TC& instance, const std::string& name, test_suite::test_case_type depends ) -{ - vertex_t v = boost::add_vertex( boost::white_color, g); - boost::add_edge( depends, v, g ); - _test[v].tc = detail::make_test_case( f, instance ); - _test[v].state = 0; - _test[v].name = name; - // ++_stat.total; - - return v; -} - -typedef test_suite::test_case_type test_case_type; - -} // namespace exam - -#ifdef FIT_EXAM -# define EXAM_IMPL(F) F( exam::test_suite *__exam_ts, int __exam_counter ) -# define EXAM_DECL(F) F( exam::test_suite *, int = 0 ) -# define EXAM_RESULT __exam_counter -# define EXAM_CHECK(C) if ( !(C) ) { __exam_ts->report( __FILE__, __LINE__, false, #C ); __exam_counter |= 1; } else __exam_ts->report( __FILE__, __LINE__, true, #C ) -# define EXAM_MESSAGE(M) __exam_ts->report( __FILE__, __LINE__, true, M ) -# define EXAM_REQUIRE(C) if ( !(C) ) { __exam_ts->report( __FILE__, __LINE__, false, #C ); return 1; } else __exam_ts->report( __FILE__, __LINE__, true, #C ) -# define EXAM_FAIL(M) __exam_ts->report( __FILE__, __LINE__, false, M ); return 1 -# define EXAM_ERROR(M) __exam_ts->report( __FILE__, __LINE__, false, M ); __exam_counter |= 1 -#else -# define EXAM_IMPL(F) F( exam::test_suite *, int ) -# define EXAM_DECL(F) F( exam::test_suite *, int = 0 ) -# define EXAM_RESULT 0 -# define EXAM_CHECK(C) -# define EXAM_MESSAGE(M) -# define EXAM_REQUIRE(C) -# define EXAM_FAIL(M) -# define EXAM_ERROR(M) -#endif - - -#endif // __suite_h - Copied: trunk/complement/explore/include/exam/logger.h (from rev 1612, trunk/complement/explore/app/exam/logger.h) =================================================================== --- trunk/complement/explore/include/exam/logger.h (rev 0) +++ trunk/complement/explore/include/exam/logger.h 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,94 @@ +// -*- C++ -*- Time-stamp: <07/07/13 11:01:52 ptr> + +#ifndef __logger_h +#define __logger_h + +#include <string> +#include <cstdio> +#include <ostream> + +namespace exam { + +class base_logger +{ + public: + + enum trace_flags { + trace = 1, + trace_suite = 2, + silent = 4, + verbose = 8 + }; + + enum tc_result { + pass = 0, + fail, + skip + }; + + struct stat + { + stat() : + total(0), + passed(0), + failed(0), + skipped(0) + { } + + int total; + int passed; + int failed; + int skipped; + }; + + base_logger() : + _flags( 0 ) + { } + virtual ~base_logger() + { } + + int flags() const; + bool is_trace() const; + + int flags( int ); + + virtual void report( const char *, int, bool, const char * ) = 0; + + virtual void begin_ts() = 0; + virtual void end_ts() = 0; + virtual void result( const base_logger::stat&, const std::string& suite_name ) = 0; + virtual void tc( tc_result, const std::string& ) = 0; + + protected: + int _flags; +}; + +class trivial_logger : + public base_logger +{ + public: + explicit trivial_logger( std::ostream& str ) : + s( &str ), + f( 0 ) + { } + + explicit trivial_logger( FILE *fs ) : + s( 0 ), + f( fs ) + { } + + virtual void report( const char *, int, bool, const char * ); + + virtual void begin_ts(); + virtual void end_ts(); + virtual void result( const base_logger::stat&, const std::string& ); + virtual void tc( base_logger::tc_result, const std::string& ); + + private: + std::ostream *s; + FILE *f; +}; + +} // namespace exam + +#endif // __logger_h Copied: trunk/complement/explore/include/exam/suite.h (from rev 1612, trunk/complement/explore/app/exam/suite.h) =================================================================== --- trunk/complement/explore/include/exam/suite.h (rev 0) +++ trunk/complement/explore/include/exam/suite.h 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,284 @@ +// -*- C++ -*- Time-stamp: <07/07/15 16:33:17 ptr> + +#ifndef __suite_h +#define __suite_h + +#include <iostream> +#include <sstream> +#include <map> +#include <boost/graph/adjacency_list.hpp> +#include <string> +#include <exception> + +#include "logger.h" + +enum vertex_testcase_t { vertex_testcase }; + +namespace boost { + BOOST_INSTALL_PROPERTY( vertex, testcase ); +} // namespace boost + +namespace exam { + +class test_suite; + +namespace detail { + +struct call_impl +{ + virtual ~call_impl() + { } + // virtual int invoke() = 0; + virtual int invoke( test_suite *, int = 0 ) = 0; +}; + +template <typename F> +class call_impl_t : + public call_impl +{ + public: + explicit call_impl_t( F f ) : + _f( f ) + { } + + // virtual int invoke() + // { return _f(); } + + virtual int invoke( test_suite *s, int count = 0 ) + { return _f( s, count ); } + + + private: + F _f; +}; + +class dummy +{ + public: + // virtual int f() + // { return 0; } + + virtual int f( test_suite *, int count = 0 ) + { return count; } + + private: + virtual ~dummy() + { } +}; + +template <class TC> +class method_invoker +{ + public: + // typedef int (TC::*mf_type_a)(); + typedef int (TC::*mf_type)( test_suite *, int ); + + explicit method_invoker( TC& instance, mf_type f ) : + _inst(instance), + _func(f) + { } + + method_invoker( const method_invoker<TC>& m ) : + _inst( m._inst ), + _func( m._func ) + { } + + // int operator()() + // { return (_inst.*_func)(); } + + int operator()( test_suite *ts, int count = 0 ) + { return (_inst.*_func)( ts, count ); } + + private: + method_invoker& operator =( const method_invoker<TC>& ) + { return *this; } + + TC& _inst; + mf_type _func; +}; + +class call +{ + public: + call() + { } + + template <class F> + call( F f ) + { new (&_buf[0]) call_impl_t<F>(f); } + + // int operator()() + // { return reinterpret_cast<call_impl *>(&_buf[0])->invoke(); } + + int operator()( test_suite *ts, int count = 0 ) + { return reinterpret_cast<call_impl *>(&_buf[0])->invoke( ts, count ); } + + private: + // call_impl *_f; + char _buf[((sizeof(call_impl_t<method_invoker<dummy> >)+64) / 64) << 6]; +}; + + +class test_case +{ + public: + test_case( const call& f ) : + _tc( f ) + { } + + // int operator ()() + // { return _tc(); } + + int operator ()( test_suite *ts, int count = 0 ) + { return _tc( ts, count ); } + + private: + call _tc; +}; + +inline test_case *make_test_case( const call& f ) +{ + return new test_case( f ); +} + +template <class TC> +inline test_case *make_test_case( int (TC::*f)( test_suite *, int ), TC& instance ) +{ + return new test_case( method_invoker<TC>(instance, f) ); +} + +} // namespace detail + +class init_exception : + public std::exception +{ +}; + +class test_suite +{ + private: + typedef boost::property<vertex_testcase_t,int> TestCaseProperty; + typedef boost::property<boost::vertex_color_t, boost::default_color_type, TestCaseProperty> VColorProperty; + + typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VColorProperty > graph_t; + typedef boost::graph_traits<graph_t>::vertex_iterator vertex_iterator_t; + + typedef boost::graph_traits<graph_t>::vertex_descriptor vertex_t; + typedef boost::property_map<graph_t,boost::vertex_color_t>::type vertex_color_map_t; + typedef boost::property_map<graph_t,vertex_testcase_t>::type vertex_testcase_map_t; + + public: + typedef int (*func_type)( test_suite *, int ); + typedef vertex_t test_case_type; + + test_suite( const std::string& name ); + test_suite( const char *name ); + ~test_suite(); + + test_case_type add( func_type, const std::string& name ); + test_case_type add( func_type, const std::string& name, test_case_type ); + + template <class TC> + test_case_type add( int (TC::*)( test_suite *, int ), TC&, const std::string& name ); + + template <class TC> + test_case_type add( int (TC::*)( test_suite *, int ), TC&, const std::string& name, test_case_type ); + + int girdle( test_case_type start ); + int girdle() + { return girdle( root ); } + int run( test_suite *, int count = 0 ); + + void run_test_case( vertex_t v ); + void check_test_case( vertex_t u, vertex_t v ); + void clean_test_case_state( vertex_t v ); + + int flags(); + int flags( int ); + bool is_trace(); + void report( const char *, int, bool, const char * ); + base_logger *set_global_logger( base_logger * ); + base_logger *set_logger( base_logger * ); + + private: + enum { + pass = 0, + fail = 1, + skip = 2 + }; + + graph_t g; + vertex_t root; + vertex_testcase_map_t testcase; + base_logger *local_logger; + + struct test_case_collect + { + detail::test_case *tc; + int state; + std::string name; + }; + + typedef std::map<vertex_t,test_case_collect> test_case_map_type; + test_case_map_type _test; + base_logger::stat _stat; + std::string _suite_name; + + static int _root_func( test_suite *, int = 0 ); + + static base_logger *logger; +}; + +template <class TC> +test_suite::test_case_type test_suite::add( int (TC::*f)( test_suite *, int ), TC& instance, const std::string& name ) +{ + vertex_t v = boost::add_vertex( boost::white_color, g); + boost::add_edge( root, v, g ); + _test[v].tc = detail::make_test_case( f, instance ); + _test[v].state = 0; + _test[v].name = name; + // ++_stat.total; + + return v; +} + +template <class TC> +test_suite::test_case_type test_suite::add( int (TC::*f)( test_suite *, int ), TC& instance, const std::string& name, test_suite::test_case_type depends ) +{ + vertex_t v = boost::add_vertex( boost::white_color, g); + boost::add_edge( depends, v, g ); + _test[v].tc = detail::make_test_case( f, instance ); + _test[v].state = 0; + _test[v].name = name; + // ++_stat.total; + + return v; +} + +typedef test_suite::test_case_type test_case_type; + +} // namespace exam + +#ifdef FIT_EXAM +# define EXAM_IMPL(F) F( exam::test_suite *__exam_ts, int __exam_counter ) +# define EXAM_DECL(F) F( exam::test_suite *, int = 0 ) +# define EXAM_RESULT __exam_counter +# define EXAM_CHECK(C) if ( !(C) ) { __exam_ts->report( __FILE__, __LINE__, false, #C ); __exam_counter |= 1; } else __exam_ts->report( __FILE__, __LINE__, true, #C ) +# define EXAM_MESSAGE(M) __exam_ts->report( __FILE__, __LINE__, true, M ) +# define EXAM_REQUIRE(C) if ( !(C) ) { __exam_ts->report( __FILE__, __LINE__, false, #C ); return 1; } else __exam_ts->report( __FILE__, __LINE__, true, #C ) +# define EXAM_FAIL(M) __exam_ts->report( __FILE__, __LINE__, false, M ); return 1 +# define EXAM_ERROR(M) __exam_ts->report( __FILE__, __LINE__, false, M ); __exam_counter |= 1 +#else +# define EXAM_IMPL(F) F( exam::test_suite *, int ) +# define EXAM_DECL(F) F( exam::test_suite *, int = 0 ) +# define EXAM_RESULT 0 +# define EXAM_CHECK(C) +# define EXAM_MESSAGE(M) +# define EXAM_REQUIRE(C) +# define EXAM_FAIL(M) +# define EXAM_ERROR(M) +#endif + + +#endif // __suite_h + Property changes on: trunk/complement/explore/lib/exam ___________________________________________________________________ Name: svn:ignore + obj Copied: trunk/complement/explore/lib/exam/logger.cc (from rev 1612, trunk/complement/explore/app/exam/logger.cc) =================================================================== --- trunk/complement/explore/lib/exam/logger.cc (rev 0) +++ trunk/complement/explore/lib/exam/logger.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,111 @@ +// -*- C++ -*- Time-stamp: <07/07/13 10:53:32 ptr> + +#include <exam/logger.h> +#include <iostream> + +namespace exam { + +using namespace std; + +int base_logger::flags() const +{ + return _flags; +} + +bool base_logger::is_trace() const +{ + return (_flags & trace) != 0; +} + +int base_logger::flags( int f ) +{ + int tmp = _flags; + _flags = f; + if ( (f & silent) != 0 ) { + _flags &= ~trace_suite; + } + return tmp; +} + +void trivial_logger::report( const char *file, int line, bool cnd, const char *expr ) +{ + if ( (cnd && ((_flags & trace) == 0)) || ((_flags & silent) != 0) ) { + return; + } + + if ( s != 0 ) { + *s << file << ":" << line << ": " << (cnd ? "pass" : "fail" ) << ": " << expr + << std::endl; + } else { + fprintf( f, "%s:%d: %s: %s\n", file, line, (cnd ? "pass" : "fail" ), expr ); + } +} + +void trivial_logger::begin_ts() +{ + if ( (_flags & trace_suite) == 0 ) { + return; + } + + if ( s != 0 ) { + *s << "== Begin test suite\n"; + } else { + fprintf( f, "== Begin test suite\n" ); + } +} + +void trivial_logger::end_ts() +{ + if ( (_flags & trace_suite) == 0 ) { + return; + } + + if ( *s ) { + *s << "== End test suite\n"; + } else { + fprintf( f, "== End test suite\n" ); + } +} + +void trivial_logger::result( const base_logger::stat& _stat, const string& suite_name ) +{ + if ( s != 0 ) { + *s << "*** " << (_stat.failed != 0 ? "FAIL " : "PASS " ) << suite_name + << " (+" << _stat.passed + << "-" << _stat.failed + << "~" << _stat.skipped << "/" << _stat.total << ") ***" << endl; + } else { + fprintf( f, "*** %s (+%d-%d~%d/%d) ***\n", (_stat.failed != 0 ? "FAIL" : "PASS" ), _stat.passed, _stat.failed, _stat.skipped, _stat.total ); + } +} + +void trivial_logger::tc( base_logger::tc_result r, const std::string& name ) +{ + if ( ((_flags & silent) != 0) || ((r == pass) && ((_flags & verbose) == 0) )) { + return; + } + + static const char *m[] = { " PASS ", " FAIL ", " SKIP " }; + const char *rs = ""; + + switch ( r ) + { + case pass: + rs = m[0]; + break; + case fail: + rs = m[1]; + break; + case skip: + rs = m[2]; + break; + } + + if ( s != 0 ) { + *s << rs << name << endl; + } else { + fprintf( f, "%s%s\n", rs, name.c_str() ); + } +} + +} //namespace exam Copied: trunk/complement/explore/lib/exam/suite.cc (from rev 1612, trunk/complement/explore/app/exam/suite.cc) =================================================================== --- trunk/complement/explore/lib/exam/suite.cc (rev 0) +++ trunk/complement/explore/lib/exam/suite.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,265 @@ +// -*- C++ -*- Time-stamp: <07/07/15 16:33:03 ptr> + +#include <exam/suite.h> +#include <boost/graph/breadth_first_search.hpp> +#include <stack> + +#include <cstdio> +#include <iostream> + +namespace exam { + +using namespace std; +using namespace boost; +using namespace detail; + +namespace detail { + +template <class Tag> +struct vertex_recorder : + public base_visitor<vertex_recorder<Tag> > +{ + typedef Tag event_filter; + + vertex_recorder(test_suite& ts) : + _suite(ts) + { } + + template <class Vertex, class Graph> + void operator()(Vertex v, const Graph& g) + { _suite.run_test_case( v ); } + + test_suite& _suite; +}; + +template <class Tag> +vertex_recorder<Tag> record_vertexes(test_suite& ts, Tag) +{ return vertex_recorder<Tag>(ts); } + +template <class Tag> +struct skip_recorder : + public base_visitor<skip_recorder<Tag> > +{ + typedef Tag event_filter; + + skip_recorder(test_suite& ts) : + _suite(ts) + { } + + template <class Edge, class Graph> + void operator()(Edge e, const Graph& g) + { + // typename graph_traits<Graph>::vertex_descriptor u = boost::source( e, g ); + // typename graph_traits<Graph>::vertex_descriptor v = boost::target( e, g ); + _suite.check_test_case( boost::source( e, g ), boost::target( e, g ) ); + } + + test_suite& _suite; +}; + +template <class Tag> +skip_recorder<Tag> record_skip(test_suite& ts, Tag) +{ return skip_recorder<Tag>(ts); } + +template <class Tag> +struct white_recorder : + public base_visitor<white_recorder<Tag> > +{ + typedef Tag event_filter; + + white_recorder(test_suite& ts) : + _suite(ts) + { } + + template <class Vertex, class Graph> + void operator()(Vertex v, const Graph& g) + { + // std::cerr << "On vertex " << v << std::endl; + // boost::put( boost::vertex_color, g, v, white_color ); + _suite.clean_test_case_state( v ); + } + + test_suite& _suite; +}; + +template <class Tag> +white_recorder<Tag> record_white(test_suite& ts, Tag) +{ return white_recorder<Tag>(ts); } + + +} // namespace detail + +int EXAM_IMPL(test_suite::_root_func) +{ + throw init_exception(); + + return -1; +} + +test_suite::test_suite( const string& name ) : + root( add_vertex( white_color, g ) ), + _suite_name( name ), + local_logger( logger ) +{ + testcase = get( vertex_testcase, g ); + _test[root].tc = detail::make_test_case( detail::call( _root_func ) ); + _test[root].state = 0; +} + +test_suite::test_suite( const char *name ) : + root( add_vertex( white_color, g ) ), + _suite_name( name ), + local_logger( logger ) +{ + testcase = get( vertex_testcase, g ); + _test[root].tc = detail::make_test_case( detail::call( _root_func ) ); + _test[root].state = 0; +} + +test_suite::~test_suite() +{ + for ( test_case_map_type::iterator i = _test.begin(); i != _test.end(); ++i ) { + delete i->second.tc; + } +} + +int test_suite::girdle( test_suite::test_case_type start ) +{ + stack<vertex_t> buffer; + vertex_color_map_t color = get( vertex_color, g ); + + // detail::white_recorder<on_initialize_vertex> vis( *this ); + // + // vertex_iterator_t i, i_end; + + // for ( tie(i, i_end) = vertices(g); i != i_end; ++i ) { + // // vis.initialize_vertex( *i, g ); + // put( color, *i, white_color ); + // } + + _stat = base_logger::stat(); + local_logger->begin_ts(); + breadth_first_search( g, start, buffer, + make_bfs_visitor( + make_pair( record_white(*this,on_initialize_vertex()), + make_pair( record_vertexes(*this,on_discover_vertex()), + record_skip(*this,on_examine_edge()) ) ) ), + color ); + local_logger->end_ts(); + local_logger->result( _stat, _suite_name ); + + return _stat.failed; +} + +test_suite::test_case_type test_suite::add( test_suite::func_type f, const string& name ) +{ + vertex_t v = add_vertex( white_color, g); + add_edge( root, v, g ); + _test[v].tc = detail::make_test_case( detail::call( f ) ); + _test[v].state = 0; + _test[v].name = name; + // ++_stat.total; + + return v; +} + +test_suite::test_case_type test_suite::add( test_suite::func_type f, const string& name, test_suite::test_case_type depends ) +{ + vertex_t v = add_vertex( white_color, g); + add_edge( depends, v, g ); + _test[v].tc = detail::make_test_case( detail::call( f ) ); + _test[v].state = 0; + _test[v].name = name; + // ++_stat.total; + + return v; +} + +int test_suite::flags() +{ + return local_logger->flags(); +} + +bool test_suite::is_trace() +{ + return local_logger->is_trace(); +} + +int test_suite::flags( int f ) +{ + return local_logger->flags( f ); +} + +trivial_logger __trivial_logger_inst( cerr ); + +base_logger *test_suite::logger = &__trivial_logger_inst; + +base_logger *test_suite::set_global_logger( base_logger *new_logger ) +{ + base_logger *tmp = logger; + logger = new_logger; + if ( tmp == local_logger ) { // if local_logger was identical to logger, switch it too + local_logger = logger; + } + return tmp; +} + +base_logger *test_suite::set_logger( base_logger *new_logger ) +{ + base_logger *tmp = local_logger; + local_logger = new_logger; + return tmp; +} + +void test_suite::report( const char *file, int line, bool cnd, const char *expr ) +{ + local_logger->report( file, line, cnd, expr ); +} + +void test_suite::run_test_case( test_suite::vertex_t v ) +{ + try { + ++_stat.total; + if ( _test[v].state == 0 ) { + if ( (*_test[v].tc)( this, 0 ) == 0 ) { + ++_stat.passed; + local_logger->tc( base_logger::pass, _test[v].name ); + } else { + _test[v].state = fail; + ++_stat.failed; + local_logger->tc( base_logger::fail, _test[v].name ); + } + } else { + ++_stat.skipped; + local_logger->tc( base_logger::skip, _test[v].name ); + } + } + catch ( init_exception& ) { + --_stat.total; + } + catch ( ... ) { + ++_stat.failed; + _test[v].state = fail; + local_logger->tc( base_logger::fail, _test[v].name ); + } +} + +void test_suite::check_test_case( test_suite::vertex_t u, test_suite::vertex_t v ) +{ + if ( _test[u].state != 0 ) { + _test[v].state = skip; + } +} + +void test_suite::clean_test_case_state( vertex_t v ) +{ + _test[v].state = 0; +} + +int test_suite::run( test_suite *, int ) +{ + return girdle( root ); +} + + +} // namespace exam Property changes on: trunk/complement/explore/lib/exam/ut ___________________________________________________________________ Name: svn:ignore + obj Copied: trunk/complement/explore/lib/exam/ut/Makefile (from rev 1606, trunk/complement/explore/app/exam/Makefile) =================================================================== --- trunk/complement/explore/lib/exam/ut/Makefile (rev 0) +++ trunk/complement/explore/lib/exam/ut/Makefile 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,11 @@ +# -*- Makefile -*- Time-stamp: <07/07/05 09:31:15 ptr> + +SRCROOT := ../../.. + +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak + +# INCLUDES += -I${BOOST_DIR} +INCLUDES += -I${CoMT_INCLUDE_DIR} + +LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR} Copied: trunk/complement/explore/lib/exam/ut/Makefile.inc (from rev 1613, trunk/complement/explore/app/exam/Makefile.inc) =================================================================== --- trunk/complement/explore/lib/exam/ut/Makefile.inc (rev 0) +++ trunk/complement/explore/lib/exam/ut/Makefile.inc 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,7 @@ +# -*- makefile -*- Time-stamp: <02/07/14 14:03:13 ptr> + +PRGNAME = exam_self_test +SRC_CC = exam_self_test.cc \ + exam_test_suite.cc \ + ../suite.cc \ + ../logger.cc Copied: trunk/complement/explore/lib/exam/ut/dummy_test.cc (from rev 1612, trunk/complement/explore/app/exam/dummy_test.cc) =================================================================== --- trunk/complement/explore/lib/exam/ut/dummy_test.cc (rev 0) +++ trunk/complement/explore/lib/exam/ut/dummy_test.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,36 @@ +#include <exam/suite.h> + +int EXAM_IMPL(func) +{ + EXAM_CHECK(false); + + return EXAM_RESULT; +} + +class test_x +{ + public: + + int EXAM_IMPL(f) + { + EXAM_CHECK(false); + EXAM_CHECK(true); + + return EXAM_RESULT; + } + + int EXAM_IMPL(f_good) + { + EXAM_CHECK(true); + EXAM_CHECK(true); + + return EXAM_RESULT; + } +}; + +int EXAM_IMPL(func_good) +{ + EXAM_CHECK(true); + + return EXAM_RESULT; +} Copied: trunk/complement/explore/lib/exam/ut/exam_self_test.cc (from rev 1613, trunk/complement/explore/app/exam/exam_self_test.cc) =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_self_test.cc (rev 0) +++ trunk/complement/explore/lib/exam/ut/exam_self_test.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,14 @@ +// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> + +#include "exam_test_suite.h" + +int main( int, char ** ) +{ + // exam::test_suite t( "exam self test" ); + // t.add( exam_self_test, "exam self test suite" ); + // + // return t.girdle(); + + return exam_self_test(0); +} + Copied: trunk/complement/explore/lib/exam/ut/exam_test_suite.cc (from rev 1612, trunk/complement/explore/app/exam/exam_test_suite.cc) =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.cc (rev 0) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.cc 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,239 @@ +// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> + +#include "exam_test_suite.h" + +#include "dummy_test.cc" + +int EXAM_IMPL(exam_basic_test::function_good) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t( "exam self test, good function" ); + t.set_logger( &logger ); + + test_x tx; + t.add( func_good, "function" ); + t.add( &test_x::f_good, tx, "member function" ); + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r0 ); + + // std::cerr << "%%%\n"; + // std::cerr << buff.str() << std::endl; + // std::cerr << "%%%\n"; + + return EXAM_RESULT; +} + +int EXAM_IMPL(exam_basic_test::function) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t( "exam self test, fail function" ); + t.set_logger( &logger ); + + test_x tx; + t.add( func, "function" ); + t.add( &test_x::f, tx, "member function" ); + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r1 ); + + // std::cerr << "%%%\n"; + // std::cerr << buff.str() << std::endl; + // std::cerr << "%%%\n"; + + return EXAM_RESULT; +} + +int EXAM_IMPL(exam_basic_test::dep) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t( "exam self test, fail function" ); + t.set_logger( &logger ); + + test_x tx; + t.add( func_good, "function good", // "child" + t.add( &test_x::f_good, tx, "member function good" ) ); // "parent" + t.add( func, "function fail", // <- skiped, because depends upon failed (next line) + t.add( &test_x::f, tx, "member function fail" ) ); // <- fail + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r2 ); + + // std::cerr << "%%%\n"; + // std::cerr << buff.str() << std::endl; + // std::cerr << "%%%\n"; + + return EXAM_RESULT; +} + +int EXAM_IMPL(exam_basic_test::trace) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t( "exam self test, fail function" ); + t.set_logger( &logger ); + + logger.flags( exam::base_logger::trace_suite ); + + test_x tx; + t.add( func_good, "function good", // "child" + t.add( &test_x::f_good, tx, "member function good" ) ); // "parent" + t.add( func, "function fail", // <- skiped, because depends upon failed (next line) + t.add( &test_x::f, tx, "member function fail" ) ); // <- fail + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r3 ); + + buff.str( "" ); + buff.clear(); + + logger.flags( exam::base_logger::silent ); + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r4 ); + + buff.str( "" ); + buff.clear(); + + logger.flags( exam::base_logger::trace ); + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r5 ); + + buff.str( "" ); + buff.clear(); + + logger.flags( exam::base_logger::verbose ); + + t.girdle(); + + logger.flags( 0 ); + + EXAM_REQUIRE( buff.str() == r6 ); + + // std::cerr << "%%%\n"; + // std::cerr << buff.str() << std::endl; + // std::cerr << "%%%\n"; + + return EXAM_RESULT; +} + +int EXAM_IMPL(exam_basic_test::dep_test_suite) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t0( "exam self test, test suite master" ); + t0.set_logger( &logger ); + + test_x tx0; + t0.add( func_good, "function" ); + t0.add( &test_x::f_good, tx0, "member function" ); + + exam::test_suite t1( "exam self test, test suite slave" ); + t1.set_logger( &logger ); + + test_x tx1; + t1.add( func_good, "function good", // "child" + t1.add( &test_x::f_good, tx1, "member function good" ) ); // "parent" + t1.add( func, "function fail", // <- skiped, because depends upon failed (next line) + t1.add( &test_x::f, tx1, "member function fail" ) ); // <- fail + + exam::test_suite t( "exam self test, test suites dependency" ); + t.set_logger( &logger ); + + t.add( &exam::test_suite::run, t1, "slave test suite", + t.add( &exam::test_suite::run, t0, "master test suite" ) ); + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r7 ); + + // std::cerr << "%%%\n"; + // std::cerr << buff.str() << std::endl; + // std::cerr << "%%%\n"; + + return EXAM_RESULT; +} + +const std::string exam_basic_test::r0 = "\ +*** PASS exam self test, good function (+2-0~0/2) ***\n"; + +const std::string exam_basic_test::r1 = "\ +dummy_test.cc:5: fail: false\n\ + FAIL function\n\ +dummy_test.cc:16: fail: false\n\ + FAIL member function\n\ +*** FAIL exam self test, fail function (+0-2~0/2) ***\n"; + +const std::string exam_basic_test::r2 = "\ +dummy_test.cc:16: fail: false\n\ + FAIL member function fail\n\ + SKIP function fail\n\ +*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; + +const std::string exam_basic_test::r3 = "\ +== Begin test suite\n\ +dummy_test.cc:16: fail: false\n\ + FAIL member function fail\n\ + SKIP function fail\n\ +== End test suite\n\ +*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; + +const std::string exam_basic_test::r4 = "\ +*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; + +const std::string exam_basic_test::r5 = "\ +dummy_test.cc:24: pass: true\n\ +dummy_test.cc:25: pass: true\n\ +dummy_test.cc:16: fail: false\n\ +dummy_test.cc:17: pass: true\n\ + FAIL member function fail\n\ + SKIP function fail\n\ +dummy_test.cc:33: pass: true\n\ +*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; + +const std::string exam_basic_test::r6 = "\ + PASS member function good\n\ +dummy_test.cc:16: fail: false\n\ + FAIL member function fail\n\ + SKIP function fail\n\ + PASS function good\n\ +*** FAIL exam self test, fail function (+2-1~1/4) ***\n"; + +const std::string exam_basic_test::r7 = "\ +*** PASS exam self test, test suite master (+2-0~0/2) ***\n\ +dummy_test.cc:16: fail: false\n\ + FAIL member function fail\n\ + SKIP function fail\n\ +*** FAIL exam self test, test suite slave (+2-1~1/4) ***\n\ + FAIL slave test suite\n\ +*** FAIL exam self test, test suites dependency (+1-1~0/2) ***\n"; + +int EXAM_IMPL(exam_self_test) +{ + exam::test_suite t( "exam self test" ); + exam_basic_test exam_basic; + + t.add( &exam_basic_test::function_good, exam_basic, "call test, good calls" ); + t.add( &exam_basic_test::function, exam_basic, "call test, fail calls" ); + exam::test_suite::test_case_type d = t.add( &exam_basic_test::dep, exam_basic, "call test, tests dependency" ); + t.add( &exam_basic_test::trace, exam_basic, "trace flags test", d ); + t.add( &exam_basic_test::dep_test_suite, exam_basic, "test suites grouping", d ); + + return t.girdle(); +} + Copied: trunk/complement/explore/lib/exam/ut/exam_test_suite.h (from rev 1612, trunk/complement/explore/app/exam/exam_test_suite.h) =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.h (rev 0) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.h 2007-07-16 14:34:39 UTC (rev 1614) @@ -0,0 +1,42 @@ +// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> + +#ifndef __exam_test_suite_h +#define __exam_test_suite_h + +#define FIT_EXAM + +#include <exam/suite.h> +#include <string> +#include <sstream> + +class exam_basic_test +{ + public: + exam_basic_test() : + buff(), + logger( buff ) + { } + + int EXAM_DECL(function_good); + int EXAM_DECL(function); + int EXAM_DECL(dep); + int EXAM_DECL(trace); + int EXAM_DECL(dep_test_suite); + + private: + std::stringstream buff; + exam::trivial_logger logger; + + static const std::string r0; + static const std::string r1; + static const std::string r2; + static const std::string r3; + static const std::string r4; + static const std::string r5; + static const std::string r6; + static const std::string r7; +}; + +int EXAM_DECL(exam_self_test); + +#endif // __exam_test_suite_h This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-07-16 21:14:16
|
Revision: 1616 http://svn.sourceforge.net/complement/?rev=1616&view=rev Author: complement Date: 2007-07-16 14:14:15 -0700 (Mon, 16 Jul 2007) Log Message: ----------- added multiple dependencies Modified Paths: -------------- trunk/complement/explore/include/exam/suite.h trunk/complement/explore/lib/exam/ChangeLog trunk/complement/explore/lib/exam/suite.cc trunk/complement/explore/lib/exam/ut/dummy_test.cc trunk/complement/explore/lib/exam/ut/exam_test_suite.cc trunk/complement/explore/lib/exam/ut/exam_test_suite.h Modified: trunk/complement/explore/include/exam/suite.h =================================================================== --- trunk/complement/explore/include/exam/suite.h 2007-07-16 15:17:55 UTC (rev 1615) +++ trunk/complement/explore/include/exam/suite.h 2007-07-16 21:14:15 UTC (rev 1616) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/15 16:33:17 ptr> +// -*- C++ -*- Time-stamp: <07/07/16 23:07:02 ptr> #ifndef __suite_h #define __suite_h @@ -178,12 +178,18 @@ test_case_type add( func_type, const std::string& name ); test_case_type add( func_type, const std::string& name, test_case_type ); + template <class InputIter> + test_case_type add( func_type, const std::string& name, InputIter, InputIter ); + template <class TC> test_case_type add( int (TC::*)( test_suite *, int ), TC&, const std::string& name ); template <class TC> test_case_type add( int (TC::*)( test_suite *, int ), TC&, const std::string& name, test_case_type ); + template <class TC, class InputIter> + test_case_type add( int (TC::*)( test_suite *, int ), TC&, const std::string& name, InputIter, InputIter ); + int girdle( test_case_type start ); int girdle() { return girdle( root ); } @@ -242,6 +248,21 @@ return v; } +template <class InputIter> +test_suite::test_case_type test_suite::add( test_suite::func_type f, const std::string& name, InputIter first, InputIter last ) +{ + vertex_t v = boost::add_vertex( boost::white_color, g); + while ( first != last ) { + boost::add_edge( *first++, v, g ); + } + _test[v].tc = detail::make_test_case( detail::call( f ) ); + _test[v].state = 0; + _test[v].name = name; + // ++_stat.total; + + return v; +} + template <class TC> test_suite::test_case_type test_suite::add( int (TC::*f)( test_suite *, int ), TC& instance, const std::string& name, test_suite::test_case_type depends ) { @@ -255,6 +276,21 @@ return v; } +template <class TC, class InputIter> +test_suite::test_case_type test_suite::add( int (TC::*f)( test_suite *, int ), TC& instance, const std::string& name, InputIter first, InputIter last ) +{ + vertex_t v = boost::add_vertex( boost::white_color, g); + while ( first != last ) { + boost::add_edge( *first++, v, g ); + } + _test[v].tc = detail::make_test_case( f, instance ); + _test[v].state = 0; + _test[v].name = name; + // ++_stat.total; + + return v; +} + typedef test_suite::test_case_type test_case_type; } // namespace exam Modified: trunk/complement/explore/lib/exam/ChangeLog =================================================================== --- trunk/complement/explore/lib/exam/ChangeLog 2007-07-16 15:17:55 UTC (rev 1615) +++ trunk/complement/explore/lib/exam/ChangeLog 2007-07-16 21:14:15 UTC (rev 1616) @@ -1,3 +1,11 @@ +2007-07-17 Petr Ovtchenkov <pt...@is...> + + * suite.h, suite.cc: added multiple dependencies; + + * ut/exam_test_suite.cc, ut/exam_test_suite.h, ut/dummy_test.cc: + test for multiple dependencies; discover problem with multiple + dependencies. + 2007-07-16 Petr Ovtchenkov <pt...@is...> * converted from prototype in app/exam; Modified: trunk/complement/explore/lib/exam/suite.cc =================================================================== --- trunk/complement/explore/lib/exam/suite.cc 2007-07-16 15:17:55 UTC (rev 1615) +++ trunk/complement/explore/lib/exam/suite.cc 2007-07-16 21:14:15 UTC (rev 1616) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/15 16:33:03 ptr> +// -*- C++ -*- Time-stamp: <07/07/17 00:36:02 ptr> #include <exam/suite.h> #include <boost/graph/breadth_first_search.hpp> @@ -51,7 +51,10 @@ { // typename graph_traits<Graph>::vertex_descriptor u = boost::source( e, g ); // typename graph_traits<Graph>::vertex_descriptor v = boost::target( e, g ); + // boost::out_edges( v, g ); + // for () { _suite.check_test_case( boost::source( e, g ), boost::target( e, g ) ); + // } } test_suite& _suite; Modified: trunk/complement/explore/lib/exam/ut/dummy_test.cc =================================================================== --- trunk/complement/explore/lib/exam/ut/dummy_test.cc 2007-07-16 15:17:55 UTC (rev 1615) +++ trunk/complement/explore/lib/exam/ut/dummy_test.cc 2007-07-16 21:14:15 UTC (rev 1616) @@ -34,3 +34,17 @@ return EXAM_RESULT; } + +int EXAM_IMPL(func_good2) +{ + EXAM_CHECK(true); + + return EXAM_RESULT; +} + +int EXAM_IMPL(func_good3) +{ + EXAM_CHECK(true); + + return EXAM_RESULT; +} Modified: trunk/complement/explore/lib/exam/ut/exam_test_suite.cc =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.cc 2007-07-16 15:17:55 UTC (rev 1615) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.cc 2007-07-16 21:14:15 UTC (rev 1616) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> +// -*- C++ -*- Time-stamp: <07/07/17 00:38:11 ptr> #include "exam_test_suite.h" @@ -169,6 +169,70 @@ return EXAM_RESULT; } +int EXAM_IMPL(exam_basic_test::multiple_dep) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t( "exam self test, fail function" ); + t.set_logger( &logger ); + + test_x tx; + + exam::test_suite::test_case_type tc[2]; + + tc[0] = t.add( &test_x::f_good, tx, "member function good" ); + tc[1] = t.add( func_good, "function good" ); + + t.add( func, "function fail", tc, tc + 2 ); + t.add( &test_x::f, tx, "member function fail", tc, tc + 2 ); + t.add( func_good2, "function 2 good", tc, tc + 2 ); + + t.girdle(); + + EXAM_REQUIRE( buff.str() == r8 ); + + // std::cerr << "%%%\n"; + // std::cerr << buff.str() << std::endl; + // std::cerr << "%%%\n"; + + return EXAM_RESULT; +} + +int EXAM_IMPL(exam_basic_test::multiple_dep_complex) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t( "exam self test, fail function" ); + t.set_logger( &logger ); + + test_x tx; + + exam::test_suite::test_case_type tc[2]; + exam::test_suite::test_case_type tcx[2]; + + tc[0] = t.add( &test_x::f_good, tx, "member function good" ); + tc[1] = t.add( func_good, "function good" ); + + tcx[0] = t.add( func, "function fail", tc, tc + 2 ); + t.add( &test_x::f, tx, "member function fail", tc, tc + 2 ); + tcx[1] = t.add( func_good2, "function 2 good", tc, tc + 2 ); + t.add( func_good3, "function 3 good", tcx, tcx + 2 ); // <-- problem + + logger.flags( exam::base_logger::verbose ); + t.girdle(); + logger.flags( 0 ); + + // EXAM_REQUIRE( buff.str() == r9 ); + + std::cerr << "%%%\n"; + std::cerr << buff.str() << std::endl; + std::cerr << "%%%\n"; + + return EXAM_RESULT; +} + const std::string exam_basic_test::r0 = "\ *** PASS exam self test, good function (+2-0~0/2) ***\n"; @@ -223,17 +287,32 @@ FAIL slave test suite\n\ *** FAIL exam self test, test suites dependency (+1-1~0/2) ***\n"; +const std::string exam_basic_test::r8 = "\ +dummy_test.cc:5: fail: false\n\ + FAIL function fail\n\ +dummy_test.cc:16: fail: false\n\ + FAIL member function fail\n\ +*** FAIL exam self test, fail function (+3-2~0/5) ***\n"; + +const std::string exam_basic_test::r9 = "\ +dummy_test.cc:5: fail: false\n\ + FAIL function fail\n\ +dummy_test.cc:16: fail: false\n\ + FAIL member function fail\n\ +*** FAIL exam self test, fail function (+3-2~1/6) ***\n"; + int EXAM_IMPL(exam_self_test) { exam::test_suite t( "exam self test" ); exam_basic_test exam_basic; - t.add( &exam_basic_test::function_good, exam_basic, "call test, good calls" ); - t.add( &exam_basic_test::function, exam_basic, "call test, fail calls" ); - exam::test_suite::test_case_type d = t.add( &exam_basic_test::dep, exam_basic, "call test, tests dependency" ); + exam::test_suite::test_case_type d0 = t.add( &exam_basic_test::function_good, exam_basic, "call test, good calls" ); + t.add( &exam_basic_test::function, exam_basic, "call test, fail calls", d0 ); + exam::test_suite::test_case_type d = t.add( &exam_basic_test::dep, exam_basic, "call test, tests dependency", d0 ); t.add( &exam_basic_test::trace, exam_basic, "trace flags test", d ); t.add( &exam_basic_test::dep_test_suite, exam_basic, "test suites grouping", d ); + exam::test_suite::test_case_type d2 = t.add( &exam_basic_test::multiple_dep, exam_basic, "multiple dependencies", d ); + // t.add( &exam_basic_test::multiple_dep_complex, exam_basic, "complex multiple dependencies", d2 ); return t.girdle(); } - Modified: trunk/complement/explore/lib/exam/ut/exam_test_suite.h =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.h 2007-07-16 15:17:55 UTC (rev 1615) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.h 2007-07-16 21:14:15 UTC (rev 1616) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/16 16:33:17 ptr> +// -*- C++ -*- Time-stamp: <07/07/16 23:40:09 ptr> #ifndef __exam_test_suite_h #define __exam_test_suite_h @@ -22,6 +22,8 @@ int EXAM_DECL(dep); int EXAM_DECL(trace); int EXAM_DECL(dep_test_suite); + int EXAM_DECL(multiple_dep); + int EXAM_DECL(multiple_dep_complex); private: std::stringstream buff; @@ -35,6 +37,8 @@ static const std::string r5; static const std::string r6; static const std::string r7; + static const std::string r8; + static const std::string r9; }; int EXAM_DECL(exam_self_test); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |