[complement-svn] SF.net SVN: complement: [1737] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-09-18 09:21:47
|
Revision: 1737 http://complement.svn.sourceforge.net/complement/?rev=1737&view=rev Author: complement Date: 2007-09-18 02:21:45 -0700 (Tue, 18 Sep 2007) Log Message: ----------- removed intermediate _xcall, use direct call of _call as thread function; add locker for _rip_id---it may be changed from different threads in case of fast termination of thread; libxmt: version 1.13.0 Modified Paths: -------------- trunk/complement/explore/include/mt/xmt.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/xmt.cc Modified: trunk/complement/explore/include/mt/xmt.h =================================================================== --- trunk/complement/explore/include/mt/xmt.h 2007-09-14 10:08:15 UTC (rev 1736) +++ trunk/complement/explore/include/mt/xmt.h 2007-09-18 09:21:45 UTC (rev 1737) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/08/03 09:47:08 ptr> +// -*- C++ -*- Time-stamp: <07/09/15 10:03:40 ptr> /* * Copyright (c) 1997-1999, 2002-2007 @@ -144,12 +144,12 @@ // extern __FIT_DECLSPEC void signal_throw( int sig ) throw( int ); // extern __FIT_DECLSPEC void signal_thread_exit( int sig ); -#ifdef __unix -extern "C" void *_xcall( void * ); // forward declaration -#endif -#ifdef WIN32 -extern "C" unsigned long __stdcall _xcall( void *p ); // forward declaration -#endif +// #ifdef __unix +// extern "C" void *_xcall( void * ); // forward declaration +// #endif +// #ifdef WIN32 +// extern "C" unsigned long __stdcall _xcall( void *p ); // forward declaration +// #endif #ifndef WIN32 // using std::size_t; @@ -1463,7 +1463,7 @@ bool bad() const { /* Locker lk( _llock ); */ return (_id == bad_thread_id); } bool is_join_req() const // if true, you can (and should) use join() - { /* Locker lk( _llock ); */ return (_rip_id != bad_thread_id) && ((_flags & (daemon | detached)) == 0); } + { scoped_lock lk( _rip_id_lock ); return (_rip_id != bad_thread_id) && ((_flags & (daemon | detached)) == 0); } __FIT_DECLSPEC bool is_self(); @@ -1494,7 +1494,11 @@ bool _not_run() const { /* Locker lk( _llock ); */ return _id == bad_thread_id; } void _create( const void *p, size_t psz ) throw( std::runtime_error); + static void *_call( void *p ); +#ifdef WIN32 + statuc unsigned long __stdcall _call( void *p ); +#endif static void unexpected(); static void terminate(); @@ -1518,6 +1522,7 @@ thread_id_type _id; thread_id_type _rip_id; + mutex _rip_id_lock; #ifdef _PTHREADS # ifndef __hpux // sorry, POSIX threads don't have suspend/resume calls, so it should @@ -1536,12 +1541,12 @@ // mutex _llock; friend class Init; // extern "C", wrap for thread_create -#ifdef __unix - friend void *_xcall( void * ); -#endif -#ifdef __FIT_WIN32THREADS - friend unsigned long __stdcall _xcall( void *p ); -#endif +// #ifdef __unix +// friend void *_xcall( void * ); +// #endif +// #ifdef __FIT_WIN32THREADS +// friend unsigned long __stdcall _xcall( void *p ); +// #endif }; template <bool SCOPE> Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-09-14 10:08:15 UTC (rev 1736) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-09-18 09:21:45 UTC (rev 1737) @@ -1,3 +1,13 @@ +2007-09-18 Petr Ovtchenkov <pt...@is...> + + * xmt.h, xmt.cc: removed intermediate _xcall, use direct call of _call + as thread function; + + * xmt.h, xmt.cc: add locker for _rip_id---it may be changed from different + threads in case of fast termination of thread; + + * libxmt: version 1.13.0 + 2007-09-05 Petr Ovtchenkov <pt...@is...> * xmt.h, xmt.cc: looks like non-POD return from thread is unstable, Modified: trunk/complement/explore/lib/mt/xmt.cc =================================================================== --- trunk/complement/explore/lib/mt/xmt.cc 2007-09-14 10:08:15 UTC (rev 1736) +++ trunk/complement/explore/lib/mt/xmt.cc 2007-09-18 09:21:45 UTC (rev 1737) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/06/14 10:10:54 ptr> +// -*- C++ -*- Time-stamp: <07/09/15 10:16:39 ptr> /* * Copyright (c) 1997-1999, 2002-2007 @@ -419,6 +419,7 @@ thr_join( _rip_id, 0, &rt ); # endif // Locker lk( _llock ); + scoped_lock lk( _rip_id_lock ); _rip_id = bad_thread_id; } #endif // __FIT_UITHREADS || PTHREADS @@ -544,7 +545,7 @@ // follow part of _call if ( (me->_flags & (daemon | detached)) != 0 ) { // otherwise join expected - // Locker lk( me->_llock ); // !!!!??? in the signal handler? + // scoped_lock lk( _rip_id_lock ); // !!!!??? in the signal handler? me->_rip_id = me->_id = bad_thread_id; } else { me->_id = bad_thread_id; @@ -718,21 +719,23 @@ // pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED ); // pthread_attr_setschedpolicy(&attr,SCHED_OTHER); } - err = pthread_create( &_id, _flags != 0 || _stack_sz != 0 ? &attr : 0, _xcall, this ); + scoped_lock lk( _rip_id_lock ); + err = pthread_create( &_id, _flags != 0 || _stack_sz != 0 ? &attr : 0, _call, this ); if ( err != 0 ) { _rip_id = _id = bad_thread_id; } else { _rip_id = _id; } + lk.unlock(); if ( _flags != 0 || _stack_sz != 0 ) { pthread_attr_destroy( &attr ); } #endif #ifdef __FIT_UITHREADS - err = thr_create( 0, 0, _xcall, this, _flags, &_id ); + err = thr_create( 0, 0, _call, this, _flags, &_id ); #endif #ifdef __FIT_WIN32THREADS - _rip_id = _id = CreateThread( 0, 0, _xcall, this, (_flags & suspended), &_thr_id ); + _rip_id = _id = CreateThread( 0, 0, _call, this, (_flags & suspended), &_thr_id ); err = GetLastError(); #endif @@ -750,28 +753,12 @@ #pragma warning( disable : 4101 ) #endif -extern "C" { #ifdef __unix - void *_xcall( void *p ) - { - return Thread::_call( p ); - } +void *Thread::_call( void *p ) #endif #ifdef WIN32 - unsigned long __stdcall _xcall( void *p ) - { - return (unsigned long)Thread::_call( p ); - } +unsigned long __stdcall Thread::_call( void *p ) #endif -#ifdef __FIT_NETWARE - void _xcall( void *p ) - { - Thread::_call( p ); - } -#endif -} // extern "C" - -void *Thread::_call( void *p ) { Thread *me = static_cast<Thread *>(p); @@ -816,6 +803,7 @@ #ifdef __FIT_WIN32THREADS CloseHandle( me->_id ); #endif + scoped_lock lk( me->_rip_id_lock ); me->_id = bad_thread_id; me->_rip_id = bad_thread_id; } else { @@ -830,6 +818,7 @@ #ifdef __FIT_WIN32THREADS CloseHandle( me->_id ); #endif + scoped_lock lk( me->_rip_id_lock ); me->_id = bad_thread_id; me->_rip_id = bad_thread_id; } else { @@ -848,6 +837,7 @@ #ifdef __FIT_WIN32THREADS CloseHandle( me->_id ); #endif + scoped_lock lk( me->_rip_id_lock ); me->_id = bad_thread_id; me->_rip_id = bad_thread_id; } else { @@ -868,6 +858,7 @@ #ifdef __FIT_WIN32THREADS CloseHandle( me->_id ); #endif + scoped_lock lk( me->_rip_id_lock ); me->_id = bad_thread_id; me->_rip_id = bad_thread_id; } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |