[complement-svn] SF.net SVN: complement: [1606] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
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] |